diff --git a/source/common/utility/cmdlib.h b/source/common/utility/cmdlib.h index 392d0f46d..eb76450eb 100644 --- a/source/common/utility/cmdlib.h +++ b/source/common/utility/cmdlib.h @@ -90,6 +90,18 @@ inline constexpr double Scale(double a, double b, double c) return (a * b) / c; } +template +inline constexpr int Sgn(const T& val) +{ + return (val > 0) - (val < 0); +} + +template +inline constexpr T lerp(const T min, const T max, const T input) +{ + return (T(1) - input) * min + input * max; +} + class FileReader; struct MD5Context; @@ -105,9 +117,6 @@ inline void fillshort(void* buff, size_t count, uint16_t clear) } } -template inline constexpr int Sgn(const T& val) { return (val > 0) - (val < 0); } - - inline int sizeToBits(int w) { int j = 15; diff --git a/source/common/utility/vectors.h b/source/common/utility/vectors.h index 019eb9db1..538a1d8e4 100644 --- a/source/common/utility/vectors.h +++ b/source/common/utility/vectors.h @@ -1364,7 +1364,7 @@ public: return Degrees_ / other; } - constexpr double operator/ (TAngle other) const + constexpr TAngle operator/ (TAngle other) const { return Degrees_ / other.Degrees_; } diff --git a/source/games/blood/src/view.cpp b/source/games/blood/src/view.cpp index 412d5a6ac..8e9ab69ea 100644 --- a/source/games/blood/src/view.cpp +++ b/source/games/blood/src/view.cpp @@ -526,7 +526,7 @@ static void SetupView(PLAYER* pPlayer, DVector3& cPos, DAngle& cA, DAngle& cH, s { cPos.Z += bobHeight; } - cPos.Z -= clamp(cH.Tan(), -1.171875, 1.171875) * 5.; + cPos.Z -= lerp(-10., 10., ((cH.Normalized180() + DAngle90) / DAngle180).Degrees()); } else { diff --git a/source/games/duke/src/hudweapon_d.cpp b/source/games/duke/src/hudweapon_d.cpp index c709847a3..9801cd5e4 100644 --- a/source/games/duke/src/hudweapon_d.cpp +++ b/source/games/duke/src/hudweapon_d.cpp @@ -231,7 +231,8 @@ void displayweapon_d(int snum, double interpfrac) } plravel = getavel(snum) * (1. / 16.); - horiz16th = clamp((!SyncInput() ? p->horizon.sum() : p->horizon.interpolatedsum(interpfrac)).Tan(), -2., 2.) * 8.; + auto horiz = !SyncInput() ? p->horizon.sum() : p->horizon.interpolatedsum(interpfrac); + horiz16th = lerp(-16., 16., ((horiz.Normalized180() + DAngle90) / DAngle180).Degrees()); look_anghalf = p->angle.look_anghalf(interpfrac); looking_arc = p->angle.looking_arc(interpfrac); hard_landing *= 8.; diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 2f8f85c47..b4ea750c7 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -180,7 +180,7 @@ static void shootflamethrowerflame(DDukeActor* actor, int p, DVector3 spos, DAng // WTF??? DAngle myang = DAngle90 - (DAngle180 - abs(abs((spos.XY() - ps[p].pos.XY()).Angle() - sang) - DAngle180)); if (ps[p].GetActor()->vel.X != 0) - vel = ((myang / DAngle90) * ps[p].GetActor()->vel.X) + 25; + vel = ((myang / DAngle90).Degrees() * ps[p].GetActor()->vel.X) + 25; if (actor->sector()->lotag == 2 && (krand() % 5) == 0) spawned = spawn(actor, WATERBUBBLE); }