Browse Source

Small tweaks:

- Math functions return results in 32-bit int, cast back to short is done only where necessary
- Changed GTE screen distance to obtain an exact 90 degree horizontal FOV in 4:3 mode
unrollquadloop
Nico de Poel 3 years ago
parent
commit
9c1cbd467e
  1. 8
      display.c
  2. 8
      qmath.h
  3. 4
      world.c

8
display.c

@ -40,7 +40,8 @@ MATRIX light_dirs = {
MATRIX vp_matrix;
u_long *curOT;
// Scale X coordinates to correct the aspect ratio for the chosen resolution
// We're using a virtual screen resolution of 320x240, which is then scaled according to display resolution,
// video mode and widescreen options to maintain a consistent aspect ratio.
VECTOR aspect_scale = { SCREENWIDTH * ONE / 320, ONE, ONE };
u_short polyCount;
@ -53,7 +54,10 @@ void display_init()
// Initialize GTE
InitGeom();
gte_SetGeomScreen(180); // Screen depth for FOV control. Determines the distance of the camera to the near plane.
// Screen depth for FOV control. Determines the distance of the camera to the near plane.
// Setting this to half the virtual screen width gives us an exact 90 degree horizontal FOV when playing in 4:3 mode.
gte_SetGeomScreen(160);
// Start the display in progressive mode
int screenHeight;

8
qmath.h

@ -3,18 +3,18 @@
MATRIX *RotMatrixQ(SVECTOR *r, MATRIX *m);
INLINE short m_dot12s(const SVECTOR a, const SVECTOR b)
INLINE int m_dot12s(const SVECTOR a, const SVECTOR b)
{
return (short)(((int)a.vx * b.vx) >> 12) + (((int)a.vy * b.vy) >> 12) + (((int)a.vz * b.vz) >> 12);
return (((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 short 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;
return (short)(x + y + z - dist2);
return (x + y + z - dist2);
}
#endif // __QMATH_H__

4
world.c

@ -274,7 +274,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 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)
@ -283,7 +283,7 @@ static INLINE short world_planeDot(const SVECTOR *dir, const ps1bsp_plane_t *pla
if (plane->type < 3)
return ((short*)dir)[plane->type];
return m_dot12s(*dir, plane->normal);
return (short)m_dot12s(*dir, plane->normal);
}
static void world_drawface(const world_t *world, const ps1bsp_face_t *face)

Loading…
Cancel
Save