Fix slope plane distortion

This commit is contained in:
Lactozilla 2024-01-29 22:08:22 -03:00
parent 4649f3a46b
commit 6180ddde32
18 changed files with 240 additions and 76 deletions

View file

@ -37,6 +37,7 @@ add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32
m_random.c m_random.c
m_tokenizer.c m_tokenizer.c
m_queue.c m_queue.c
m_vector.c
info.c info.c
p_ceilng.c p_ceilng.c
p_enemy.c p_enemy.c

View file

@ -31,6 +31,7 @@ m_perfstats.c
m_random.c m_random.c
m_tokenizer.c m_tokenizer.c
m_queue.c m_queue.c
m_vector.c
info.c info.c
p_ceilng.c p_ceilng.c
p_enemy.c p_enemy.c

View file

@ -2609,12 +2609,16 @@ static int slope_set(lua_State *L)
slope->o.z = luaL_checkfixed(L, -1); slope->o.z = luaL_checkfixed(L, -1);
else else
slope->o.z = 0; 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); lua_pop(L, 1);
break; 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->zdelta = luaL_checkfixed(L, 3);
slope->zangle = R_PointToAngle2(0, 0, FRACUNIT, -slope->zdelta); slope->zangle = R_PointToAngle2(0, 0, FRACUNIT, -slope->zdelta);
slope->dzdelta = FixedToDouble(slope->zdelta);
P_CalculateSlopeNormal(slope); P_CalculateSlopeNormal(slope);
break; break;
} }
@ -2624,6 +2628,7 @@ static int slope_set(lua_State *L)
return luaL_error(L, "invalid zangle for slope!"); return luaL_error(L, "invalid zangle for slope!");
slope->zangle = zangle; slope->zangle = zangle;
slope->zdelta = -FINETANGENT(((slope->zangle+ANGLE_90)>>ANGLETOFINESHIFT) & 4095); slope->zdelta = -FINETANGENT(((slope->zangle+ANGLE_90)>>ANGLETOFINESHIFT) & 4095);
slope->dzdelta = FixedToDouble(slope->zdelta);
P_CalculateSlopeNormal(slope); P_CalculateSlopeNormal(slope);
break; break;
} }
@ -2631,6 +2636,8 @@ static int slope_set(lua_State *L)
slope->xydirection = luaL_checkangle(L, 3); slope->xydirection = luaL_checkangle(L, 3);
slope->d.x = -FINECOSINE((slope->xydirection>>ANGLETOFINESHIFT) & FINEMASK); slope->d.x = -FINECOSINE((slope->xydirection>>ANGLETOFINESHIFT) & FINEMASK);
slope->d.y = -FINESINE((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); P_CalculateSlopeNormal(slope);
break; break;
} }

View file

@ -3,6 +3,7 @@
// Copyright (C) 1993-1996 by id Software, Inc. // Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team. // Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2023 by Sonic Team Junior. // Copyright (C) 1999-2023 by Sonic Team Junior.
// Copyright (C) 2009 by Stephen McGranahan.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.

View file

@ -50,6 +50,20 @@ FUNCMATH FUNCINLINE static ATTRINLINE fixed_t FloatToFixed(float f)
return (fixed_t)(f * FRACUNIT); 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 // for backwards compat
#define FIXED_TO_FLOAT(x) FixedToFloat(x) // (((float)(x)) / ((float)FRACUNIT)) #define FIXED_TO_FLOAT(x) FixedToFloat(x) // (((float)(x)) / ((float)FRACUNIT))
#define FLOAT_TO_FIXED(f) FloatToFixed(f) // (fixed_t)((f) * ((float)FRACUNIT)) #define FLOAT_TO_FIXED(f) FloatToFixed(f) // (fixed_t)((f) * ((float)FRACUNIT))

53
src/m_vector.c Normal file
View file

@ -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);
}

27
src/m_vector.h Normal file
View file

@ -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

View file

