2017-04-26 17:20:15 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Copyright (c) 1994 Stanford University */
|
|
|
|
/* */
|
|
|
|
/* All rights reserved. */
|
|
|
|
/* */
|
|
|
|
/* Permission is given to use, copy, and modify this software for any */
|
|
|
|
/* non-commercial purpose as long as this copyright notice is not */
|
|
|
|
/* removed. All other uses, including redistribution in whole or in */
|
|
|
|
/* part, are forbidden without prior written permission. */
|
|
|
|
/* */
|
|
|
|
/* This software is provided with absolutely no warranty and no */
|
|
|
|
/* support. */
|
|
|
|
/* */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NAME
|
|
|
|
* bbox.c
|
|
|
|
*
|
|
|
|
* DESCRIPTION
|
|
|
|
* This file contains routines that read, inquire, and normalize bounding
|
|
|
|
* boxes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2017-04-26 18:03:02 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
2017-04-26 17:20:15 +02:00
|
|
|
#include "rt.h"
|
|
|
|
|
2017-04-26 18:03:02 +02:00
|
|
|
|
|
|
|
|
2017-04-26 17:20:15 +02:00
|
|
|
/*
|
|
|
|
* NAME
|
|
|
|
* InquireBoundBoxValues - return min and max bound values for each coordinate axis
|
|
|
|
*
|
|
|
|
* SYNOPSIS
|
|
|
|
* VOID InquireBoundBoxValues(pbb, minx, miny, minz, maxx, maxy, maxz)
|
|
|
|
* BBOX *pbb; // Ptr to bounding box.
|
|
|
|
* REAL *minx, *miny, *minz; // Near planes.
|
|
|
|
* REAL *maxx, *maxy, *maxz; // Far planes.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
VOID InquireBoundBoxValues(BBOX *pbb, REAL *minx, REAL *miny, REAL *minz, REAL *maxx, REAL *maxy, REAL *maxz)
|
2017-04-26 18:03:02 +02:00
|
|
|
{
|
|
|
|
*minx = pbb->dnear[0];
|
|
|
|
*miny = pbb->dnear[1];
|
|
|
|
*minz = pbb->dnear[2];
|
|
|
|
*maxx = pbb->dfar[0];
|
|
|
|
*maxy = pbb->dfar[1];
|
|
|
|
*maxz = pbb->dfar[2];
|
|
|
|
}
|
2017-04-26 17:20:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NAME
|
|
|
|
* NormalizeBoundBox - normalize bounding box given a normalization matrix
|
|
|
|
*
|
|
|
|
* SYNOPSIS
|
|
|
|
* VOID NormalizeBoundBox(bv, mat)
|
|
|
|
* BBOX *pbb; // Ptr to bounding box.
|
|
|
|
* MATRIX mat; // Normalization matrix.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Nothing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
VOID NormalizeBoundBox(BBOX *pbb, MATRIX mat)
|
2017-04-26 18:03:02 +02:00
|
|
|
{
|
|
|
|
POINT tmp;
|
2017-04-26 17:20:15 +02:00
|
|
|
|
2017-04-26 18:03:02 +02:00
|
|
|
/* dnear and dfar are only vectors of length 3 */
|
2017-04-26 17:20:15 +02:00
|
|
|
|
2017-04-26 18:03:02 +02:00
|
|
|
tmp[0] = pbb->dnear[0];
|
|
|
|
tmp[1] = pbb->dnear[1];
|
|
|
|
tmp[2] = pbb->dnear[2];
|
|
|
|
tmp[3] = 1.0;
|
2017-04-26 17:20:15 +02:00
|
|
|
|
2017-04-26 18:03:02 +02:00
|
|
|
VecMatMult(tmp, mat, tmp);
|
2017-04-26 17:20:15 +02:00
|
|
|
|
2017-04-26 18:03:02 +02:00
|
|
|
pbb->dnear[0] = tmp[0];
|
|
|
|
pbb->dnear[1] = tmp[1];
|
|
|
|
pbb->dnear[2] = tmp[2];
|
2017-04-26 17:20:15 +02:00
|
|
|
|
2017-04-26 18:03:02 +02:00
|
|
|
tmp[0] = pbb->dfar[0];
|
|
|
|
tmp[1] = pbb->dfar[1];
|
|
|
|
tmp[2] = pbb->dfar[2];
|
|
|
|
tmp[3] = 1.0;
|
2017-04-26 17:20:15 +02:00
|
|
|
|
2017-04-26 18:03:02 +02:00
|
|
|
VecMatMult(tmp, mat, tmp);
|
2017-04-26 17:20:15 +02:00
|
|
|
|
2017-04-26 18:03:02 +02:00
|
|
|
pbb->dfar[0] = tmp[0];
|
|
|
|
pbb->dfar[1] = tmp[1];
|
|
|
|
pbb->dfar[2] = tmp[2];
|
|
|
|
}
|
2017-04-26 17:20:15 +02:00
|
|
|
|