mirror of
https://github.com/ZDoom/Raze.git
synced 2025-02-21 02:51:46 +00:00
- Convert calcviewpitch()
to work with a temporary DAngle so we can eliminate the temporary tanhoriz()
friend.
This commit is contained in:
parent
ca8f8d6d36
commit
eedcfb46c6
2 changed files with 10 additions and 19 deletions
|
@ -68,7 +68,6 @@ class fixedhoriz
|
|||
constexpr fixedhoriz(fixed_t v) : value(v) {}
|
||||
|
||||
friend constexpr fixedhoriz buildhoriz(int v);
|
||||
friend constexpr fixedhoriz tanhoriz(double v);
|
||||
friend fixedhoriz pitchhoriz(double v);
|
||||
|
||||
friend FSerializer &Serialize(FSerializer &arc, const char *key, fixedhoriz &obj, fixedhoriz *defval);
|
||||
|
@ -178,7 +177,6 @@ public:
|
|||
};
|
||||
|
||||
inline constexpr fixedhoriz buildhoriz(int v) { return fixedhoriz(IntToFixed(v)); }
|
||||
inline constexpr fixedhoriz tanhoriz(double v) { return fixedhoriz(FloatToFixed<23>(v)); }
|
||||
inline fixedhoriz pitchhoriz(double v) { return fixedhoriz(fixed_t(clamp<double>(IntToFixed(128) * tan(v * (pi::pi() / 180.)), -INT32_MAX, INT32_MAX))); }
|
||||
|
||||
inline FSerializer &Serialize(FSerializer &arc, const char *key, fixedhoriz &obj, fixedhoriz *defval)
|
||||
|
|
|
@ -46,25 +46,11 @@ inline static double getCorrectedScale(const double scaleAdjust)
|
|||
return scaleAdjust < 1. ? scaleAdjust * (1. + 0.21 * (1. - scaleAdjust)) : scaleAdjust;
|
||||
}
|
||||
|
||||
inline static fixedhoriz getscaledhoriz(const double value, const double scaleAdjust, const fixedhoriz object, const double push)
|
||||
{
|
||||
return tanhoriz(getCorrectedScale(scaleAdjust) * ((object.Tan() * getTicrateScale(value)) + push));
|
||||
}
|
||||
|
||||
inline static DAngle getscaledangle(const double value, const double scaleAdjust, const DAngle object, const DAngle push)
|
||||
{
|
||||
return ((object.Normalized180() * getTicrateScale(value)) + push) * getCorrectedScale(scaleAdjust);
|
||||
}
|
||||
|
||||
inline static void scaletozero(fixedhoriz& object, const double value, const double scaleAdjust, const double push = DBL_MAX)
|
||||
{
|
||||
if (auto sgn = object.Sgn())
|
||||
{
|
||||
object -= getscaledhoriz(value, scaleAdjust, object, push == DBL_MAX ? sgn * (1. / 576.) : push);
|
||||
if (sgn != object.Sgn()) object = pitchhoriz(nullAngle.Degrees());
|
||||
}
|
||||
}
|
||||
|
||||
inline static void scaletozero(DAngle& object, const double value, const double scaleAdjust, const DAngle push = -minAngle)
|
||||
{
|
||||
if (auto sgn = object.Sgn())
|
||||
|
@ -391,11 +377,15 @@ Average: 4.375;
|
|||
*/
|
||||
|
||||
static constexpr double HORIZOFFSPEED = (1. / 8.) * 35.;
|
||||
static constexpr double HORIZOFFSPEEDF = 1.95835;
|
||||
|
||||
void PlayerHorizon::calcviewpitch(const DVector2& pos, DAngle const ang, bool const aimmode, bool const canslopetilt, sectortype* const cursectnum, double const scaleAdjust, bool const climbing)
|
||||
{
|
||||
if (cl_slopetilting && cursectnum != nullptr)
|
||||
{
|
||||
// Temporarily hold horizoff as pitch.
|
||||
auto tmpangle = DAngle::fromDeg(horizoff.Degrees());
|
||||
|
||||
if (aimmode && canslopetilt) // If the floor is sloped
|
||||
{
|
||||
// Get a point, 512 (64 for Blood) units ahead of player's position
|
||||
|
@ -417,7 +407,7 @@ void PlayerHorizon::calcviewpitch(const DVector2& pos, DAngle const ang, bool co
|
|||
// accordingly
|
||||
if (cursectnum == tempsect || (!isBlood() && abs(getflorzofslopeptr(tempsect, rotpt) - k) <= 4))
|
||||
{
|
||||
horizoff += maphoriz(scaleAdjust * ((j - k) * (!isBlood() ? 0.625 : 5.5)));
|
||||
tmpangle += DAngle::fromDeg(maphoriz(scaleAdjust * ((j - k) * (!isBlood() ? 0.625 : 5.5))).Degrees());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -425,13 +415,16 @@ void PlayerHorizon::calcviewpitch(const DVector2& pos, DAngle const ang, bool co
|
|||
if (climbing)
|
||||
{
|
||||
// tilt when climbing but you can't even really tell it.
|
||||
if (horizoff.Degrees() < 38) horizoff += getscaledhoriz(HORIZOFFSPEED, scaleAdjust, pitchhoriz(38) - horizoff, 0.0078125);
|
||||
if (tmpangle < DAngle::fromDeg(38)) tmpangle += getscaledangle(HORIZOFFSPEEDF, scaleAdjust, DAngle::fromDeg(38) - tmpangle, DAngle::fromDeg(0.4476));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Make horizoff grow towards 0 since horizoff is not modified when you're not on a slope.
|
||||
scaletozero(horizoff, HORIZOFFSPEED, scaleAdjust, horizoff.Sgn() * (1. / 128.));
|
||||
scaletozero(tmpangle, HORIZOFFSPEEDF, scaleAdjust, DAngle::fromDeg(tmpangle.Sgn() * 0.4476));
|
||||
}
|
||||
|
||||
// Convert temporary angle back to fixedhoriz.
|
||||
horizoff = pitchhoriz(ClampViewPitch(tmpangle.Degrees()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue