//#define ENABLE_DEBUG_POLYHEDRON_DUMPS //Dumps debug information to disk for use with glview. Requires that tier2 also be in all projects using debug mathlib
Assert( false ); //TODO: create directories in linux
#endif
}
#endif
voidCPolyhedron_AllocByNew::Release( void )
{
deletethis;
}
CPolyhedron_AllocByNew *CPolyhedron_AllocByNew::Allocate( unsignedshort iVertices, unsignedshort iLines, unsignedshort iIndices, unsignedshort iPolygons ) //creates the polyhedron along with enough memory to hold all it's data in a single allocation
CPolyhedron *GetTempPolyhedron( unsignedshort iVertices, unsignedshort iLines, unsignedshort iIndices, unsignedshort iPolygons ) //grab the temporary polyhedron. Avoids new/delete for quick work. Can only be in use by one chunk of code at a time
{
AssertMsg( s_TempMemoryPolyhedron.iReferenceCount == 0, "Temporary polyhedron memory being rewritten before released" );
GeneratePolyhedronFromPlanes_LineLL *pConnectedLines; //keep these in a clockwise order, circular linking
floatfPlaneDist; //used in plane cutting
PolyhedronPointPlanarity planarity;
int iSaveIndices;
};
structGeneratePolyhedronFromPlanes_Line
{
GeneratePolyhedronFromPlanes_Point *pPoints[2]; //the 2 connecting points in no particular order
GeneratePolyhedronFromPlanes_Polygon *pPolygons[2]; //viewing from the outside with the point connections going up, 0 is the left polygon, 1 is the right
int iSaveIndices;
bool bAlive; //connected to at least one living point
bool bCut; //connected to at least one dead point
GeneratePolyhedronFromPlanes_LineLL *pPointLineLinks[2]; //rather than going into a point and searching for its link to this line, lets just cache it to eliminate searching
GeneratePolyhedronFromPlanes_LineLL *pPolygonLineLinks[2]; //rather than going into a polygon and searching for its link to this line, lets just cache it to eliminate searching
#ifdef POLYHEDRON_EXTENSIVE_DEBUGGING
int iDebugFlags;
#endif
};
structGeneratePolyhedronFromPlanes_LineLL
{
GeneratePolyhedronFromPlanes_Line *pLine;
int iReferenceIndex; //whatever is referencing the line should know which side of the line it's on (points and polygons), for polygons, it's which point to follow to continue going clockwise, which makes polygon 0 the one on the left side of an upward facing line vector, for points, it's the OTHER point's index
GeneratePolyhedronFromPlanes_LineLL *pPrev;
GeneratePolyhedronFromPlanes_LineLL *pNext;
};
structGeneratePolyhedronFromPlanes_Polygon
{
Vector vSurfaceNormal;
GeneratePolyhedronFromPlanes_LineLL *pLines; //keep these in a clockwise order, circular linking
bool bMissingASide;
};
structGeneratePolyhedronFromPlanes_UnorderedPolygonLL//an unordered collection of polygons
//A large part of clipping will either eliminate the polyhedron entirely, or clip nothing at all, so lets just check for those first and throw away useless planes
boolFindConvexShapeLooseAABB( constfloat *pInwardFacingPlanes, int iPlaneCount, Vector *pAABBMins, Vector *pAABBMaxs ) //bounding box of the convex shape (subject to floating point error)
{
//returns false if the AABB hasn't been set
if( pAABBMins == NULL && pAABBMaxs == NULL ) //no use in actually finding out what it is
float *vertsIn = NULL; //we'll be allocating a new buffer for this with each new polygon, and moving it off to the polygon array
float *vertsOut = (float *)stackalloc( (iPlaneCount + 4) * (sizeof( float ) * 3) ); //each plane will initially have 4 points in its polygon representation, and each plane clip has the possibility to add 1 point to the polygon
//pIndexArray[iIndexCount] = pLineWalk->pLine->pPoints[pLineWalk->iReferenceIndex]->iWorkData; //startpoint of each line, iWorkData is the index of the vertex