Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

Plane.c File Reference

#include <Assert.h>
#include <Windows.h>
#include <Math.h>
#include "BaseType.h"
#include "System.h"
#include "World.h"
#include "GBSPFile.h"
#include "Vec3d.h"
#include "XForm3d.h"
#include "Plane.h"

Go to the source code of this file.

Functions

geBoolean GENESISCC Plane_SetEngine (geEngine *Engine)
geBoolean GENESISCC Plane_SetWorld (geWorld *World)
geBoolean GENESISCC Plane_SetGBSP (World_BSP *BSP)
int32 GENESISCC Plane_FindLeaf (const geWorld *World, int32 Node, const geVec3d *POV)
geFloat GENESISCC Plane_PlaneDistanceFast (const GFX_Plane *Plane, const geVec3d *Point)
geFloat GENESISCC Plane_PlaneDistance (const GFX_Plane *Plane, const geVec3d *Point)
geFloat GENESISCC Plane_FaceDistanceFast (const GFX_Face *Face, const geVec3d *Point)
void gePlane_SetFromVerts (GFX_Plane *Plane, const geVec3d *V1, const geVec3d *V2, const geVec3d *V3)

Variables

geEngineCEngine
geWorldCWorld
GBSP_BSPDataBSPData


Function Documentation

void gePlane_SetFromVerts GFX_Plane Plane,
const geVec3d V1,
const geVec3d V2,
const geVec3d V3
 

Definition at line 207 of file Plane.c.

References GFX_Plane::Dist, geVec3d_CrossProduct(), geVec3d_DotProduct(), geVec3d_Normalize(), geVec3d_Subtract(), GFX_Plane::Normal, PLANE_ANY, GFX_Plane::Type, V1, and V2.

Referenced by RenderFace().

00208 {
00209         geVec3d         Vect1, Vect2;
00210         
00211         // Get the 2 vectors to derive the normal
00212         geVec3d_Subtract(V1, V2, &Vect1);
00213         geVec3d_Subtract(V3, V2, &Vect2);
00214         
00215         // The normal is the cross between these 2 vectors
00216         geVec3d_CrossProduct(&Vect1, &Vect2, &Plane->Normal);
00217         geVec3d_Normalize(&Plane->Normal);
00218 
00219         // Get the planes distance from the origin, by projecting a vert on the plane
00220         // along the plane normal, to the origin...
00221         Plane->Dist = geVec3d_DotProduct(V1, &Plane->Normal);
00222 
00223         // Finally, get the plane type
00224         Plane->Type = PLANE_ANY;
00225 }

geFloat GENESISCC Plane_FaceDistanceFast const GFX_Face Face,
const geVec3d Point
 

Definition at line 167 of file Plane.c.

References BSPData, GFX_Plane::Dist, geFloat, GENESISCC, geVec3d_DotProduct(), GBSP_BSPData::GFXPlanes, GFX_Plane::Normal, NULL, PLANE_X, PLANE_Y, PLANE_Z, GFX_Face::PlaneNum, GFX_Face::PlaneSide, GFX_Plane::Type, geVec3d::X, geVec3d::Y, and geVec3d::Z.

00168 {
00169         geFloat         Dist, PDist;
00170         GFX_Plane       *Plane;
00171 
00172         assert(Face != NULL);
00173         assert(Point != NULL);
00174 
00175         assert(BSPData != NULL);
00176         assert(BSPData->GFXPlanes != NULL);
00177         
00178         Plane = &BSPData->GFXPlanes[Face->PlaneNum];
00179         PDist = Plane->Dist;
00180 
00181         switch (Plane->Type)
00182         {
00183                 case PLANE_X:
00184                         Dist = (Point->X - PDist);
00185                         break;
00186                 case PLANE_Y:
00187                         Dist = (Point->Y - PDist);
00188                         break;
00189                 case PLANE_Z:
00190                         Dist = (Point->Z - PDist);
00191                         break;
00192               
00193                 default:
00194                         Dist = geVec3d_DotProduct(Point, &Plane->Normal) - PDist;
00195                         break;
00196         }
00197 
00198         if (Face->PlaneSide)
00199                 Dist = -Dist;
00200 
00201         return Dist;
00202 }

int32 GENESISCC Plane_FindLeaf const geWorld World,
int32  Node,
const geVec3d POV
 

Definition at line 84 of file Plane.c.

References World_BSP::BSPData, GFX_Node::Children, geWorld::CurrentBSP, geFloat, GENESISCC, GBSP_BSPData::GFXNodes, GBSP_BSPData::GFXPlanes, int32, and Plane_PlaneDistanceFast().

Referenced by geWorld_GetLeaf(), geWorld_LinkPolyToLeaf(), and Vis_VisWorld().

