raylib-cpp
C++ object-oriented wrapper library for raylib.
Loading...
Searching...
No Matches
RadiansDegrees.hpp
1#ifndef RAYLIB_CPP_INCLUDE_RADIANS_DEGREES_HPP_
2#define RAYLIB_CPP_INCLUDE_RADIANS_DEGREES_HPP_
3
4#include "./raylib.hpp"
5#include "./raylib-cpp-utils.hpp"
6#include "./raymath.hpp"
7
8#ifndef RAYLIB_CPP_NO_MATH
9#include <cmath>
10#endif
11
12namespace raylib {
13 class Degree;
14
18 class Radian {
19 float value;
20 public:
21 Radian(const float radian) : value(radian) {}
22 Radian(const Radian& other) : Radian(other.value) {}
23 Radian() : Radian(0) {}
24 Radian(const Degree d);
25
26 Radian& operator=(const Radian& other) = default;
27
28 operator float() const { return value; }
29
30 Radian operator+(const Radian other) const { return value + other.value; }
31 Radian operator-(const Radian other) const { return value - other.value; }
32 Radian operator*(const Radian other) const { return value * other.value; }
33 Radian operator/(const Radian other) const { return value / other.value; }
34
35 Radian& operator+=(const Radian other) { *this = *this + other; return *this; }
36 Radian& operator-=(const Radian other) { *this = *this - other; return *this; }
37 Radian& operator*=(const Radian other) { *this = *this * other; return *this; }
38 Radian& operator/=(const Radian other) { *this = *this / other; return *this; }
39
40 float DegreeValue() const;
41 };
42
46 class Degree {
47 float value;
48 public:
49 Degree(float degree) : value(degree) {}
50 Degree(const Degree& other) : Degree(other.value) {}
51 Degree() : Degree(0) {}
52 Degree(const Radian r) : Degree(float(r) * RAD2DEG) {}
53
54 Degree& operator=(const Degree& other) = default;
55
56 operator float() const { return value; }
57
58 Degree operator+(const Degree other) const { return value + other.value; }
59 Degree operator-(const Degree other) const { return value - other.value; }
60 Degree operator*(const Degree other) const { return value * other.value; }
61 Degree operator/(const Degree other) const { return value / other.value; }
62
63 Degree& operator+=(const Degree other) { *this = *this + other; return *this; }
64 Degree& operator-=(const Degree other) { *this = *this - other; return *this; }
65 Degree& operator*=(const Degree other) { *this = *this * other; return *this; }
66 Degree& operator/=(const Degree other) { *this = *this / other; return *this; }
67
68 float RadianValue() const { return Radian(*this); }
69 };
70
71 inline Radian::Radian(const Degree d) : Radian(float(d) * DEG2RAD) {}
72 inline float Radian::DegreeValue() const { return Degree(*this); }
73}
74
75#endif // RAYLIB_CPP_INCLUDE_RADIANS_DEGREES_HPP_
Degree type (allows automatic worry free conversion between radians and degrees)
Radian type (allows automatic worry free conversion between radians and degrees)