MarSTDv2004: CBsp Class Reference

MarSTDv2004

CBsp Class Reference

Inheritance diagram for CBsp:

Inheritance graph
[legend]
Collaboration diagram for CBsp:

Collaboration graph
[legend]
List of all members.

Detailed Description

BSP (Binary Space Partition) class. This class will take any mesh and create a BSP from it. Common uses are optimising collision detection, maximising overdraw on accelerated platforms, or z-sorting on software platforms.
// Example:

void create_bsp(CBsp& bsp)
{

        // Add a donut shape.
        
        CGeomBuilder::I().donut(bsp, 10, 10, 2.0, 1.0);
        
        // Add a square.
        
        CPoly* poly = bsp.add(new CPoly);
        
        for (int i = 0; i < 4; i++)
        {
                CEdge* egde = poly->add(new CEdge);
                edge->p[0] = sin(i / 4.0 * M_PI);
                edge->p[1] = cos(i / 4.0 * M_PI);
        }
        
        poly->init();   // Very important. This will set up the plane, which is neccessary for BSP to work.
        
        // Partition BSP.
        
        bsp.split();
        
}
Author:
Marcel Smit

Definition at line 92 of file CBsp.h.


Public Member Functions

int coplanar ()
void move (CPoly *poly, CBsp *bsp)
int onFront (CPoly *poly, int bias=0)
int onBack (CPoly *poly, int bias=0)
void getSplitInfo (CPlane &p, CBspSplitInfo &i, int flip)
int test (CBspSplitInfo *i1, CBspSplitInfo *i2)
int test1 (CBspSplitInfo *i1, CBspSplitInfo *i2)
int test2 (CBspSplitInfo *i1, CBspSplitInfo *i2)
CPlane getSplitPlane ()
void split (CPoly *poly)
void split ()
CSphere getBoundingSphere (CPoly *poly)
void initBoundingSpheres ()
 Initialises all bounding spheres before initiaiting split.
void freeBoundingSpheres ()
 Frees all bounding spheres and restored the polygons' custom data fields.
void restorePolyData ()
 Restored the polygons' custom data fields.
void initBoundingBox ()
void getHitLeafs (CVector point, std::vector< CBsp * > *bspArray)
void getHitLeafs (CSphere sohere, std::vector< CBsp * > *bspArray)
CPolyadd (CPoly *poly)
CPolyaddHead (CPoly *poly)
CPolyaddTail (CPoly *poly)
CPolyunlink (CPoly *poly)
void remove (CPoly *poly)
void clear ()
void copy (CMesh *mesh)
CMeshcopy ()
void triangulate (CMesh *mesh)
void transform (CMatrix *matrix)
void move (CMesh *mesh)
void paint (void *data)

Public Attributes

CPlane plane
 Splitting plane.
int planeFlipped
CBspchild [2]
 Front & back children.
CBspparent
float eps
 Epsilon to keep floating point happy and reduce splits.
int initialized
 0 if this BSP needs initialisation, else 1.
CBspPolyDatapolyData
 Polygon info structure.
CVector mins
CVector maxs
 Bounding box.
CSphere sphere
 Bounding sphere.
float volume
 Bounding box volume.
int noSplittingPlane
 Set to 1 if getSplitPlane() could not find any suitable splitting plane, else 0.
CPolypolyHead
 First polygon in DLL.
CPolypolyTail
 Last polygon in DLL.
int polyCount
 Number of polygons in DLL.
void * data
 Custom data field.

Member Function Documentation

int CBsp::coplanar  ) 
 

Return true if all polygons lie on one plane.

void CBsp::move CPoly poly,
CBsp bsp
 

Moves a polygon from this BSP to another.

Parameters:
poly Polygon to move.
bsp Destination BSP.

int CBsp::onFront CPoly poly,
int  bias = 0
 

Return 1 if the polygon lies on the front side of the plane.

Parameters:
poly Polygon to test.
bias If bias is set to 1, the epsilon value will be doubled.

int CBsp::onBack CPoly poly,
int  bias = 0
 

Return true if the polygon lies on the back side of the plane.

Parameters:
poly Polygon to test.
bias If bias is set to 1, the epsilon value will be doubled.

void CBsp::getSplitInfo CPlane p,
CBspSplitInfo i,
int  flip
 

Fills in the CBspSplitInfo structure with some statistics on how this plane will split the geometry. This information is used to decide which plane to use to split.

Parameters:
p Splitting plane to get info about.
i Info structure that will be filled.
flip If set to 1, the plane will be flipped (mirrored).

int CBsp::test CBspSplitInfo i1,
CBspSplitInfo i2
 

Returns 1 when i2 is a better split than i1.

Parameters:
i1 Info structure 1.
i2 Info structure 2.

int CBsp::test1 CBspSplitInfo i1,
CBspSplitInfo i2
 

Helper function in determining the 'best' splitting plane.

Parameters:
i1 Info structure 1.
i2 Info structure 2.

int CBsp::test2 CBspSplitInfo i1,
CBspSplitInfo i2
 

Helper function in determining the 'best' splitting plane.

Parameters:
i1 Info structure 1.
i2 Info structure 2.

CPlane CBsp::getSplitPlane  ) 
 

Returns the plane this BSP should be split with. The plane is automatically calculated by using statictical data acquired using test splits.

void CBsp::split CPoly poly  ) 
 

Split the polygon, dividing it over the front and back child nodes.

Parameters:
poly Polygon to split. This polygon must not be on the front side or back side. It must be spanning.

void CBsp::split  ) 
 

Splits the BSP node if neccessary.

CSphere CBsp::getBoundingSphere CPoly poly  ) 
 

Returns the bounding sphere for a given polygon.

Parameters:
poly Polygon for which to calculate bounding sphere.

void CBsp::initBoundingBox  ) 
 

Initializes the bounding box. This is done for every node of the tree.

void CBsp::getHitLeafs CVector  point,
std::vector< CBsp * > *  bspArray
 

Get the leafs the point is in.

void CBsp::getHitLeafs CSphere  sohere,
std::vector< CBsp * > *  bspArray
 

Get the leafs the sphere is in.

CPoly* CMesh::add CPoly poly  )  [inherited]
 

Links polygon to tail.

See also:
add_tail()

CPoly* CMesh::addHead CPoly poly  )  [inherited]
 

Links polygon to head.

See also:
add_tail()

CPoly* CMesh::addTail CPoly poly  )  [inherited]
 

Links polygon to tail.

See also:
add_head()

CPoly* CMesh::unlink CPoly poly  )  [inherited]
 

Unlinks poygon from DLL.

void CMesh::remove CPoly poly  )  [inherited]
 

Unlinks polygon from DLL and frees memory.

void CMesh::clear  )  [inherited]
 

Clear polygon DLL.

void CMesh::transform CMatrix matrix  )  [inherited]
 

Transforms all vertices in mesh.

Parameters:
matrix Matrix that will be used to transform vertices.

void CMesh::move CMesh mesh  )  [inherited]
 

Moves contents of polygons DLL to another mesh.

void CMesh::paint void *  data  )  [inherited]
 

Assign a custom data reference to all polygon.

Parameters:
data Pointer to custom data structure.


The documentation for this class was generated from the following file:
Generated on Tue Feb 8 21:59:31 2005 for MarSTDv2004 by  doxygen 1.4.1