@ -1658,7 +1658,7 @@ typedef enum
typedef struct textmap_plane_s { typedef struct textmap_plane_s {
UINT8 defined; UINT8 defined;
fixed_t a, b, c, d; double a, b, c, d;
} textmap_plane_t; } textmap_plane_t;
textmap_plane_t textmap_planefloor = {0, 0, 0, 0, 0}; 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")) else if (fastcmp(param, "floorplane_a"))
{ {
textmap_planefloor.defined |= PD_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")) else if (fastcmp(param, "floorplane_b"))
{ {
textmap_planefloor.defined |= PD_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")) else if (fastcmp(param, "floorplane_c"))
{ {
textmap_planefloor.defined |= PD_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")) else if (fastcmp(param, "floorplane_d"))
{ {
textmap_planefloor.defined |= PD_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")) else if (fastcmp(param, "ceilingplane_a"))
{ {
textmap_planeceiling.defined |= PD_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")) else if (fastcmp(param, "ceilingplane_b"))
{ {
textmap_planeceiling.defined |= PD_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")) else if (fastcmp(param, "ceilingplane_c"))
{ {
textmap_planeceiling.defined |= PD_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")) else if (fastcmp(param, "ceilingplane_d"))
{ {
textmap_planeceiling.defined |= PD_D; textmap_planeceiling.defined |= PD_D;
textmap_planeceiling.d = FLOAT_TO_FIXED(atof(val)); textmap_planeceiling.d = atof(val);
} }
else if (fastcmp(param, "lightcolor")) 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)) 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; sc->hasslope = true;
} }
if (textmap_planeceiling.defined == (PD_A|PD_B|PD_C|PD_D)) 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; sc->hasslope = true;
} }

View file

@ -14,6 +14,7 @@
#include "r_defs.h" #include "r_defs.h"
#include "r_state.h" #include "r_state.h"
#include "m_bbox.h" #include "m_bbox.h"
#include "m_vector.h"
#include "z_zone.h" #include "z_zone.h"
#include "p_local.h" #include "p_local.h"
#include "p_spec.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); 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. /// Setup slope via 3 vertexes.
static void ReconfigureViaVertexes (pslope_t *slope, const vector3_t v1, const vector3_t v2, const vector3_t v3) 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->xydirection = R_PointToAngle2(0, 0, slope->d.x, slope->d.y)+ANGLE_180;
slope->zangle = InvAngle(R_PointToAngle2(0, 0, FRACUNIT, slope->zdelta)); slope->zangle = InvAngle(R_PointToAngle2(0, 0, FRACUNIT, slope->zdelta));
} }
P_RecalculateSlopeVectors(slope);
} }
/// Setup slope via constants. /// 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 m;
fixed_t o = 0; 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) 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); o = abs(c) <= FRACUNIT ? -FixedMul(d, FixedDiv(FRACUNIT, c)) : -FixedDiv(d, c);
}
// Set origin. // Set origin.
FV3_Load(&slope->o, 0, 0, o); FV3_Load(&slope->o, 0, 0, o);
// Get slope's normal. // Get slope's normal.
vector3_t *normal = &slope->normal;
FV3_Load(normal, a, b, c); FV3_Load(normal, a, b, c);
FV3_Normalize(normal); FV3_Normalize(normal);
@ -123,6 +163,17 @@ static void ReconfigureViaConstants (pslope_t *slope, const fixed_t a, const fix
// Get angles // Get angles
slope->xydirection = R_PointToAngle2(0, 0, slope->d.x, slope->d.y)+ANGLE_180; slope->xydirection = R_PointToAngle2(0, 0, slope->d.x, slope->d.y)+ANGLE_180;
slope->zangle = InvAngle(R_PointToAngle2(0, 0, FRACUNIT, slope->zdelta)); 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. /// Recalculate dynamic slopes.
@ -162,6 +213,7 @@ void T_DynamicSlopeLine (dynlineplanethink_t* th)
slope->zdelta = FixedDiv(zdelta, th->extent); slope->zdelta = FixedDiv(zdelta, th->extent);
slope->zangle = R_PointToAngle2(0, 0, th->extent, -zdelta); slope->zangle = R_PointToAngle2(0, 0, th->extent, -zdelta);
P_CalculateSlopeNormal(slope); P_CalculateSlopeNormal(slope);
P_RecalculateSlopeVectors(slope);
} }
} }
@ -695,7 +747,7 @@ pslope_t *P_SlopeById(UINT16 id)
} }
/// Creates a new slope from equation constants. /// 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); pslope_t* ret = Slope_Add(0);

View file

