From ed5287ef2346b1be0a84bbe81002b27aeb3c6d30 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 26 Aug 2022 18:02:39 +0200 Subject: [PATCH] - added Q16 and Build angle converters to TAngle To have full coverage. Q16 is what ACS uses and Build angles are needed in Raze. --- src/common/utility/vectors.h | 20 ++++++++++++++++++++ src/playsim/p_acs.cpp | 6 +++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/common/utility/vectors.h b/src/common/utility/vectors.h index dce0f301e..e55307811 100644 --- a/src/common/utility/vectors.h +++ b/src/common/utility/vectors.h @@ -1208,6 +1208,16 @@ public: return TAngle(f * (90. / 0x40000000)); } + static constexpr TAngle fromBuild(int bang) + { + return TAngle(bang * (90. / 512)); + } + + static constexpr TAngle fromQ16(int bang) + { + return TAngle(bang * (90. / 16384)); + } + TAngle(const TAngle &other) = default; TAngle &operator= (const TAngle &other) = default; @@ -1320,6 +1330,16 @@ public: return Degrees_; } + constexpr int Buildang() const + { + return int(Degrees_ * (512 / 90.0)); + } + + constexpr int Q16() const + { + return int(Degrees_ * (16384 / 90.0)); + } + TVector2 ToVector(vec_t length = 1) const { return TVector2(length * Cos(), length * Sin()); diff --git a/src/playsim/p_acs.cpp b/src/playsim/p_acs.cpp index 67e5be4d8..c50e0d2a7 100644 --- a/src/playsim/p_acs.cpp +++ b/src/playsim/p_acs.cpp @@ -615,17 +615,17 @@ inline int DoubleToACS(double val) inline DAngle ACSToAngle(int acsval) { - return DAngle::fromDeg(acsval * (360. / 65536.)); + return DAngle::fromQ16(acsval); } inline int AngleToACS(DAngle ang) { - return ang.BAMs() >> 16; + return ang.Q16(); } inline int PitchToACS(DAngle ang) { - return int(ang.Normalized180().Degrees() * (65536. / 360)); + return ang.Normalized180().Q16(); } struct CallReturn