mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-22 04:21:23 +00:00
Recalculate slope vectors at render time
This commit is contained in:
parent
b15fca4d66
commit
c7c13e3372
6 changed files with 31 additions and 18 deletions
|
@ -3221,6 +3221,8 @@ static thinker_t* LoadMobjThinker(actionf_p1 thinker)
|
||||||
slope->normal.x = READFIXED(save_p);
|
slope->normal.x = READFIXED(save_p);
|
||||||
slope->normal.y = READFIXED(save_p);
|
slope->normal.y = READFIXED(save_p);
|
||||||
slope->normal.z = READFIXED(save_p);
|
slope->normal.z = READFIXED(save_p);
|
||||||
|
|
||||||
|
slope->moved = true;
|
||||||
}
|
}
|
||||||
if (diff2 & MD2_DRAWONLYFORPLAYER)
|
if (diff2 & MD2_DRAWONLYFORPLAYER)
|
||||||
mobj->drawonlyforplayer = &players[READUINT8(save_p)];
|
mobj->drawonlyforplayer = &players[READUINT8(save_p)];
|
||||||
|
|
|
@ -29,13 +29,14 @@ pslope_t *slopelist = NULL;
|
||||||
UINT16 slopecount = 0;
|
UINT16 slopecount = 0;
|
||||||
|
|
||||||
// Calculate line normal
|
// Calculate line normal
|
||||||
void P_CalculateSlopeNormal(pslope_t *slope) {
|
void P_CalculateSlopeNormal(pslope_t *slope)
|
||||||
|
{
|
||||||
slope->normal.z = FINECOSINE(slope->zangle>>ANGLETOFINESHIFT);
|
slope->normal.z = FINECOSINE(slope->zangle>>ANGLETOFINESHIFT);
|
||||||
slope->normal.x = FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), slope->d.x);
|
slope->normal.x = FixedMul(FINESINE(slope->zangle>>ANGLETOFINESHIFT), slope->d.x);
|
||||||
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)
|
static void CalculateNormalDir(pslope_t *slope, dvector3_t *dnormal)
|
||||||
{
|
{
|
||||||
double hyp = hypot(dnormal->x, dnormal->y);
|
double hyp = hypot(dnormal->x, dnormal->y);
|
||||||
|
|
||||||
|
@ -52,17 +53,14 @@ static void CalculateVectors(pslope_t *slope, dvector3_t *dnormal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void P_RecalculateSlopeVectors(pslope_t *slope)
|
void P_CalculateSlopeVectors(pslope_t *slope)
|
||||||
{
|
{
|
||||||
dvector3_t dnormal;
|
dvector3_t dnormal;
|
||||||
|
|
||||||
dnormal.x = FixedToDouble(slope->normal.x);
|
DVector3_Load(&dnormal, FixedToDouble(slope->normal.x), FixedToDouble(slope->normal.y), FixedToDouble(slope->normal.z));
|
||||||
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));
|
DVector3_Load(&slope->dorigin, FixedToDouble(slope->o.x), FixedToDouble(slope->o.y), FixedToDouble(slope->o.z));
|
||||||
|
|
||||||
CalculateVectors(slope, &dnormal);
|
CalculateNormalDir(slope, &dnormal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Setup slope via 3 vertexes.
|
/// Setup slope via 3 vertexes.
|
||||||
|
@ -121,7 +119,7 @@ static void ReconfigureViaVertexes (pslope_t *slope, const vector3_t v1, const v
|
||||||
slope->zangle = InvAngle(R_PointToAngle2(0, 0, FRACUNIT, slope->zdelta));
|
slope->zangle = InvAngle(R_PointToAngle2(0, 0, FRACUNIT, slope->zdelta));
|
||||||
}
|
}
|
||||||
|
|
||||||
P_RecalculateSlopeVectors(slope);
|
P_CalculateSlopeVectors(slope);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Setup slope via constants.
|
/// Setup slope via constants.
|
||||||
|
@ -173,7 +171,7 @@ static void ReconfigureViaConstants (pslope_t *slope, const double pa, const dou
|
||||||
|
|
||||||
DVector3_Load(&slope->dorigin, 0, 0, d_o);
|
DVector3_Load(&slope->dorigin, 0, 0, d_o);
|
||||||
|
|
||||||
CalculateVectors(slope, &dnormal);
|
CalculateNormalDir(slope, &dnormal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recalculate dynamic slopes.
|
/// Recalculate dynamic slopes.
|
||||||
|
@ -212,8 +210,8 @@ void T_DynamicSlopeLine (dynlineplanethink_t* th)
|
||||||
if (slope->zdelta != FixedDiv(zdelta, th->extent)) {
|
if (slope->zdelta != FixedDiv(zdelta, th->extent)) {
|
||||||
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);
|
||||||
|
slope->moved = true;
|
||||||
P_CalculateSlopeNormal(slope);
|
P_CalculateSlopeNormal(slope);
|
||||||
P_RecalculateSlopeVectors(slope);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,7 +442,7 @@ static void line_SpawnViaLine(const int linenum, const boolean spawnthinker)
|
||||||
fslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y);
|
fslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y);
|
||||||
|
|
||||||
P_CalculateSlopeNormal(fslope);
|
P_CalculateSlopeNormal(fslope);
|
||||||
P_RecalculateSlopeVectors(fslope);
|
P_CalculateSlopeVectors(fslope);
|
||||||
|
|
||||||
if (spawnthinker && (flags & SL_DYNAMIC))
|
if (spawnthinker && (flags & SL_DYNAMIC))
|
||||||
P_AddDynLineSlopeThinker(fslope, DP_FRONTFLOOR, line, extent);
|
P_AddDynLineSlopeThinker(fslope, DP_FRONTFLOOR, line, extent);
|
||||||
|
@ -462,7 +460,7 @@ static void line_SpawnViaLine(const int linenum, const boolean spawnthinker)
|
||||||
cslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y);
|
cslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y);
|
||||||
|
|
||||||
P_CalculateSlopeNormal(cslope);
|
P_CalculateSlopeNormal(cslope);
|
||||||
P_RecalculateSlopeVectors(cslope);
|
P_CalculateSlopeVectors(cslope);
|
||||||
|
|
||||||
if (spawnthinker && (flags & SL_DYNAMIC))
|
if (spawnthinker && (flags & SL_DYNAMIC))
|
||||||
P_AddDynLineSlopeThinker(cslope, DP_FRONTCEIL, line, extent);
|
P_AddDynLineSlopeThinker(cslope, DP_FRONTCEIL, line, extent);
|
||||||
|
@ -503,7 +501,7 @@ static void line_SpawnViaLine(const int linenum, const boolean spawnthinker)
|
||||||
fslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y);
|
fslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y);
|
||||||
|
|
||||||
P_CalculateSlopeNormal(fslope);
|
P_CalculateSlopeNormal(fslope);
|
||||||
P_RecalculateSlopeVectors(fslope);
|
P_CalculateSlopeVectors(fslope);
|
||||||
|
|
||||||
if (spawnthinker && (flags & SL_DYNAMIC))
|
if (spawnthinker && (flags & SL_DYNAMIC))
|
||||||
P_AddDynLineSlopeThinker(fslope, DP_BACKFLOOR, line, extent);
|
P_AddDynLineSlopeThinker(fslope, DP_BACKFLOOR, line, extent);
|
||||||
|
@ -521,7 +519,7 @@ static void line_SpawnViaLine(const int linenum, const boolean spawnthinker)
|
||||||
cslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y);
|
cslope->xydirection = R_PointToAngle2(origin.x, origin.y, point.x, point.y);
|
||||||
|
|
||||||
P_CalculateSlopeNormal(cslope);
|
P_CalculateSlopeNormal(cslope);
|
||||||
P_RecalculateSlopeVectors(cslope);
|
P_CalculateSlopeVectors(cslope);
|
||||||
|
|
||||||
if (spawnthinker && (flags & SL_DYNAMIC))
|
if (spawnthinker && (flags & SL_DYNAMIC))
|
||||||
P_AddDynLineSlopeThinker(cslope, DP_BACKCEIL, line, extent);
|
P_AddDynLineSlopeThinker(cslope, DP_BACKCEIL, line, extent);
|
||||||
|
|
|
@ -51,7 +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_CalculateSlopeVectors(pslope_t *slope);
|
||||||
void P_InitSlopes(void);
|
void P_InitSlopes(void);
|
||||||
void P_SpawnSlopes(const boolean fromsave);
|
void P_SpawnSlopes(const boolean fromsave);
|
||||||
|
|
||||||
|
|
|
@ -349,6 +349,8 @@ typedef struct pslope_s
|
||||||
|
|
||||||
double dzdelta;
|
double dzdelta;
|
||||||
|
|
||||||
|
boolean moved : 1;
|
||||||
|
|
||||||
UINT8 flags; // Slope options
|
UINT8 flags; // Slope options
|
||||||
} pslope_t;
|
} pslope_t;
|
||||||
|
|
||||||
|
|
|
@ -631,7 +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);
|
interp->dynslope.slope->moved = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -699,6 +699,12 @@ void R_SetSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos,
|
||||||
double height, z_at_xy;
|
double height, z_at_xy;
|
||||||
float ang;
|
float ang;
|
||||||
|
|
||||||
|
if (slope->moved)
|
||||||
|
{
|
||||||
|
P_CalculateSlopeVectors(slope);
|
||||||
|
slope->moved = false;
|
||||||
|
}
|
||||||
|
|
||||||
R_SetSlopePlaneOrigin(slope, xpos, ypos, zpos, xoff, yoff, angle);
|
R_SetSlopePlaneOrigin(slope, xpos, ypos, zpos, xoff, yoff, angle);
|
||||||
height = R_GetSlopeZAt(slope, xpos, ypos);
|
height = R_GetSlopeZAt(slope, xpos, ypos);
|
||||||
zeroheight = height - FixedToDouble(zpos);
|
zeroheight = height - FixedToDouble(zpos);
|
||||||
|
@ -735,9 +741,14 @@ void R_SetSlopePlane(pslope_t *slope, fixed_t xpos, fixed_t ypos, fixed_t zpos,
|
||||||
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)
|
||||||
{
|
{
|
||||||
double height, z_at_xy;
|
double height, z_at_xy;
|
||||||
|
|
||||||
float ang;
|
float ang;
|
||||||
|
|
||||||
|
if (slope->moved)
|
||||||
|
{
|
||||||
|
P_CalculateSlopeVectors(slope);
|
||||||
|
slope->moved = false;
|
||||||
|
}
|
||||||
|
|
||||||
R_SetSlopePlaneOrigin(slope, xpos, ypos, zpos, xoff, yoff, angle);
|
R_SetSlopePlaneOrigin(slope, xpos, ypos, zpos, xoff, yoff, angle);
|
||||||
height = R_GetSlopeZAt(slope, xpos, ypos);
|
height = R_GetSlopeZAt(slope, xpos, ypos);
|
||||||
zeroheight = height - FixedToDouble(zpos);
|
zeroheight = height - FixedToDouble(zpos);
|
||||||
|
|
Loading…
Reference in a new issue