diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 21f7c6c45..a75274615 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -37,6 +37,7 @@ add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32
m_random.c
m_tokenizer.c
m_queue.c
+ m_vector.c
info.c
p_ceilng.c
p_enemy.c
diff --git a/src/Sourcefile b/src/Sourcefile
index ad5eacfeb..60ee5db5b 100644
--- a/src/Sourcefile
+++ b/src/Sourcefile
@@ -31,6 +31,7 @@ m_perfstats.c
m_random.c
m_tokenizer.c
m_queue.c
+m_vector.c
info.c
p_ceilng.c
p_enemy.c
diff --git a/src/lua_maplib.c b/src/lua_maplib.c
index 5b80d4d38..83f4964bf 100644
--- a/src/lua_maplib.c
+++ b/src/lua_maplib.c
@@ -2609,12 +2609,16 @@ static int slope_set(lua_State *L)
slope->o.z = luaL_checkfixed(L, -1);
else
slope->o.z = 0;
+ slope->dorigin.x = FixedToDouble(slope->o.x);
+ slope->dorigin.y = FixedToDouble(slope->o.y);
+ slope->dorigin.z = FixedToDouble(slope->o.z);
lua_pop(L, 1);
break;
}
- case slope_zdelta: { // zdelta, this is temp until i figure out wtf to do
+ case slope_zdelta: { // zdelta
slope->zdelta = luaL_checkfixed(L, 3);
slope->zangle = R_PointToAngle2(0, 0, FRACUNIT, -slope->zdelta);
+ slope->dzdelta = FixedToDouble(slope->zdelta);
P_CalculateSlopeNormal(slope);
break;
}
@@ -2624,6 +2628,7 @@ static int slope_set(lua_State *L)
return luaL_error(L, "invalid zangle for slope!");
slope->zangle = zangle;
slope->zdelta = -FINETANGENT(((slope->zangle+ANGLE_90)>>ANGLETOFINESHIFT) & 4095);
+ slope->dzdelta = FixedToDouble(slope->zdelta);
P_CalculateSlopeNormal(slope);
break;
}
@@ -2631,6 +2636,8 @@ static int slope_set(lua_State *L)
slope->xydirection = luaL_checkangle(L, 3);
slope->d.x = -FINECOSINE((slope->xydirection>>ANGLETOFINESHIFT) & FINEMASK);
slope->d.y = -FINESINE((slope->xydirection>>ANGLETOFINESHIFT) & FINEMASK);
+ slope->dnormdir.x = FixedToDouble(slope->d.x);
+ slope->dnormdir.y = FixedToDouble(slope->d.y);
P_CalculateSlopeNormal(slope);
break;
}
diff --git a/src/m_fixed.c b/src/m_fixed.c
index b674e3b2c..19c1e8091 100644
--- a/src/m_fixed.c
+++ b/src/m_fixed.c
@@ -3,6 +3,7 @@
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2023 by Sonic Team Junior.
+// Copyright (C) 2009 by Stephen McGranahan.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
diff --git a/src/m_fixed.h b/src/m_fixed.h
index 4e644c9b6..f40c7b308 100644
--- a/src/m_fixed.h
+++ b/src/m_fixed.h
@@ -50,6 +50,20 @@ FUNCMATH FUNCINLINE static ATTRINLINE fixed_t FloatToFixed(float f)
return (fixed_t)(f * FRACUNIT);
}
+/*!
+ \brief convert fixed_t into double-precision floating number
+*/
+
+FUNCMATH FUNCINLINE static ATTRINLINE double FixedToDouble(fixed_t x)
+{
+ return x / (double)FRACUNIT;
+}
+
+FUNCMATH FUNCINLINE static ATTRINLINE fixed_t DoubleToFixed(double f)
+{
+ return (fixed_t)(f * FRACUNIT);
+}
+
// for backwards compat
#define FIXED_TO_FLOAT(x) FixedToFloat(x) // (((float)(x)) / ((float)FRACUNIT))
#define FLOAT_TO_FIXED(f) FloatToFixed(f) // (fixed_t)((f) * ((float)FRACUNIT))
diff --git a/src/m_vector.c b/src/m_vector.c
new file mode 100644
index 000000000..546826c76
--- /dev/null
+++ b/src/m_vector.c
@@ -0,0 +1,53 @@
+// SONIC ROBO BLAST 2
+//-----------------------------------------------------------------------------
+// Copyright (C) 1999-2024 by Sonic Team Junior.
+// Copyright (C) 2009 by Stephen McGranahan.
+//
+// This program is free software distributed under the
+// terms of the GNU General Public License, version 2.
+// See the 'LICENSE' file for more details.
+//-----------------------------------------------------------------------------
+/// \file m_vector.c
+/// \brief Basic vector functions
+
+#include "doomdef.h"
+
+#include "m_vector.h"
+
+void DVector3_Load(dvector3_t *vec, double x, double y, double z)
+{
+ vec->x = x;
+ vec->y = y;
+ vec->z = z;
+}
+
+double DVector3_Magnitude(const dvector3_t *a_normal)
+{
+ double xs = a_normal->x * a_normal->x;
+ double ys = a_normal->y * a_normal->y;
+ double zs = a_normal->z * a_normal->z;
+ return sqrt(xs + ys + zs);
+}
+
+double DVector3_Normalize(dvector3_t *a_normal)
+{
+ double magnitude = DVector3_Magnitude(a_normal);
+ a_normal->x /= magnitude;
+ a_normal->y /= magnitude;
+ a_normal->z /= magnitude;
+ return magnitude;
+}
+
+void DVector3_Negate(dvector3_t *a_o)
+{
+ a_o->x = -a_o->x;
+ a_o->y = -a_o->y;
+ a_o->z = -a_o->z;
+}
+
+void DVector3_Cross(const dvector3_t *a_1, const dvector3_t *a_2, dvector3_t *a_o)
+{
+ a_o->x = (a_1->y * a_2->z) - (a_1->z * a_2->y);
+ a_o->y = (a_1->z * a_2->x) - (a_1->x * a_2->z);
+ a_o->z = (a_1->x * a_2->y) - (a_1->y * a_2->x);
+}
diff --git a/src/m_vector.h b/src/m_vector.h
new file mode 100644
index 000000000..abd23f1cf
--- /dev/null
+++ b/src/m_vector.h
@@ -0,0 +1,27 @@
+// SONIC ROBO BLAST 2
+//-----------------------------------------------------------------------------
+// Copyright (C) 1999-2024 by Sonic Team Junior.
+// Copyright (C) 2009 by Stephen McGranahan.
+//
+// This program is free software distributed under the
+// terms of the GNU General Public License, version 2.
+// See the 'LICENSE' file for more details.
+//-----------------------------------------------------------------------------
+/// \file m_vector.h
+/// \brief Basic vector functions
+
+#ifndef __M_VECTOR__
+#define __M_VECTOR__
+
+typedef struct
+{
+ double x, y, z;
+} dvector3_t;
+
+void DVector3_Load(dvector3_t *vec, double x, double y, double z);
+double DVector3_Magnitude(const dvector3_t *a_normal);
+double DVector3_Normalize(dvector3_t *a_normal);
+void DVector3_Negate(dvector3_t *a_o);
+void DVector3_Cross(const dvector3_t *a_1, const dvector3_t *a_2, dvector3_t *a_o);
+
+#endif
diff --git a/src/p_setup.c b/src/p_setup.c
index 851231c42..84cb5920b 100644
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -1650,15 +1650,15 @@ textmap_colormap_t textmap_colormap = { false, 0, 25, 0, 25, 0, 31, 0 };
typedef enum
{
- PD_A = 1,
- PD_B = 1<<1,
- PD_C = 1<<2,
- PD_D = 1<<3,
+ PD_A = 1,
+ PD_B = 1<<1,
+ PD_C = 1<<2,
+ PD_D = 1<<3,
} planedef_t;
typedef struct textmap_plane_s {
- UINT8 defined;
- fixed_t a, b, c, d;
+ UINT8 defined;
+ double a, b, c, d;
} textmap_plane_t;
textmap_plane_t textmap_planefloor = {0, 0, 0, 0, 0};
@@ -1719,42 +1719,42 @@ static void ParseTextmapSectorParameter(UINT32 i, const char *param, const char
else if (fastcmp(param, "floorplane_a"))
{
textmap_planefloor.defined |= PD_A;
- textmap_planefloor.a = FLOAT_TO_FIXED(atof(val));
+ textmap_planefloor.a = atof(val);
}
else if (fastcmp(param, "floorplane_b"))
{
textmap_planefloor.defined |= PD_B;
- textmap_planefloor.b = FLOAT_TO_FIXED(atof(val));
+ textmap_planefloor.b = atof(val);
}
else if (fastcmp(param, "floorplane_c"))
{
textmap_planefloor.defined |= PD_C;
- textmap_planefloor.c = FLOAT_TO_FIXED(atof(val));
+ textmap_planefloor.c = atof(val);
}
else if (fastcmp(param, "floorplane_d"))
{
textmap_planefloor.defined |= PD_D;
- textmap_planefloor.d = FLOAT_TO_FIXED(atof(val));
+ textmap_planefloor.d = atof(val);
}
else if (fastcmp(param, "ceilingplane_a"))
{
textmap_planeceiling.defined |= PD_A;
- textmap_planeceiling.a = FLOAT_TO_FIXED(atof(val));
+ textmap_planeceiling.a = atof(val);
}
else if (fastcmp(param, "ceilingplane_b"))
{
textmap_planeceiling.defined |= PD_B;
- textmap_planeceiling.b = FLOAT_TO_FIXED(atof(val));
+ textmap_planeceiling.b = atof(val);
}
else if (fastcmp(param, "ceilingplane_c"))
{
textmap_planeceiling.defined |= PD_C;
- textmap_planeceiling.c = FLOAT_TO_FIXED(atof(val));
+ textmap_planeceiling.c = atof(val);
}
else if (fastcmp(param, "ceilingplane_d"))
{
textmap_planeceiling.defined |= PD_D;
- textmap_planeceiling.d = FLOAT_TO_FIXED(atof(val));
+ textmap_planeceiling.d = atof(val);
}
else if (fastcmp(param, "lightcolor"))
{
@@ -2992,13 +2992,13 @@ static void P_LoadTextmap(void)
if (textmap_planefloor.defined == (PD_A|PD_B|PD_C|PD_D))
{
- sc->f_slope = MakeViaEquationConstants(textmap_planefloor.a, textmap_planefloor.b, textmap_planefloor.c, textmap_planefloor.d);
+ sc->f_slope = P_MakeSlopeViaEquationConstants(textmap_planefloor.a, textmap_planefloor.b, textmap_planefloor.c, textmap_planefloor.d);
sc->hasslope = true;
}
if (textmap_planeceiling.defined == (PD_A|PD_B|PD_C|PD_D))
{
- sc->c_slope = MakeViaEquationConstants(textmap_planeceiling.a, textmap_planeceiling.b, textmap_planeceiling.c, textmap_planeceiling.d);
+ sc->c_slope = P_MakeSlopeViaEquationConstants(textmap_planeceiling.a, textmap_planeceiling.b, textmap_planeceiling.c, textmap_planeceiling.d);
sc->hasslope = true;
}
diff --git a/src/p_slopes.c b/src/p_slopes.c
index 1c0ee81a7..a41a3343a 100644
--- a/src/p_slopes.c
+++ b/src/p_slopes.c
@@ -14,6 +14,7 @@
#include "r_defs.h"
#include "r_state.h"
#include "m_bbox.h"
+#include "m_vector.h"
#include "z_zone.h"
#include "p_local.h"
#include "p_spec.h"
@@ -34,6 +35,36 @@ void P_CalculateSlopeNormal(pslope_t *slope) {
slope->normal.y = FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), slope->d.y);
}
+static void CalculateVectors(pslope_t *slope, dvector3_t *dnormal)
+{
+ double hyp = hypot(dnormal->x, dnormal->y);
+ if (fpclassify(hyp) == FP_ZERO)
+ {
+ slope->dnormdir.x = slope->dnormdir.y = 0.0;
+ slope->dzdelta = 0.0;
+ }
+ else
+ {
+ slope->dnormdir.x = -(dnormal->x / hyp);
+ slope->dnormdir.y = -(dnormal->y / hyp);
+
+ slope->dzdelta = hyp / dnormal->z;
+ }
+}
+
+void P_RecalculateSlopeVectors(pslope_t *slope)
+{
+ dvector3_t dnormal;
+
+ dnormal.x = FixedToDouble(slope->normal.x);
+ dnormal.y = FixedToDouble(slope->normal.y);
+ dnormal.z = FixedToDouble(slope->normal.z);
+
+ DVector3_Load(&slope->dorigin, FixedToDouble(slope->o.x), FixedToDouble(slope->o.y), FixedToDouble(slope->o.z));
+
+ CalculateVectors(slope, &dnormal);
+}
+
/// Setup slope via 3 vertexes.
static void ReconfigureViaVertexes (pslope_t *slope, const vector3_t v1, const vector3_t v2, const vector3_t v3)
{
@@ -89,22 +120,31 @@ static void ReconfigureViaVertexes (pslope_t *slope, const vector3_t v1, const v
slope->xydirection = R_PointToAngle2(0, 0, slope->d.x, slope->d.y)+ANGLE_180;
slope->zangle = InvAngle(R_PointToAngle2(0, 0, FRACUNIT, slope->zdelta));
}
+
+ P_RecalculateSlopeVectors(slope);
}
/// Setup slope via constants.
-static void ReconfigureViaConstants (pslope_t *slope, const fixed_t a, const fixed_t b, const fixed_t c, const fixed_t d)
+static void ReconfigureViaConstants (pslope_t *slope, const double pa, const double pb, const double pc, const double pd)
{
fixed_t m;
fixed_t o = 0;
- vector3_t *normal = &slope->normal;
+ double d_o = 0.0;
+
+ fixed_t a = DoubleToFixed(pa), b = DoubleToFixed(pb), c = DoubleToFixed(pc), d = DoubleToFixed(pd);
if (c)
+ {
+ d_o = abs(c) <= FRACUNIT ? -(pd * (1.0 / pc)) : -(pd / pc);
o = abs(c) <= FRACUNIT ? -FixedMul(d, FixedDiv(FRACUNIT, c)) : -FixedDiv(d, c);
+ }
// Set origin.
FV3_Load(&slope->o, 0, 0, o);
// Get slope's normal.
+ vector3_t *normal = &slope->normal;
+
FV3_Load(normal, a, b, c);
FV3_Normalize(normal);
@@ -123,6 +163,17 @@ static void ReconfigureViaConstants (pslope_t *slope, const fixed_t a, const fix
// Get angles
slope->xydirection = R_PointToAngle2(0, 0, slope->d.x, slope->d.y)+ANGLE_180;
slope->zangle = InvAngle(R_PointToAngle2(0, 0, FRACUNIT, slope->zdelta));
+
+ dvector3_t dnormal;
+
+ DVector3_Load(&dnormal, pa, pb, pc);
+ DVector3_Normalize(&dnormal);
+ if (dnormal.z < 0)
+ DVector3_Negate(&dnormal);
+
+ DVector3_Load(&slope->dorigin, 0, 0, d_o);
+
+ CalculateVectors(slope, &dnormal);
}
/// Recalculate dynamic slopes.
@@ -162,6 +213,7 @@ void T_DynamicSlopeLine (dynlineplanethink_t* th)
slope->zdelta = FixedDiv(zdelta, th->extent);
slope->zangle = R_PointToAngle2(0, 0, th->extent, -zdelta);
P_CalculateSlopeNormal(slope);
+ P_RecalculateSlopeVectors(slope);
}
}
@@ -695,7 +747,7 @@ pslope_t *P_SlopeById(UINT16 id)
}
/// Creates a new slope from equation constants.
-pslope_t *MakeViaEquationConstants(const fixed_t a, const fixed_t b, const fixed_t c, const fixed_t d)
+pslope_t *P_MakeSlopeViaEquationConstants(const double a, const double b, const double c, const double d)
{
pslope_t* ret = Slope_Add(0);
diff --git a/src/p_slopes.h b/src/p_slopes.h
index 096bf8f82..78731c2a9 100644
--- a/src/p_slopes.h
+++ b/src/p_slopes.h
@@ -13,7 +13,7 @@
#ifndef P_SLOPES_H__
#define P_SLOPES_H__
-#include "m_fixed.h" // Vectors
+#include "m_fixed.h"
extern pslope_t *slopelist;
extern UINT16 slopecount;
@@ -51,6 +51,7 @@ typedef enum
void P_LinkSlopeThinkers (void);
void P_CalculateSlopeNormal(pslope_t *slope);
+void P_RecalculateSlopeVectors(pslope_t *slope);
void P_InitSlopes(void);
void P_SpawnSlopes(const boolean fromsave);
@@ -88,7 +89,7 @@ fixed_t P_GetWallTransferMomZ(mobj_t *mo, pslope_t *slope);
void P_HandleSlopeLanding(mobj_t *thing, pslope_t *slope);
void P_ButteredSlope(mobj_t *mo);
-pslope_t *MakeViaEquationConstants(const fixed_t a, const fixed_t b, const fixed_t c, const fixed_t d);
+pslope_t *P_MakeSlopeViaEquationConstants(const double a, const double b, const double c, const double d);
/// Dynamic plane type enum for the thinker. Will have a different functionality depending on this.
typedef enum {
diff --git a/src/r_defs.h b/src/r_defs.h
index 16c660b01..4e03afd81 100644
--- a/src/r_defs.h
+++ b/src/r_defs.h
@@ -16,6 +16,7 @@
// Some more or less basic data types we depend on.
#include "m_fixed.h"
+#include "m_vector.h"
// We rely on the thinker data struct to handle sound origins in sectors.
#include "d_think.h"
@@ -343,6 +344,11 @@ typedef struct pslope_s
angle_t zangle; /// Precomputed angle of the plane going up from the ground (not measured in degrees).
angle_t xydirection;/// Precomputed angle of the normal's projection on the XY plane.
+ dvector3_t dorigin;
+ dvector3_t dnormdir;
+
+ double dzdelta;
+
UINT8 flags; // Slope options
} pslope_t;
diff --git a/src/r_draw.c b/src/r_draw.c
index ff2e43df3..d51f2d3bd 100644
--- a/src/r_draw.c
+++ b/src/r_draw.c
@@ -113,8 +113,9 @@ UINT8 *ds_source; // points to the start of a flat
UINT8 *ds_transmap; // one of the translucency tables
// Vectors for Software's tilted slope drawers
-floatv3_t ds_su, ds_sv, ds_sz, ds_slopelight;
-float focallengthf, zeroheight;
+dvector3_t ds_su, ds_sv, ds_sz, ds_slopelight;
+double zeroheight;
+float focallengthf;
/** \brief Variable flat sizes
*/
diff --git a/src/r_draw.h b/src/r_draw.h
index 29370015a..329877e7f 100644
--- a/src/r_draw.h
+++ b/src/r_draw.h
@@ -66,13 +66,10 @@ extern boolean ds_powersoftwo, ds_solidcolor, ds_fog;
extern UINT8 *ds_source;
extern UINT8 *ds_transmap;
-typedef struct {
- float x, y, z;
-} floatv3_t;
-
// Vectors for Software's tilted slope drawers
-extern floatv3_t ds_su, ds_sv, ds_sz, ds_slopelight;
-extern float focallengthf, zeroheight;
+extern dvector3_t ds_su, ds_sv, ds_sz, ds_slopelight;
+extern double zeroheight;
+extern float focallengthf;
// Variable flat sizes
extern UINT32 nflatxshift;
diff --git a/src/r_fps.c b/src/r_fps.c
index de450aaa7..dd43ca8d4 100644
--- a/src/r_fps.c
+++ b/src/r_fps.c
@@ -19,9 +19,9 @@
#include "i_video.h"
#include "r_plane.h"
#include "p_spec.h"
+#include "p_slopes.h"
#include "r_state.h"
#include "z_zone.h"
-#include "console.h" // con_startup_loadprogress
#include "m_perfstats.h" // ps_metric_t
#ifdef HWRENDER
#include "hardware/hw_main.h" // for cv_glshearing
@@ -631,6 +631,7 @@ void R_ApplyLevelInterpolators(fixed_t frac)
R_LerpVector3(&interp->dynslope.oldo, &interp->dynslope.bako, frac, &interp->dynslope.slope->o);
R_LerpVector2(&interp->dynslope.oldd, &interp->dynslope.bakd, frac, &interp->dynslope.slope->d);
interp->dynslope.slope->zdelta = R_LerpFixed(interp->dynslope.oldzdelta, interp->dynslope.bakzdelta, frac);
+ P_RecalculateSlopeVectors(interp->dynslope.slope);
break;
}
}
diff --git a/src/r_plane.c b/src/r_plane.c
index 612c650fc..f3536dbb2 100644
--- a/src/r_plane.c
+++ b/src/r_plane.c
@@ -84,11 +84,11 @@ fixed_t yslopetab[MAXVIDHEIGHT*16];
fixed_t *yslope;
static fixed_t xoffs, yoffs;
-static floatv3_t slope_origin, slope_u, slope_v;
-static floatv3_t slope_lightu, slope_lightv;
+static dvector3_t slope_origin, slope_u, slope_v;
+static dvector3_t slope_lightu, slope_lightv;
static void CalcSlopePlaneVectors(visplane_t *pl, fixed_t xoff, fixed_t yoff);
-static void CalcSlopeLightVectors(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t height, float ang, angle_t plangle);
+static void CalcSlopeLightVectors(pslope_t *slope, fixed_t xpos, fixed_t ypos, double height, float ang, angle_t plangle);
static void DoSlopeCrossProducts(void);
static void DoSlopeLightCrossProduct(void);
@@ -660,16 +660,17 @@ static void R_DrawSkyPlane(visplane_t *pl)
}
}
-// Returns the height of the sloped plane at (x, y) as a 32.16 fixed_t
-static INT64 R_GetSlopeZAt(const pslope_t *slope, fixed_t x, fixed_t y)
+// Returns the height of the sloped plane at (x, y) as a double
+static double R_GetSlopeZAt(const pslope_t *slope, fixed_t x, fixed_t y)
{
- INT64 x64 = ((INT64)x - (INT64)slope->o.x);
- INT64 y64 = ((INT64)y - (INT64)slope->o.y);
+ // (d + a*x + b*y) * -(1.0 / c)
- x64 = (x64 * (INT64)slope->d.x) / FRACUNIT;
- y64 = (y64 * (INT64)slope->d.y) / FRACUNIT;
+ double px = FixedToDouble(x) - slope->dorigin.x;
+ double py = FixedToDouble(y) - slope->dorigin.y;
- return (INT64)slope->o.z + ((x64 + y64) * (INT64)slope->zdelta) / FRACUNIT;
+ double dist = (px * slope->dnormdir.x) + (py * slope->dnormdir.y);
+
+ return slope->dorigin.z + (dist * slope->dzdelta);
}
// Sets the texture origin vector of the sloped plane.
@@ -687,19 +688,19 @@ static void R_SetSlopePlaneOrigin(pslope_t *slope, fixed_t xpos, fixed_t ypos, f
// errors if the flat is rotated.
slope_origin.x = vxf * cos(ang) - vyf * sin(ang);
slope_origin.z = vxf * sin(ang) + vyf * cos(ang);
- slope_origin.y = (R_GetSlopeZAt(slope, -xoff, yoff) - zpos) / (float)FRACUNIT;
+ slope_origin.y = R_GetSlopeZAt(slope, -xoff, yoff) - FixedToDouble(zpos);
}
// This function calculates all of the vectors necessary for drawing a sloped plane.
void R_SetSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos, fixed_t xoff, fixed_t yoff, angle_t angle, angle_t plangle)
{
// I copied ZDoom's code and adapted it to SRB2... -Red
- fixed_t height, z_at_xy;
+ double height, z_at_xy;
float ang;
R_SetSlopePlaneOrigin(slope, xpos, ypos, zpos, xoff, yoff, angle);
- height = P_GetSlopeZAt(slope, xpos, ypos);
- zeroheight = FixedToFloat(height - zpos);
+ height = R_GetSlopeZAt(slope, xpos, ypos);
+ zeroheight = height - FixedToDouble(zpos);
ang = ANG2RAD(ANGLE_180 - (angle + plangle));
@@ -720,10 +721,10 @@ void R_SetSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos,
slope_u.z = -cos(ang);
plangle >>= ANGLETOFINESHIFT;
- z_at_xy = P_GetSlopeZAt(slope, xpos + FINESINE(plangle), ypos + FINECOSINE(plangle));
- slope_v.y = FixedToFloat(z_at_xy - height);
- z_at_xy = P_GetSlopeZAt(slope, xpos + FINECOSINE(plangle), ypos - FINESINE(plangle));
- slope_u.y = FixedToFloat(z_at_xy - height);
+ z_at_xy = R_GetSlopeZAt(slope, xpos + FINESINE(plangle), ypos + FINECOSINE(plangle));
+ slope_v.y = z_at_xy - height;
+ z_at_xy = R_GetSlopeZAt(slope, xpos + FINECOSINE(plangle), ypos - FINESINE(plangle));
+ slope_u.y = z_at_xy - height;
DoSlopeCrossProducts();
DoSlopeLightCrossProduct();
@@ -732,13 +733,13 @@ void R_SetSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos,
// This function calculates all of the vectors necessary for drawing a sloped and scaled plane.
void R_SetScaledSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos, fixed_t xs, fixed_t ys, fixed_t xoff, fixed_t yoff, angle_t angle, angle_t plangle)
{
- fixed_t height, z_at_xy;
+ double height, z_at_xy;
float ang;
R_SetSlopePlaneOrigin(slope, xpos, ypos, zpos, xoff, yoff, angle);
- height = P_GetSlopeZAt(slope, xpos, ypos);
- zeroheight = FixedToFloat(height - zpos);
+ height = R_GetSlopeZAt(slope, xpos, ypos);
+ zeroheight = height - FixedToDouble(zpos);
ang = ANG2RAD(ANGLE_180 - (angle + plangle));
@@ -762,18 +763,18 @@ void R_SetScaledSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t
slope_u.z = -xscale * cos(ang);
ang = ANG2RAD(plangle);
- z_at_xy = P_GetSlopeZAt(slope, xpos + FloatToFixed(yscale * sin(ang)), ypos + FloatToFixed(yscale * cos(ang)));
- slope_v.y = FixedToFloat(z_at_xy - height);
- z_at_xy = P_GetSlopeZAt(slope, xpos + FloatToFixed(xscale * cos(ang)), ypos - FloatToFixed(xscale * sin(ang)));
- slope_u.y = FixedToFloat(z_at_xy - height);
+ z_at_xy = R_GetSlopeZAt(slope, xpos + FloatToFixed(yscale * sin(ang)), ypos + FloatToFixed(yscale * cos(ang)));
+ slope_v.y = z_at_xy - height;
+ z_at_xy = R_GetSlopeZAt(slope, xpos + FloatToFixed(xscale * cos(ang)), ypos - FloatToFixed(xscale * sin(ang)));
+ slope_u.y = z_at_xy - height;
DoSlopeCrossProducts();
DoSlopeLightCrossProduct();
}
-static void CalcSlopeLightVectors(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t height, float ang, angle_t plangle)
+static void CalcSlopeLightVectors(pslope_t *slope, fixed_t xpos, fixed_t ypos, double height, float ang, angle_t plangle)
{
- fixed_t z_at_xy;
+ double z_at_xy;
slope_lightv.x = cos(ang);
slope_lightv.z = sin(ang);
@@ -782,25 +783,17 @@ static void CalcSlopeLightVectors(pslope_t *slope, fixed_t xpos, fixed_t ypos, f
slope_lightu.z = -cos(ang);
plangle >>= ANGLETOFINESHIFT;
- z_at_xy = P_GetSlopeZAt(slope, xpos + FINESINE(plangle), ypos + FINECOSINE(plangle));
- slope_lightv.y = FixedToFloat(z_at_xy - height);
- z_at_xy = P_GetSlopeZAt(slope, xpos + FINECOSINE(plangle), ypos - FINESINE(plangle));
- slope_lightu.y = FixedToFloat(z_at_xy - height);
+ z_at_xy = R_GetSlopeZAt(slope, xpos + FINESINE(plangle), ypos + FINECOSINE(plangle));
+ slope_lightv.y = z_at_xy - height;
+ z_at_xy = R_GetSlopeZAt(slope, xpos + FINECOSINE(plangle), ypos - FINESINE(plangle));
+ slope_lightu.y = z_at_xy - height;
}
-// Eh. I tried making this stuff fixed-point and it exploded on me. Here's a macro for the only floating-point vector function I recall using.
-#define CROSS(d, v1, v2) \
-d.x = (v1.y * v2.z) - (v1.z * v2.y);\
-d.y = (v1.z * v2.x) - (v1.x * v2.z);\
-d.z = (v1.x * v2.y) - (v1.y * v2.x)
-
static void DoSlopeCrossProducts(void)
{
- float sfmult = 65536.f;
-
- CROSS(ds_su, slope_origin, slope_v);
- CROSS(ds_sv, slope_origin, slope_u);
- CROSS(ds_sz, slope_v, slope_u);
+ DVector3_Cross(&slope_origin, &slope_v, &ds_su);
+ DVector3_Cross(&slope_origin, &slope_u, &ds_sv);
+ DVector3_Cross(&slope_v, &slope_u, &ds_sz);
ds_su.z *= focallengthf;
ds_sv.z *= focallengthf;
@@ -810,6 +803,8 @@ static void DoSlopeCrossProducts(void)
return;
// Premultiply the texture vectors with the scale factors
+ float sfmult = 65536.f;
+
if (ds_powersoftwo)
sfmult *= 1 << nflatshiftup;
@@ -823,13 +818,11 @@ static void DoSlopeCrossProducts(void)
static void DoSlopeLightCrossProduct(void)
{
- CROSS(ds_slopelight, slope_lightv, slope_lightu);
+ DVector3_Cross(&slope_lightv, &slope_lightu, &ds_slopelight);
ds_slopelight.z *= focallengthf;
}
-#undef CROSS
-
static void CalcSlopePlaneVectors(visplane_t *pl, fixed_t xoff, fixed_t yoff)
{
if (!ds_fog && (pl->xscale != FRACUNIT || pl->yscale != FRACUNIT))
diff --git a/src/sdl/Srb2SDL-vc10.vcxproj b/src/sdl/Srb2SDL-vc10.vcxproj
index 7142cb64c..462170078 100644
--- a/src/sdl/Srb2SDL-vc10.vcxproj
+++ b/src/sdl/Srb2SDL-vc10.vcxproj
@@ -295,6 +295,7 @@
+
@@ -473,6 +474,7 @@
+
diff --git a/src/sdl/Srb2SDL-vc10.vcxproj.filters b/src/sdl/Srb2SDL-vc10.vcxproj.filters
index 44c353ae2..59bb76b52 100644
--- a/src/sdl/Srb2SDL-vc10.vcxproj.filters
+++ b/src/sdl/Srb2SDL-vc10.vcxproj.filters
@@ -348,6 +348,9 @@
M_Misc
+
+ M_Misc
+
M_Misc
@@ -846,6 +849,9 @@
M_Misc
+
+ M_Misc
+
M_Misc
diff --git a/src/tables.c b/src/tables.c
index 315fe1d7a..d0fb428ba 100644
--- a/src/tables.c
+++ b/src/tables.c
@@ -3,6 +3,7 @@
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2023 by Sonic Team Junior.
+// Copyright (C) 2009 by Stephen McGranahan.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.