Browse Source

Sped up plane calculations by making use of axis-aligned properties

tess_experiment
Nico de Poel 3 years ago
parent
commit
b0d36ab11b
  1. 3
      ps1bsp.h
  2. BIN
      test.ps1bsp
  3. 16
      world.c

3
ps1bsp.h

@ -85,7 +85,8 @@ typedef struct
typedef struct
{
SVECTOR normal;
int dist;
short dist;
short type;
} ps1bsp_plane_t;
typedef struct

BIN
test.ps1bsp

16
world.c

@ -205,10 +205,22 @@ static INLINE void drawface_quad_strip(const ps1bsp_face_t *face, SVECTOR *vecs)
static INLINE short world_pointPlaneDist(const VECTOR *point, const ps1bsp_plane_t *plane)
{
// TODO: can be optimized for axis-aligned planes, no need for a dot product there
// Make use of axis-aligned planes to skip the need for a dot product
if (plane->type < 3)
return (short)(((int*)point)[plane->type] - plane->dist);
return m_pointPlaneDist2(*point, plane->normal, plane->dist);
}
static INLINE short world_planeDot(const SVECTOR *dir, const ps1bsp_plane_t *plane)
{
// Make use of axis-aligned planes to skip the need for a dot product
if (plane->type < 3)
return ((short*)dir)[plane->type];
return m_dot12s(*dir, plane->normal);
}
static void world_drawface(const world_t *world, const ps1bsp_face_t *face)
{
// Backface culling using the face's plane and center point
@ -219,7 +231,7 @@ static void world_drawface(const world_t *world, const ps1bsp_face_t *face)
cam_vec.vz = center.vz - cam_pos.vz;
const ps1bsp_plane_t *plane = &world->planes[face->planeId];
short dot = m_dot12s(cam_vec, plane->normal);
short dot = world_planeDot(&cam_vec, plane);
if ((dot >= 0) ^ face->side)
return;

Loading…
Cancel
Save