From 9c1cbd467e2f4391903a199614a5694bd219c983 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Wed, 25 Jan 2023 12:44:50 +0100 Subject: [PATCH] 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 --- display.c | 8 ++++++-- qmath.h | 8 ++++---- world.c | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/display.c b/display.c index 11ff9ce..9253ac2 100644 --- a/display.c +++ b/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; diff --git a/qmath.h b/qmath.h index 4b2ac13..1839310 100644 --- a/qmath.h +++ b/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__ diff --git a/world.c b/world.c index 146bf9c..edb1f38 100644 --- a/world.c +++ b/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)