/*
Copyright (C) 1997, 1998, 1999 by Alex Pfaffe
(Digital Dawn Graphics Inc)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _ddgBBox_Class_
#define _ddgBBox_Class_
#ifdef DDG
#include "math/ddgvec.h"
#include "math/ddggeom.h"
#else
#include "csgeom/math3d.h"
#include "csterr/util/ddg.h"
#include "csterr/math/ddggeom.h"
#endif
// Visibility data. 1 byte.
typedef unsigned char ddgClipFlags;
enum {
DDGCF_LIN = 1 << 0,
DDGCF_RIN = 1 << 1,
DDGCF_TIN = 1 << 2,
DDGCF_BIN = 1 << 3,
DDGCF_NIN = 1 << 4,
DDGCF_FIN = 1 << 5,
DDGCF_ALLIN = 1 << 6,
DDGCF_ALLOUT = 1 << 7
};
#define DDGCF_VISIBILITY \
(DDGCF_LIN | DDGCF_RIN | DDGCF_TIN | DDGCF_BIN | DDGCF_NIN | DDGCF_FIN)
// Visibility data. 2 bits.
typedef unsigned char ddgVisState;
enum ddgVis { ddgOUT=0, ddgPART=1, ddgIN=2, ddgUNDEF = 3};
class WEXP ddgBBox {
ddgVector3 _min;
ddgVector3 _max;
public:
static short _corner[8][3];
typedef enum { XLT, XGT, YLT, YGT, ZLT, ZGT } Split;
ddgBBox(float xc = 0.0, float xd = MAXFLOAT,
float yc = 0.0, float yd = MAXFLOAT,
float zc = 0.0, float zd = MAXFLOAT);
ddgBBox(const ddgVector3 &min, const ddgVector3 &max);
void set(float xmin = -MAXFLOAT, float xmax = MAXFLOAT,
float ymin = -MAXFLOAT, float ymax = MAXFLOAT,
float zmin = -MAXFLOAT, float zmax = MAXFLOAT);
void set(const ddgVector3 &min, const ddgVector3 &max)
{ _min = min; _max = max; }
float minx( void ) { return _min[0]; }
float miny( void ) { return _min[1]; }
float minz( void ) { return _min[2]; }
float maxx( void ) { return _max[0]; }
float maxy( void ) { return _max[1]; }
float maxz( void ) { return _max[2]; }
ddgVector3 *min(void) { return &_min; }
ddgVector3 *max(void) { return &_max; }
void setx(float min, float max)
{
_min[0] = min;
_max[0] = max;
}
void sety(float min, float max)
{
_min[1] = min;
_max[1] = max;
}
void setz(float min, float max)
{
_min[2] = min;
_max[2] = max;
}
float cornerx(int n);
float cornery(int n);
float cornerz(int n);
void copy(ddgBBox *src);
void split(Split side, float value = 0 );
ddgVector3 centre(void)
{ return ( _min + _max ) * 0.5;}
void move(ddgVector3 o)
{ _min = _min + o; _max = _max + o; }
void scale(ddgVector3 s)
{
ddgVector3 c(_min + _max);
c = c * 0.5;
ddgVector3 d(c - _min);
d[0] *= s[0];
d[1] *= s[1];
d[2] *= s[2];
_min = c - d;
_max = c + d;
}
float distancesq( ddgVector3 *p);
float distance( ddgVector3 *p) { return sqrtf(distancesq(p)); }
bool intersect( ddgVector3 *p1, ddgVector3 *p2);
bool intersect( ddgBBox *b );
ddgVector3 size(void) { return _max - _min; }
ddgClipFlags visibleSpace( ddgBBox b, float tanHalfFOV );
ddgVis isVisible(ddgPlane Planes[6]);
};
#endif