From 9992d36bf356d158a43af3a95b7c817587e5997f Mon Sep 17 00:00:00 2001 From: Nev3r Date: Wed, 2 Jun 2021 10:58:36 +0200 Subject: [PATCH] Add slope equation constant parsing functionality. --- src/p_slopes.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/p_slopes.h | 1 + 2 files changed, 41 insertions(+) diff --git a/src/p_slopes.c b/src/p_slopes.c index f52158a34..885987597 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -131,6 +131,36 @@ void P_ReconfigureViaVertexes (pslope_t *slope, const vector3_t v1, const vector } } +/// 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) +{ + fixed_t m; + vector3_t *normal = &slope->normal; + + // Set origin. + FV3_Load(&slope->o, 0, 0, c ? -FixedDiv(d, c) : 0); + + // Get slope's normal. + FV3_Load(normal, a, b, c); + FV3_Normalize(normal); + + // Invert normal if it's facing down. + if (normal->z < 0) + FV3_Negate(normal); + + // Get direction vector + m = FixedHypot(normal->x, normal->y); + slope->d.x = -FixedDiv(normal->x, m); + slope->d.y = -FixedDiv(normal->y, m); + + // Z delta + slope->zdelta = FixedDiv(m, normal->z); + + // 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)); +} + /// Recalculate dynamic slopes. void T_DynamicSlopeLine (dynplanethink_t* th) { @@ -680,6 +710,16 @@ pslope_t *P_SlopeById(UINT16 id) return ret; } +/// 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* ret = Slope_Add(0); + + ReconfigureViaConstants(ret, a, b, c, d); + + return ret; +} + /// Initializes and reads the slopes from the map data. void P_SpawnSlopes(const boolean fromsave) { size_t i; diff --git a/src/p_slopes.h b/src/p_slopes.h index c87208597..27f2ec27b 100644 --- a/src/p_slopes.h +++ b/src/p_slopes.h @@ -88,6 +88,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); /// Dynamic plane type enum for the thinker. Will have a different functionality depending on this. typedef enum {