Browse Source

Changed dot product and point-plane distance functions to use vector pointers as input.

Matters nothing for performance, but it does lead to some slightly cleaner and more consistent code.
unrollquadloop
Nico de Poel 3 years ago
parent
commit
ef0d2ad723
  1. 26
      frustum.c
  2. 10
      qmath.h
  3. 6
      world.c

26
frustum.c

@ -10,7 +10,7 @@ static INLINE void frustum_buildPlane(MATRIX *rot_matrix, VECTOR *normal, SVECTO
{
ApplyMatrixLV(rot_matrix, normal, normal);
VectorNormalS(normal, outPlane);
outPlane->pad = -m_dot12(cam_pos, *outPlane);
outPlane->pad = -m_dot12(&cam_pos, outPlane);
}
void frustum_update(int width, int height)
@ -61,29 +61,29 @@ void frustum_update(int width, int height)
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;
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;
if (m_dot12(*right, *point) + right->pad < 0) return 0;
if (m_dot12(*top, *point) + top->pad < 0) return 0;
if (m_dot12(*bottom, *point) + bottom->pad < 0) return 0;
if (m_dot12(left, point) + left->pad < 0) return 0;
if (m_dot12(right, point) + right->pad < 0) return 0;
if (m_dot12(top, point) + top->pad < 0) return 0;
if (m_dot12(bottom, point) + bottom->pad < 0) return 0;
return 1;
}
u_char frustum_sphereInside(const SVECTOR *sphere)
{
short radius = -sphere->pad;
if (m_dot12(*left, *sphere) + left->pad < radius) return 0;
if (m_dot12(*right, *sphere) + right->pad < radius) return 0;
if (m_dot12(*top, *sphere) + top->pad < radius) return 0;
if (m_dot12(*bottom, *sphere) + bottom->pad < radius) return 0;
if (m_dot12(left, sphere) + left->pad < radius) return 0;
if (m_dot12(right, sphere) + right->pad < radius) return 0;
if (m_dot12(top, sphere) + top->pad < radius) return 0;
if (m_dot12(bottom, sphere) + bottom->pad < radius) return 0;
return 1;
}

10
qmath.h

@ -3,14 +3,14 @@
MATRIX *RotMatrixQ(SVECTOR *r, MATRIX *m);
#define m_dot12(a, b) ((((int)(a).vx * (b).vx) >> 12) + (((int)(a).vy * (b).vy) >> 12) + (((int)(a).vz * (b).vz) >> 12))
#define m_dot12(a, b) ((((int)((a)->vx) * (b)->vx) >> 12) + (((int)((a)->vy) * (b)->vy) >> 12) + (((int)((a)->vz) * (b)->vz) >> 12))
// TODO: worth a benchmark: is it faster to copy these vectors and use them from the stack, or to do six pointer dereferences?
INLINE int m_pointPlaneDist2(const VECTOR point2, const SVECTOR normal12, int dist2)
INLINE int m_pointPlaneDist2(const VECTOR* point2, const SVECTOR* normal12, int dist2)
{
int x = ((int)point2.vx * normal12.vx) >> 12;
int y = ((int)point2.vy * normal12.vy) >> 12;
int z = ((int)point2.vz * normal12.vz) >> 12;
int x = ((int)point2->vx * normal12->vx) >> 12;
int y = ((int)point2->vy * normal12->vy) >> 12;
int z = ((int)point2->vz * normal12->vz) >> 12;
return (x + y + z - dist2);
}

6
world.c

@ -60,7 +60,7 @@ static INLINE short world_pointPlaneDist(const VECTOR *point, const ps1bsp_plane
if (plane->type < 3)
return (short)(((int*)point)[plane->type] - plane->dist);
return (short)m_pointPlaneDist2(*point, plane->normal, plane->dist);
return (short)m_pointPlaneDist2(point, &plane->normal, plane->dist);
}
static INLINE short world_planeDot(const SVECTOR *dir, const ps1bsp_plane_t *plane)
@ -69,7 +69,7 @@ static INLINE short world_planeDot(const SVECTOR *dir, const ps1bsp_plane_t *pla
if (plane->type < 3)
return ((short*)dir)[plane->type];
return (short)m_dot12(*dir, plane->normal);
return (short)m_dot12(dir, &plane->normal);
}
static INLINE char world_cull_backface(const world_t *world, const ps1bsp_face_t *face, short *dot)
@ -103,7 +103,7 @@ static INLINE char world_cull_backface(const world_t *world, const ps1bsp_face_t
// NOTE: disabling the behind-the-camera check does *not* actually solve the problem of polygons disappearing when too close to the camera!
// This means that the GPU probably already clips polygons that stretch too far outside the drawing area. Tessellation should solve this.
if (m_dot12(cam_vec, cam_dir) >= 0)
if (m_dot12(&cam_vec, &cam_dir) >= 0)
return 0;
return 1;

Loading…
Cancel
Save