00085 {
00086     geFloat             Dist;
00087         GFX_Node        *GFXNodes;
00088         GFX_Plane       *GFXPlanes;
00089         int32           Leaf;
00090 
00091         GFXNodes = World->CurrentBSP->BSPData.GFXNodes;
00092         GFXPlanes = World->CurrentBSP->BSPData.GFXPlanes;
00093 
00094     while (Node >= 0) 
00095         {
00096                 assert(Node >= 0 && Node < World->CurrentBSP->BSPData.NumGFXNodes);
00097         
00098                 Dist = Plane_PlaneDistanceFast(&GFXPlanes[GFXNodes[Node].PlaneNum], POV);
00099         
00100                 if (Dist < 0) 
00101             Node = GFXNodes[Node].Children[1];
00102                 else
00103             Node = GFXNodes[Node].Children[0];
00104     }
00105         
00106         // We are now in a leaf
00107         Leaf = -(Node+1);
00108 
00109         assert(Leaf >=0 && Leaf < World->CurrentBSP->BSPData.NumGFXLeafs);
00110         
00111         return Leaf;
00112 }

geFloat GENESISCC Plane_PlaneDistance const GFX_Plane Plane,
const geVec3d Point
 

Definition at line 151 of file Plane.c.

References GFX_Plane::Dist, geFloat, GENESISCC, geVec3d_DotProduct(), GFX_Plane::Normal, and NULL.

00152 {
00153         geFloat Dist;
00154 
00155         assert(Plane != NULL);
00156         assert(Point != NULL);
00157 
00158         Dist = geVec3d_DotProduct(Point, &Plane->Normal) - Plane->Dist;
00159 
00160         return Dist;
00161 }

geFloat GENESISCC Plane_PlaneDistanceFast const GFX_Plane Plane,
const geVec3d Point
 

Definition at line 118 of file Plane.c.

References GFX_Plane::Dist, geFloat, GENESISCC, geVec3d_DotProduct(), GFX_Plane::Normal, NULL, PLANE_X, PLANE_Y, PLANE_Z, GFX_Plane::Type, geVec3d::X, geVec3d::Y, and geVec3d::Z.

Referenced by BSPIntersect(), BSPIntersectMisc(), BSPIntersectMisc2(), IntersectLeafSides_r(), Plane_FindBNodeContents(), Plane_FindLeaf(), PointInLeafSides(), RenderBSPFrontBack_r(), RenderBSPFrontBack_r2(), SetupDynamicLight_r(), Trace_CollideBeam(), and Trace_IntersectWorldBSP().

00119 {
00120         geFloat Dist, PDist;
00121 
00122         assert(Plane != NULL);
00123         assert(Point != NULL);
00124 
00125         PDist = Plane->Dist;
00126 
00127         switch (Plane->Type)
00128         {
00129                 case PLANE_X:
00130                         Dist = (Point->X - PDist);
00131                         break;
00132                 case PLANE_Y:
00133                         Dist = (Point->Y - PDist);
00134                         break;
00135                 case PLANE_Z:
00136                         Dist = (Point->Z - PDist);
00137                         break;
00138               
00139                 default:
00140                         Dist = geVec3d_DotProduct(Point, &Plane->Normal) - PDist;
00141                         break;
00142         }
00143 
00144         return Dist;
00145 }

geBoolean GENESISCC Plane_SetEngine geEngine Engine  ) 
 

Definition at line 46 of file Plane.c.

References CEngine, Engine, GE_TRUE, geBoolean, GENESISCC, and NULL.

Referenced by World_SetEngine().

00047 {
00048         assert (Engine != NULL);
00049 
00050         CEngine = Engine;
00051 
00052         return GE_TRUE;
00053 }

geBoolean GENESISCC Plane_SetGBSP World_BSP BSP  ) 
 

Definition at line 71 of file Plane.c.

References BSPData, World_BSP::BSPData, GE_TRUE, geBoolean, GENESISCC, and NULL.

Referenced by World_SetGBSP().

00072 {
00073         assert(BSP != NULL);
00074 
00075         // Make quick pointer to the world bsp data
00076         BSPData = &BSP->BSPData;
00077 
00078         return GE_TRUE;
00079 }

geBoolean GENESISCC Plane_SetWorld geWorld World  ) 
 

Definition at line 59 of file Plane.c.

References CWorld, GE_TRUE, geBoolean, GENESISCC, and NULL.

Referenced by World_SetWorld().

00060 {
00061         assert(World != NULL);
00062         
00063         CWorld = World;
00064 
00065         return GE_TRUE;
00066 }


Variable Documentation

GBSP_BSPData* BSPData [static]
 

Definition at line 39 of file Plane.c.

Referenced by Plane_FaceDistanceFast(), and Plane_SetGBSP().

geEngine* CEngine [static]
 

Definition at line 37 of file Plane.c.

Referenced by Plane_SetEngine().

geWorld* CWorld [static]
 

Definition at line 38 of file Plane.c.

Referenced by Plane_SetWorld().


Generated on Tue Sep 30 12:37:55 2003 for GTestAndEngine by doxygen 1.3.2