diff --git a/src/r_draw.c b/src/r_draw.c index f25ecfa04..766e0428e 100644 --- a/src/r_draw.c +++ b/src/r_draw.c @@ -105,7 +105,7 @@ UINT8 *ds_transmap; // one of the translucency tables #ifdef ESLOPE pslope_t *ds_slope; // Current slope being used -FVector ds_su, ds_sv, ds_sz; // Vectors for... stuff? +floatv3_t ds_su, ds_sv, ds_sz; // Vectors for... stuff? float focallengthf, zeroheight; #endif diff --git a/src/r_draw.h b/src/r_draw.h index b29791cc4..e1818545b 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -61,11 +61,12 @@ extern UINT8 *ds_source; // start of a 64*64 tile image extern UINT8 *ds_transmap; #ifdef ESLOPE -///TODO: either convert ds_su, etc to FPU or declare a floating-point vector type somewhere -#include "hardware/hw_defs.h" +typedef struct { + float x, y, z; +} floatv3_t; pslope_t *ds_slope; // Current slope being used -FVector ds_su, ds_sv, ds_sz; // Vectors for... stuff? +floatv3_t ds_su, ds_sv, ds_sz; // Vectors for... stuff? float focallengthf, zeroheight; #endif diff --git a/src/r_plane.c b/src/r_plane.c index 839f2fa38..1c4abc8c5 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -941,41 +941,60 @@ void R_DrawSinglePlane(visplane_t *pl) if (pl->slope) { // Potentially override other stuff for now cus we're mean. :< But draw a slope plane! // I copied ZDoom's code and adapted it to SRB2... -Red - FVector p, m, n; - angle_t ang; + floatv3_t p, m, n; + float ang; //double zeroheight; + float fudge; - double vx = FIXED_TO_FLOAT(viewx); - double vy = FIXED_TO_FLOAT(viewy); - double vz = FIXED_TO_FLOAT(viewz); + float vx = FIXED_TO_FLOAT(viewx); + float vy = FIXED_TO_FLOAT(viewy); + float vz = FIXED_TO_FLOAT(viewz); zeroheight = FIXED_TO_FLOAT(P_GetZAt(pl->slope, viewx, viewy)); +#define ANG2RAD(angle) ((float)((angle)*M_PI)/ANGLE_180) + // p is the texture origin in view space // Don't add in the offsets at this stage, because doing so can result in // errors if the flat is rotated. - ang = (ANGLE_270 - viewangle)>>ANGLETOFINESHIFT; - p.x = vx * FIXED_TO_FLOAT(FINECOSINE(ang)) - vy * FIXED_TO_FLOAT(FINESINE(ang)); - p.z = vx * FIXED_TO_FLOAT(FINESINE(ang)) + vy * FIXED_TO_FLOAT(FINECOSINE(ang)); + ang = ANG2RAD(ANGLE_270 - viewangle); + p.x = vx * cos(ang) - vy * sin(ang); + p.z = vx * sin(ang) + vy * cos(ang); p.y = FIXED_TO_FLOAT(P_GetZAt(pl->slope, 0, 0)) - vz; // m is the v direction vector in view space - ang = (ANGLE_180 - viewangle - pl->plangle) >> ANGLETOFINESHIFT; - m.x = FIXED_TO_FLOAT(FINECOSINE(ang)); - m.z = FIXED_TO_FLOAT(FINESINE(ang)); + ang = ANG2RAD(ANGLE_180 - viewangle - pl->plangle); + m.x = cos(ang); + m.z = sin(ang); // n is the u direction vector in view space - n.x = FIXED_TO_FLOAT(FINESINE(ang)); - n.z = -FIXED_TO_FLOAT(FINECOSINE(ang)); + n.x = sin(ang); + n.z = -cos(ang); - ang = pl->plangle>>ANGLETOFINESHIFT; - m.y = FIXED_TO_FLOAT(P_GetZAt(pl->slope, viewx + FINESINE(ang), viewy + FINECOSINE(ang))) - zeroheight; - n.y = FIXED_TO_FLOAT(P_GetZAt(pl->slope, viewx + FINECOSINE(ang), viewy - FINESINE(ang))) - zeroheight; + ang = ANG2RAD(pl->plangle); + m.y = FIXED_TO_FLOAT(P_GetZAt(pl->slope, viewx + FLOAT_TO_FIXED(sin(ang)), viewy + FLOAT_TO_FIXED(cos(ang)))) - zeroheight; + n.y = FIXED_TO_FLOAT(P_GetZAt(pl->slope, viewx + FLOAT_TO_FIXED(cos(ang)), viewy - FLOAT_TO_FIXED(sin(ang)))) - zeroheight; - ///TODO: slope FPU conversion stuff - //M_CrossProduct3f(&ds_su, &p, &m); - //M_CrossProduct3f(&ds_sv, &p, &n); - //M_CrossProduct3f(&ds_sz, &m, &n); + // Okay, look, don't ask me why this works, but without this setup there's a disgusting-looking misalignment with the textures. -Red + fudge = ((1<