2024-09-24 10:29:21 +02:00

92 lines
2.5 KiB
C++

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0.If a copy of the MPL was not distributed with this
// file, You can obtain one at https ://mozilla.org/MPL/2.0/.
#ifndef ANGLE_H
#define ANGLE_H
namespace Passer {
namespace LinearAlgebra {
static float pi = 3.1415927410125732421875F;
static float Rad2Deg = 360.0f / (pi * 2);
static float Deg2Rad = (pi * 2) / 360.0f;
template <typename T>
class AngleOf {
public:
AngleOf<T>();
static AngleOf<T> Degrees(float f);
static AngleOf<T> Radians(float f);
// float ToFloat() const;
float InDegrees() const;
float InRadians() const;
inline T GetBinary() const { return this->value; }
// static AngleOf<T> pi;
bool operator==(const AngleOf<T> a) const;
bool operator>(AngleOf<T> a);
bool operator>=(AngleOf<T> a);
bool operator<(AngleOf<T> a);
bool operator<=(AngleOf<T> a);
AngleOf<T> operator-() const;
AngleOf<T> operator-(const AngleOf<T>& a) const;
AngleOf<T> operator+(const AngleOf<T>& a) const;
AngleOf<T> operator+=(const AngleOf<T>& a);
friend AngleOf<T> operator*(const AngleOf<T>& a, float f) {
return AngleOf::Degrees((float)a.InDegrees() * f);
}
friend AngleOf<T> operator*(float f, const AngleOf<T>& a) {
return AngleOf::Degrees((float)f * a.InDegrees());
}
static AngleOf<T> Normalize(AngleOf<T> a);
static AngleOf<T> Clamp(AngleOf<T> a, AngleOf<T> min, AngleOf<T> max);
// static AngleOf<T> Difference(AngleOf<T> a, AngleOf<T> b) {
// AngleOf<T> r = Normalize(b.InDegrees() - a.InDegrees());
// return r;
// };
static AngleOf<T> MoveTowards(AngleOf<T> fromAngle,
AngleOf<T> toAngle,
AngleOf<T> maxAngle);
static float Cos(AngleOf<T> a);
static float Sin(AngleOf<T> a);
static float Tan(AngleOf<T> a);
static AngleOf<T> Acos(float f);
static AngleOf<T> Asin(float f);
static AngleOf<T> Atan(float f);
static AngleOf<T> CosineRuleSide(float a, float b, float gamma);
static AngleOf<T> CosineRuleAngle(float a, float b, float c);
static AngleOf<T> SineRuleAngle(float a, AngleOf<T> beta, float c);
private:
T value;
AngleOf<T>(T value);
// These are deprecated, will move to private.
// Use Degrees/Radians instead
// AngleOf(signed int f);
// AngleOf(float f);
};
using Angle = AngleOf<float>;
using AngleSingle = AngleOf<float>;
using Angle16 = AngleOf<signed short>;
using Angle8 = AngleOf<signed char>;
} // namespace LinearAlgebra
} // namespace Passer
using namespace Passer::LinearAlgebra;
#endif