Skip to content

Commit

Permalink
- added Q16 and Build angle converters to TAngle
Browse files Browse the repository at this point in the history
To have full coverage. Q16 is what ACS uses and Build angles are needed in Raze.
  • Loading branch information
coelckers committed Aug 26, 2022
1 parent bbf6a24 commit 87ba51c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/common/utility/vectors.h
Expand Up @@ -1208,6 +1208,16 @@ struct TAngle
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;

Expand Down Expand Up @@ -1320,6 +1330,16 @@ struct TAngle
return Degrees_;
}

constexpr int Buildang() const
{
return int(Degrees_ * (512 / 90.0));
}

constexpr int Q16() const
{
return int(Degrees_ * (16384 / 90.0));
}

TVector2<vec_t> ToVector(vec_t length = 1) const
{
return TVector2<vec_t>(length * Cos(), length * Sin());
Expand Down
6 changes: 3 additions & 3 deletions src/playsim/p_acs.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 87ba51c

Please sign in to comment.