Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
c_angle.h
Go to the documentation of this file.
1#ifndef C_ANGLE_H
2#define C_ANGLE_H
3
5#include "angle_utils.h"
6
7
8#define DEG2S_CONSTANT (0x8000 / 180.0f)
9#define S2DEG_CONSTANT (180.0f / 0x8000)
10#define S2RAD_CONSTANT (M_PI / 0x8000)
11#define RAD2S_CONSTANT (0x8000 / M_PI)
12
13#define DEG2S(x) ((s16)((x) * DEG2S_CONSTANT))
14#define S2DEG(x) ((x) * S2DEG_CONSTANT)
15#define S2RAD(x) ((x) * S2RAD_CONSTANT)
16#define RAD2S(x) ((x) * RAD2S_CONSTANT)
17
18class cSAngle {
19private:
21
22public:
23 const static cSAngle _0;
24 const static cSAngle _1;
25 const static cSAngle _90;
26 const static cSAngle _180;
27 const static cSAngle _270;
28#ifdef __MWERKS__
31 cSAngle(const cSAngle&);
32#else
33 cSAngle() = default;
34 ~cSAngle() = default;
35 cSAngle(const cSAngle&) = default;
36#endif
37 cSAngle(s16);
38 cSAngle(float);
39 s16 Val() const { return this->mAngle; }
40 // void Set(s16 angle) { this->mAngle = angle; }
41 void Val(const cSAngle&);
42 void Val(s16);
43 void Val(float);
44 float Degree(void) const;
45 float Radian(void) const;
46 float Norm(void) const;
47 s16 Abs(void) const;
48 s16 Inv(void) const;
49 float Sin(void) const;
50 float Cos(void) const;
51 cSAngle operator-(void) const;
52 cSAngle operator+(const cSAngle&) const;
53 cSAngle operator-(const cSAngle&) const;
54 void operator+=(const cSAngle&);
55 void operator-=(const cSAngle&);
56 cSAngle operator+(short) const;
57 cSAngle operator-(short) const;
58 void operator+=(short);
59 cSAngle operator*(float) const;
60 void operator*=(float);
61 bool operator<(const cSAngle& other) const { return mAngle < other.mAngle; }
62 bool operator>(const cSAngle& other) const { return mAngle > other.mAngle; }
63 bool operator<=(const cSAngle& other) const { return mAngle <= other.mAngle; }
64 bool operator>=(const cSAngle& other) const { return mAngle >= other.mAngle; }
65 bool operator==(const cSAngle& other) const { return mAngle == other.mAngle; }
66 operator s16(void) const { return mAngle; }
67 static inline cSAngle getMaxNegative(void) { return cSAngle((s16)-0x8000); }
68 inline void mirrorAtMaxNeg(void) { *this = cSAngle((s16)-0x8000) - *this; }
69};
70
71cSAngle operator+(short, const cSAngle&);
72cSAngle operator-(short, const cSAngle&);
73
74struct cAngle {
75 static f32 Radian_to_Degree(f32 rad) { return rad * (180.0f / M_PI); }
76 static f32 Degree_to_Radian(f32 deg) { return deg * (M_PI / 180.0f); }
77 static s16 Degree_to_SAngle(f32 deg) { return DEG2S(deg); }
78 static f32 SAngle_to_Degree(s16 angle) { return S2DEG(angle); }
79 static f32 SAngle_to_Radian(s16 angle) { return angle * (M_PI / 0x8000); }
80 static f32 SAngle_to_Normal(s16 angle) { return angle * (1.0f / 0x8000); }
81 static s16 Radian_to_SAngle(f32 rad) { return rad * (0x8000 / M_PI); }
82
83 /* Converts Radian value into Degree value */
84 static f32 r2d(f32 r) { return Radian_to_Degree(r); }
85
86 /* Converts Degree value into Radian value */
87 static f32 d2r(f32 d) { return Degree_to_Radian(d); }
88
89 /* Converts Degree value to s16 angle */
90 static s16 d2s(f32 d) { return Degree_to_SAngle(d); }
91
92 /* Converts s16 angle to Degree value */
93 static f32 s2d(s16 a) { return SAngle_to_Degree(a); }
94
95 template <typename T>
96 static T Adjust(T f1, T f2, T f3);
97};
98
99template <typename T>
100T cAngle::Adjust(T f1, T f2, T f3) {
101 while (f1 >= f3) {
102 f1 -= f3 - f2;
103 }
104 while (f1 < f2) {
105 f1 += f3 - f2;
106 }
107 return f1;
108}
109
110class cDegree {
111private:
112 float mDegree;
113
114public:
115 cDegree(float);
117
118 cDegree& Formal(void);
119 void Val(float);
120 float Radian(void) const;
121 float Sin(void) const;
122 float Cos(void) const;
123 float Tan(void) const;
124
125 operator f32() const { return mDegree; }
126
127 cDegree operator*(float v) const {
128 return cDegree(mDegree * v);
129 }
130};
131
132class cSPolar {
133private:
134 float mRadial;
137
138public:
140 cSPolar(const cXyz&);
141 cSPolar& Formal(void);
142 void Val(float, short, short);
143 void Val(const cXyz&);
144 cXyz Xyz(void) const;
145 void Globe(class cSGlobe*) const;
146
147 void R(f32 i_radial) { mRadial = i_radial; }
148 void U(cSAngle const& i_angle) { mAngle2 = i_angle.Val(); }
149 void V(cSAngle const& i_angle) { mAngle1 = i_angle.Val(); }
150};
151
152class cSGlobe {
153public:
154 float mRadius;
155 cSAngle mInclination; // original: V
156 cSAngle mAzimuth; // original: U
157
158#ifdef __MWERKS__
161 cSGlobe(const cSGlobe&);
162#else
163 cSGlobe() = default;
164 ~cSGlobe() = default;
165 cSGlobe(const cSGlobe&) = default;
166#endif
167
168 void R(f32 i_radius) { mRadius = i_radius; }
169 void U(cSAngle const& i_azimuth) { mAzimuth = i_azimuth.Val(); }
170 void V(cSAngle const& i_inclination) { mInclination = i_inclination.Val(); }
171
172 cSGlobe(float, short, short);
173 cSGlobe(float, const cSAngle&, const cSAngle&);
174 cSGlobe(const cXyz&);
175 cSGlobe& Formal(void);
176 void Val(const cSGlobe&);
177 void Val(float, short, short);
178 void Val(float, const cSAngle&, const cSAngle&);
179 void Val(const cXyz&);
180 float R(void) const { return mRadius; }
181 const cSAngle& V(void) const { return mInclination; }
182 const cSAngle& U(void) const { return mAzimuth; }
183 cXyz Xyz(void) const;
184 void Polar(cSPolar*) const;
185 cXyz Norm(void) const;
186 cSGlobe& Invert(void);
187};
188
189#endif /* C_ANGLE_H */
cSAngle operator-(short, const cSAngle &)
cSAngle operator+(short, const cSAngle &)
Definition c_angle.h:110
float Radian(void) const
Definition c_angle.cpp:132
cDegree(float)
Definition c_angle.cpp:118
cDegree operator*(float v) const
Definition c_angle.h:127
float Tan(void) const
Definition c_angle.cpp:144
float Cos(void) const
Definition c_angle.cpp:140
void Val(float)
Definition c_angle.cpp:127
float Sin(void) const
Definition c_angle.cpp:136
cDegree & Formal(void)
Definition c_angle.cpp:122
~cDegree()
Definition c_angle.h:116
float mDegree
Definition c_angle.h:112
Definition c_angle.h:18
float Norm(void) const
Definition c_angle.cpp:50
bool operator>(const cSAngle &other) const
Definition c_angle.h:62
cSAngle operator+(short) const
float Sin(void) const
Definition c_angle.cpp:62
void mirrorAtMaxNeg(void)
Definition c_angle.h:68
cSAngle operator-(void) const
Definition c_angle.cpp:70
s16 mAngle
Definition c_angle.h:20
bool operator<(const cSAngle &other) const
Definition c_angle.h:61
cSAngle(const cSAngle &)=default
cSAngle operator*(float) const
Definition c_angle.cpp:102
s16 Inv(void) const
Definition c_angle.cpp:58
float Degree(void) const
Definition c_angle.cpp:42
static const cSAngle _180
Definition c_angle.h:26
static const cSAngle _0
Definition c_angle.h:23
static const cSAngle _1
Definition c_angle.h:24
bool operator<=(const cSAngle &other) const
Definition c_angle.h:63
s16 Val() const
Definition c_angle.h:39
cSAngle operator-(short) const
~cSAngle()
Definition c_angle.h:30
float Cos(void) const
Definition c_angle.cpp:66
void operator-=(const cSAngle &)
Definition c_angle.cpp:86
void operator*=(float)
Definition c_angle.cpp:106
cSAngle()
Definition c_angle.h:29
cSAngle operator+(const cSAngle &) const
Definition c_angle.cpp:74
static cSAngle getMaxNegative(void)
Definition c_angle.h:67
void operator+=(short)
cSAngle()=default
static const cSAngle _270
Definition c_angle.h:27
static const cSAngle _90
Definition c_angle.h:25
float Radian(void) const
Definition c_angle.cpp:46
bool operator==(const cSAngle &other) const
Definition c_angle.h:65
bool operator>=(const cSAngle &other) const
Definition c_angle.h:64
~cSAngle()=default
void operator+=(const cSAngle &)
Definition c_angle.cpp:82
s16 Abs(void) const
Definition c_angle.cpp:54
Definition c_angle.h:152
const cSAngle & U(void) const
Definition c_angle.h:182
float R(void) const
Definition c_angle.h:180
cSGlobe(const cSGlobe &)=default
cSAngle mInclination
Definition c_angle.h:155
cSGlobe & Formal(void)
Definition c_angle.cpp:225
cSGlobe(float, short, short)
cXyz Xyz(void) const
Definition c_angle.cpp:267
void R(f32 i_radius)
Definition c_angle.h:168
~cSGlobe()
Definition c_angle.h:160
~cSGlobe()=default
void Polar(cSPolar *) const
Definition c_angle.cpp:273
cSAngle mAzimuth
Definition c_angle.h:156
const cSAngle & V(void) const
Definition c_angle.h:181
float mRadius
Definition c_angle.h:154
cXyz Norm(void) const
Definition c_angle.cpp:277
void V(cSAngle const &i_inclination)
Definition c_angle.h:170
cSGlobe()=default
cSGlobe()
Definition c_angle.h:159
cSGlobe & Invert(void)
Definition c_angle.cpp:282
void Val(float, short, short)
void U(cSAngle const &i_azimuth)
Definition c_angle.h:169
void Val(const cSGlobe &)
Definition c_angle.cpp:240
Definition c_angle.h:132
void R(f32 i_radial)
Definition c_angle.h:147
void U(cSAngle const &i_angle)
Definition c_angle.h:148
cSPolar & Formal(void)
Definition c_angle.cpp:152
cSAngle mAngle2
Definition c_angle.h:136
cSPolar()
Definition c_angle.h:139
cXyz Xyz(void) const
Definition c_angle.cpp:193
void V(cSAngle const &i_angle)
Definition c_angle.h:149
cSAngle mAngle1
Definition c_angle.h:135
void Val(float, short, short)
void Globe(class cSGlobe *) const
Definition c_angle.cpp:203
float mRadial
Definition c_angle.h:134
r
Definition e_acos.c:105
double v
Definition e_pow.c:114
signed short int s16
Definition types.h:9
float f32
Definition types.h:25
a
Definition k_cos.c:89
Definition c_angle.h:74
static s16 Radian_to_SAngle(f32 rad)
Definition c_angle.h:81
static s16 Degree_to_SAngle(f32 deg)
Definition c_angle.h:77
static f32 Radian_to_Degree(f32 rad)
Definition c_angle.h:75
static f32 SAngle_to_Degree(s16 angle)
Definition c_angle.h:78
static f32 r2d(f32 r)
Definition c_angle.h:84
static f32 d2r(f32 d)
Definition c_angle.h:87
static T Adjust(T f1, T f2, T f3)
Definition c_angle.h:100
static f32 SAngle_to_Normal(s16 angle)
Definition c_angle.h:80
static s16 d2s(f32 d)
Definition c_angle.h:90
static f32 SAngle_to_Radian(s16 angle)
Definition c_angle.h:79
static f32 s2d(s16 a)
Definition c_angle.h:93
static f32 Degree_to_Radian(f32 deg)
Definition c_angle.h:76
Definition c_xyz.h:7