@ -13,7 +13,7 @@
#ifndef P_SLOPES_H__ #ifndef P_SLOPES_H__
#define P_SLOPES_H__ #define P_SLOPES_H__
#include "m_fixed.h" // Vectors #include "m_fixed.h"
extern pslope_t *slopelist; extern pslope_t *slopelist;
extern UINT16 slopecount; extern UINT16 slopecount;
@ -51,6 +51,7 @@ typedef enum
void P_LinkSlopeThinkers (void); void P_LinkSlopeThinkers (void);
void P_CalculateSlopeNormal(pslope_t *slope); void P_CalculateSlopeNormal(pslope_t *slope);
void P_RecalculateSlopeVectors(pslope_t *slope);
void P_InitSlopes(void); void P_InitSlopes(void);
void P_SpawnSlopes(const boolean fromsave); 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_HandleSlopeLanding(mobj_t *thing, pslope_t *slope);
void P_ButteredSlope(mobj_t *mo); 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. /// Dynamic plane type enum for the thinker. Will have a different functionality depending on this.
typedef enum { typedef enum {

View file

@ -16,6 +16,7 @@
// Some more or less basic data types we depend on. // Some more or less basic data types we depend on.
#include "m_fixed.h" #include "m_fixed.h"
#include "m_vector.h"
// We rely on the thinker data struct to handle sound origins in sectors. // We rely on the thinker data struct to handle sound origins in sectors.
#include "d_think.h" #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 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. 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 UINT8 flags; // Slope options
} pslope_t; } pslope_t;

View file

@ -113,8 +113,9 @@ UINT8 *ds_source; // points to the start of a flat
UINT8 *ds_transmap; // one of the translucency tables UINT8 *ds_transmap; // one of the translucency tables
// Vectors for Software's tilted slope drawers // Vectors for Software's tilted slope drawers
floatv3_t ds_su, ds_sv, ds_sz, ds_slopelight; dvector3_t ds_su, ds_sv, ds_sz, ds_slopelight;
float focallengthf, zeroheight; double zeroheight;
float focallengthf;
/** \brief Variable flat sizes /** \brief Variable flat sizes
*/ */

View file

@ -66,13 +66,10 @@ extern boolean ds_powersoftwo, ds_solidcolor, ds_fog;
extern UINT8 *ds_source; extern UINT8 *ds_source;
extern UINT8 *ds_transmap; extern UINT8 *ds_transmap;
typedef struct {
float x, y, z;
} floatv3_t;
// Vectors for Software's tilted slope drawers // Vectors for Software's tilted slope drawers
extern floatv3_t ds_su, ds_sv, ds_sz, ds_slopelight; extern dvector3_t ds_su, ds_sv, ds_sz, ds_slopelight;
extern float focallengthf, zeroheight; extern double zeroheight;
extern float focallengthf;
// Variable flat sizes // Variable flat sizes
extern UINT32 nflatxshift; extern UINT32 nflatxshift;

View file

@ -19,9 +19,9 @@
#include "i_video.h" #include "i_video.h"
#include "r_plane.h" #include "r_plane.h"
#include "p_spec.h" #include "p_spec.h"
#include "p_slopes.h"
#include "r_state.h" #include "r_state.h"
#include "z_zone.h" #include "z_zone.h"
#include "console.h" // con_startup_loadprogress
#include "m_perfstats.h" // ps_metric_t #include "m_perfstats.h" // ps_metric_t
#ifdef HWRENDER #ifdef HWRENDER
#include "hardware/hw_main.h" // for cv_glshearing #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_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); 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); interp->dynslope.slope->zdelta = R_LerpFixed(interp->dynslope.oldzdelta, interp->dynslope.bakzdelta, frac);
P_RecalculateSlopeVectors(interp->dynslope.slope);
break; break;
} }
} }

View file

