diff --git a/frustum.c b/frustum.c index f50865f..e8975e8 100644 --- a/frustum.c +++ b/frustum.c @@ -53,6 +53,15 @@ void frustum_update(int width, int height) // left.vx, left.pad, right.vx, right.pad, top.vz, top.pad, bottom.vz, bottom.pad); } +static INLINE u_char frustum_pointInside_(const SVECTOR p) +{ + if (m_dot12(left, p) + left.pad < 0) return 0; + if (m_dot12(right, p) + right.pad < 0) return 0; + if (m_dot12(top, p) + top.pad < 0) return 0; + if (m_dot12(bottom, p) + bottom.pad < 0) return 0; + return 1; +} + u_char frustum_pointInside(const SVECTOR *point) { if (m_dot12(left, *point) + left.pad < 0) return 0; @@ -71,3 +80,16 @@ u_char frustum_sphereInside(const SVECTOR *sphere) if (m_dot12(bottom, *sphere) + bottom.pad < radius) return 0; return 1; } + +u_char frustum_boxInside(const SVECTOR *min, const SVECTOR *max) +{ + if (frustum_pointInside_((SVECTOR) { min->vx, min->vy, min->vz })) return 1; + if (frustum_pointInside_((SVECTOR) { min->vx, min->vy, max->vz })) return 1; + if (frustum_pointInside_((SVECTOR) { min->vx, max->vy, min->vz })) return 1; + if (frustum_pointInside_((SVECTOR) { min->vx, max->vy, max->vz })) return 1; + if (frustum_pointInside_((SVECTOR) { max->vx, min->vy, min->vz })) return 1; + if (frustum_pointInside_((SVECTOR) { max->vx, min->vy, max->vz })) return 1; + if (frustum_pointInside_((SVECTOR) { max->vx, max->vy, min->vz })) return 1; + if (frustum_pointInside_((SVECTOR) { max->vx, max->vy, max->vz })) return 1; + return 0; +} diff --git a/frustum.h b/frustum.h index 244502d..c9e0796 100644 --- a/frustum.h +++ b/frustum.h @@ -4,5 +4,6 @@ void frustum_update(int width, int height); u_char frustum_pointInside(const SVECTOR *point); u_char frustum_sphereInside(const SVECTOR *sphere); +u_char frustum_boxInside(const SVECTOR *min, const SVECTOR *max); #endif // __FRUSTUM_H__ diff --git a/ps1bsp.h b/ps1bsp.h index d9bd4c6..17c3513 100755 --- a/ps1bsp.h +++ b/ps1bsp.h @@ -138,18 +138,18 @@ typedef struct SVECTOR boundingSphere; } ps1bsp_node_t; -typedef struct +typedef struct ps1bsp_leaf_s { - int type; + short type; int vislist; - SVECTOR boundingSphere; + SVECTOR mins, maxs; u_short firstLeafFace; u_short numLeafFaces; // Run-time data - u_short nextLeaf; // For chaining leafs in drawing order + struct ps1bsp_leaf_s *nextLeaf; // For chaining leafs in drawing order u_short leafDepth; // At what depth the leaf's faces should be placed in the ordering table } ps1bsp_leaf_t; diff --git a/test.ps1bsp b/test.ps1bsp index 60d25db..8c18893 100755 Binary files a/test.ps1bsp and b/test.ps1bsp differ diff --git a/world.c b/world.c index 262e70c..31139e2 100644 --- a/world.c +++ b/world.c @@ -200,7 +200,7 @@ static void world_drawnode(const world_t *world, short nodeIdx, u_char *pvs) return; const ps1bsp_leaf_t *leaf = &world->leaves[~nodeIdx]; - // if (!frustum_sphereInside(&leaf->boundingSphere)) // TODO: not sure if it's actually faster to do all these additional frustum checks + // if (!frustum_boxInside(&leaf->mins, &leaf->maxs)) // TODO: these additional frustum checks actually make things slower, probably not worth it // return; u_long frameNum = time_getFrameNumber();