diff --git a/frustum.c b/frustum.c index 5add92a..1de6eb4 100644 --- a/frustum.c +++ b/frustum.c @@ -4,7 +4,7 @@ #include -static SVECTOR *left, *right, *top, *bottom; +static SVECTOR *left, *right, *top, *bottom, *front; static INLINE void frustum_buildPlane(MATRIX *rot_matrix, VECTOR *normal, SVECTOR *outPlane) { @@ -15,7 +15,7 @@ static INLINE void frustum_buildPlane(MATRIX *rot_matrix, VECTOR *normal, SVECTO void frustum_update(int width, int height) { - VECTOR l, r, t, b; + VECTOR l, r, t, b, f; int near; gte_ReadGeomScreen(&near); @@ -41,6 +41,10 @@ void frustum_update(int width, int height) t.vy = ONE; t.vz = -b.vz; + f.vx = 0; + f.vy = ONE; + f.vz = 0; + MATRIX rot_matrix; RotMatrixQ(&cam_rot, &rot_matrix); @@ -49,11 +53,14 @@ void frustum_update(int width, int height) right = (SVECTOR*)(scratchpad + sizeof(SVECTOR) * 1); top = (SVECTOR*)(scratchpad + sizeof(SVECTOR) * 2); bottom = (SVECTOR*)(scratchpad + sizeof(SVECTOR) * 3); + front = (SVECTOR*)(scratchpad + sizeof(SVECTOR) * 4); frustum_buildPlane(&rot_matrix, &l, left); frustum_buildPlane(&rot_matrix, &r, right); frustum_buildPlane(&rot_matrix, &t, top); frustum_buildPlane(&rot_matrix, &b, bottom); + frustum_buildPlane(&rot_matrix, &f, front); + front->pad -= near >> 1; // FntPrint(-1, "l = %d %d, r = %d %d, t = %d %d, b = %d %d\n", // left.vx, left.pad, right.vx, right.pad, top.vz, top.pad, bottom.vz, bottom.pad); @@ -99,3 +106,8 @@ u_char frustum_boxInside(const SVECTOR *min, const SVECTOR *max) if (frustum_pointInside_((SVECTOR) { max->vx, max->vy, max->vz })) return 1; return 0; } + +int frustum_pointDepth(const SVECTOR *point) +{ + return m_dot12(front, point) + front->pad; +} diff --git a/frustum.h b/frustum.h index c9e0796..b0e1379 100644 --- a/frustum.h +++ b/frustum.h @@ -5,5 +5,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); +int frustum_pointDepth(const SVECTOR *point); #endif // __FRUSTUM_H__ diff --git a/world.c b/world.c index 53e9a95..b08e12d 100644 --- a/world.c +++ b/world.c @@ -469,7 +469,7 @@ void world_draw(const world_t *world) cam_leaf = world_leafAtPoint(world, &cam_pos); - u_char *pvsbuf = scratchpad + 32; // Place the PVS data after the frustum in fast RAM + u_char *pvsbuf = scratchpad + 48; // Place the PVS data after the frustum in fast RAM u_char *pvs = world_loadVisData(world, cam_leaf, &pvsbuf); //u_char *pvs = world_noVisData(world, &pvsbuf);