@ -84,11 +84,11 @@ fixed_t yslopetab[MAXVIDHEIGHT*16];
fixed_t *yslope; fixed_t *yslope;
static fixed_t xoffs, yoffs; static fixed_t xoffs, yoffs;
static floatv3_t slope_origin, slope_u, slope_v; static dvector3_t slope_origin, slope_u, slope_v;
static floatv3_t slope_lightu, slope_lightv; static dvector3_t slope_lightu, slope_lightv;
static void CalcSlopePlaneVectors(visplane_t *pl, fixed_t xoff, fixed_t yoff); 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 DoSlopeCrossProducts(void);
static void DoSlopeLightCrossProduct(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 // Returns the height of the sloped plane at (x, y) as a double
static INT64 R_GetSlopeZAt(const pslope_t *slope, fixed_t x, fixed_t y) static double R_GetSlopeZAt(const pslope_t *slope, fixed_t x, fixed_t y)
{ {
INT64 x64 = ((INT64)x - (INT64)slope->o.x); // (d + a*x + b*y) * -(1.0 / c)
INT64 y64 = ((INT64)y - (INT64)slope->o.y);
x64 = (x64 * (INT64)slope->d.x) / FRACUNIT; double px = FixedToDouble(x) - slope->dorigin.x;
y64 = (y64 * (INT64)slope->d.y) / FRACUNIT; 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. // 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. // errors if the flat is rotated.
slope_origin.x = vxf * cos(ang) - vyf * sin(ang); slope_origin.x = vxf * cos(ang) - vyf * sin(ang);
slope_origin.z = vxf * sin(ang) + vyf * cos(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. // 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) 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 // I copied ZDoom's code and adapted it to SRB2... -Red
fixed_t height, z_at_xy; double height, z_at_xy;
float ang; float ang;
R_SetSlopePlaneOrigin(slope, xpos, ypos, zpos, xoff, yoff, angle); R_SetSlopePlaneOrigin(slope, xpos, ypos, zpos, xoff, yoff, angle);
height = P_GetSlopeZAt(slope, xpos, ypos); height = R_GetSlopeZAt(slope, xpos, ypos);
zeroheight = FixedToFloat(height - zpos); zeroheight = height - FixedToDouble(zpos);
ang = ANG2RAD(ANGLE_180 - (angle + plangle)); 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); slope_u.z = -cos(ang);
plangle >>= ANGLETOFINESHIFT; plangle >>= ANGLETOFINESHIFT;
z_at_xy = P_GetSlopeZAt(slope, xpos + FINESINE(plangle), ypos + FINECOSINE(plangle)); z_at_xy = R_GetSlopeZAt(slope, xpos + FINESINE(plangle), ypos + FINECOSINE(plangle));
slope_v.y = FixedToFloat(z_at_xy - height); slope_v.y = z_at_xy - height;
z_at_xy = P_GetSlopeZAt(slope, xpos + FINECOSINE(plangle), ypos - FINESINE(plangle)); z_at_xy = R_GetSlopeZAt(slope, xpos + FINECOSINE(plangle), ypos - FINESINE(plangle));
slope_u.y = FixedToFloat(z_at_xy - height); slope_u.y = z_at_xy - height;
DoSlopeCrossProducts(); DoSlopeCrossProducts();
DoSlopeLightCrossProduct(); 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. // 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) 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; float ang;
R_SetSlopePlaneOrigin(slope, xpos, ypos, zpos, xoff, yoff, angle); R_SetSlopePlaneOrigin(slope, xpos, ypos, zpos, xoff, yoff, angle);
height = P_GetSlopeZAt(slope, xpos, ypos); height = R_GetSlopeZAt(slope, xpos, ypos);
zeroheight = FixedToFloat(height - zpos); zeroheight = height - FixedToDouble(zpos);
ang = ANG2RAD(ANGLE_180 - (angle + plangle)); 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); slope_u.z = -xscale * cos(ang);
ang = ANG2RAD(plangle); ang = ANG2RAD(plangle);
z_at_xy = P_GetSlopeZAt(slope, xpos + FloatToFixed(yscale * sin(ang)), ypos + FloatToFixed(yscale * cos(ang))); z_at_xy = R_GetSlopeZAt(slope, xpos + FloatToFixed(yscale * sin(ang)), ypos + FloatToFixed(yscale * cos(ang)));
slope_v.y = FixedToFloat(z_at_xy - height); slope_v.y = z_at_xy - height;
z_at_xy = P_GetSlopeZAt(slope, xpos + FloatToFixed(xscale * cos(ang)), ypos - FloatToFixed(xscale * sin(ang))); z_at_xy = R_GetSlopeZAt(slope, xpos + FloatToFixed(xscale * cos(ang)), ypos - FloatToFixed(xscale * sin(ang)));
slope_u.y = FixedToFloat(z_at_xy - height); slope_u.y = z_at_xy - height;
DoSlopeCrossProducts(); DoSlopeCrossProducts();
DoSlopeLightCrossProduct(); 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.x = cos(ang);
slope_lightv.z = sin(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); slope_lightu.z = -cos(ang);
plangle >>= ANGLETOFINESHIFT; plangle >>= ANGLETOFINESHIFT;
z_at_xy = P_GetSlopeZAt(slope, xpos + FINESINE(plangle), ypos + FINECOSINE(plangle)); z_at_xy = R_GetSlopeZAt(slope, xpos + FINESINE(plangle), ypos + FINECOSINE(plangle));
slope_lightv.y = FixedToFloat(z_at_xy - height); slope_lightv.y = z_at_xy - height;
z_at_xy = P_GetSlopeZAt(slope, xpos + FINECOSINE(plangle), ypos - FINESINE(plangle)); z_at_xy = R_GetSlopeZAt(slope, xpos + FINECOSINE(plangle), ypos - FINESINE(plangle));
slope_lightu.y = FixedToFloat(z_at_xy - height); 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) static void DoSlopeCrossProducts(void)
{ {
float sfmult = 65536.f; DVector3_Cross(&slope_origin, &slope_v, &ds_su);
DVector3_Cross(&slope_origin, &slope_u, &ds_sv);
CROSS(ds_su, slope_origin, slope_v); DVector3_Cross(&slope_v, &slope_u, &ds_sz);
CROSS(ds_sv, slope_origin, slope_u);
CROSS(ds_sz, slope_v, slope_u);
ds_su.z *= focallengthf; ds_su.z *= focallengthf;
ds_sv.z *= focallengthf; ds_sv.z *= focallengthf;
@ -810,6 +803,8 @@ static void DoSlopeCrossProducts(void)
return; return;
// Premultiply the texture vectors with the scale factors // Premultiply the texture vectors with the scale factors
float sfmult = 65536.f;
if (ds_powersoftwo) if (ds_powersoftwo)
sfmult *= 1 << nflatshiftup; sfmult *= 1 << nflatshiftup;
@ -823,13 +818,11 @@ static void DoSlopeCrossProducts(void)
static void DoSlopeLightCrossProduct(void) static void DoSlopeLightCrossProduct(void)
{ {
CROSS(ds_slopelight, slope_lightv, slope_lightu); DVector3_Cross(&slope_lightv, &slope_lightu, &ds_slopelight);
ds_slopelight.z *= focallengthf; ds_slopelight.z *= focallengthf;
} }
#undef CROSS
static void CalcSlopePlaneVectors(visplane_t *pl, fixed_t xoff, fixed_t yoff) static void CalcSlopePlaneVectors(visplane_t *pl, fixed_t xoff, fixed_t yoff)
{ {
if (!ds_fog && (pl->xscale != FRACUNIT || pl->yscale != FRACUNIT)) if (!ds_fog && (pl->xscale != FRACUNIT || pl->yscale != FRACUNIT))

View file

@ -295,6 +295,7 @@
<ClInclude Include="..\m_tokenizer.h" /> <ClInclude Include="..\m_tokenizer.h" />
<ClInclude Include="..\m_perfstats.h" /> <ClInclude Include="..\m_perfstats.h" />
<ClInclude Include="..\m_queue.h" /> <ClInclude Include="..\m_queue.h" />
<ClInclude Include="..\m_vector.h" />
<ClInclude Include="..\m_random.h" /> <ClInclude Include="..\m_random.h" />
<ClInclude Include="..\m_swap.h" /> <ClInclude Include="..\m_swap.h" />
<ClInclude Include="..\netcode\client_connection.h" /> <ClInclude Include="..\netcode\client_connection.h" />
@ -473,6 +474,7 @@
<ClCompile Include="..\m_tokenizer.c" /> <ClCompile Include="..\m_tokenizer.c" />
<ClCompile Include="..\m_perfstats.c" /> <ClCompile Include="..\m_perfstats.c" />
<ClCompile Include="..\m_queue.c" /> <ClCompile Include="..\m_queue.c" />
<ClCompile Include="..\m_vector.c" />
<ClCompile Include="..\m_random.c" /> <ClCompile Include="..\m_random.c" />
<ClCompile Include="..\netcode\client_connection.c" /> <ClCompile Include="..\netcode\client_connection.c" />
<ClCompile Include="..\netcode\commands.c" /> <ClCompile Include="..\netcode\commands.c" />

View file

@ -348,6 +348,9 @@
<ClInclude Include="..\m_queue.h"> <ClInclude Include="..\m_queue.h">
<Filter>M_Misc</Filter> <Filter>M_Misc</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\m_vector.h">
<Filter>M_Misc</Filter>
</ClInclude>
<ClInclude Include="..\m_random.h"> <ClInclude Include="..\m_random.h">
<Filter>M_Misc</Filter> <Filter>M_Misc</Filter>
</ClInclude> </ClInclude>
@ -846,6 +849,9 @@
<ClCompile Include="..\m_queue.c"> <ClCompile Include="..\m_queue.c">
<Filter>M_Misc</Filter> <Filter>M_Misc</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\m_vector.c">
<Filter>M_Misc</Filter>
</ClCompile>
<ClCompile Include="..\m_random.c"> <ClCompile Include="..\m_random.c">
<Filter>M_Misc</Filter> <Filter>M_Misc</Filter>
</ClCompile> </ClCompile>

View file

@ -3,6 +3,7 @@
// Copyright (C) 1993-1996 by id Software, Inc. // Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team. // Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2023 by Sonic Team Junior. // Copyright (C) 1999-2023 by Sonic Team Junior.
// Copyright (C) 2009 by Stephen McGranahan.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.