1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: math_Matrix22.h
4
5 Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Rev: 46684 $
14 *---------------------------------------------------------------------------*/
15
16 #ifndef NN_MATH_MATH_MATRIX22_H_
17 #define NN_MATH_MATH_MATRIX22_H_
18
19 #include <cstring>
20 #include <nn/math/math_Config.h>
21
22 #pragma push
23 #pragma Otime
24
25 namespace nn {
26 namespace math {
27
28 struct MTX22;
29 struct MTX23;
30
31 /* Please see man pages for details
32
33
34 */
35
36 /* ------------------------------------------------------------------------
37 Function for MTX22
38 ------------------------------------------------------------------------ */
39 /*
40
41
42
43
44
45
46 */
47 NN_MATH_INLINE MTX22* MTX22Copy(MTX22* pOut, const MTX22* p);
48
49 /*
50
51
52
53
54
55 */
56 NN_MATH_INLINE MTX22* MTX22Identity(MTX22* pOut);
57
58 /*
59
60
61
62
63
64 */
65 NN_MATH_INLINE bool MTX22IsIdentity(const MTX22* p);
66
67 /*
68
69
70
71
72
73
74
75
76 */
77 NN_MATH_INLINE MTX22* MTX22MAdd(MTX22* pOut, f32 t, const MTX22* p1, const MTX22* p2);
78
79 /*
80
81
82
83
84
85 */
86 NN_MATH_INLINE MTX22* MTX22Zero(MTX22* pOut);
87
88 /*
89
90 */
91
92 NN_MATH_INLINE MTX22* MTX23ToMTX22(MTX22* pOut, const MTX23* pM);
93
94 /* =======================================================================
95 Class definitions
96 ======================================================================== */
97 /*
98
99
100 */
101 struct MTX22_
102 {
103 //
104 struct BaseData
105 {
106 f32 _00; //
107 f32 _01; //
108 f32 _10; //
109 f32 _11; //
110 };
111
112 union
113 {
114 //----------------------------------------
115 //
116 //
117 #if defined(NN_MATH_USE_ANONYMOUS_STRUCT)
118 //
119 struct
120 {
121 f32 _00, _01;
122 f32 _10, _11;
123 };
124 #endif
125 BaseData f; //
126 f32 m[2][2]; //
127 f32 a[4]; //
128 VEC2_ v[2]; //
129 //
130 };
131 };
132
133 /*
134
135
136 */
137 class MTX22 : public MTX22_
138 {
139 public:
140 static const int ROW_COUNT = 2; //
141 static const int COLUMN_COUNT = 2; //
142
143 //
Identity()144 static const MTX22& Identity()
145 {
146 static const MTX22 identity(
147 1.0f, 0.0f,
148 0.0f, 1.0f);
149
150 return identity;
151 }
152
153 typedef MTX22 self_type; //
154 typedef f32 value_type; //
155 public:
156 //----------------------------------------
157 //
158 //
159
160 //
MTX22()161 MTX22() {}
162 //
163 explicit MTX22(const f32* p);
164 //
165 explicit MTX22(const MTX23& rhs);
166 //
MTX22(f32 x00,f32 x01,f32 x10,f32 x11)167 MTX22(f32 x00, f32 x01,
168 f32 x10, f32 x11)
169 {
170 f._00 = x00; f._01 = x01;
171 f._10 = x10; f._11 = x11;
172 }
173
174 //
175
176 //----------------------------------------
177 //
178 //
179
180 //
181 operator f32*() { return this->a; }
182 //
183 operator const f32*() const { return this->a; }
184
185 //
GetRow(int index)186 VEC2& GetRow(int index)
187 {
188 NN_MATH_MINMAXLT_ASSERT(index, 0, ROW_COUNT);
189 return *reinterpret_cast<VEC2*>(&this->v[index]);
190 }
191
192 //
GetRow(int index)193 const VEC2& GetRow(int index) const
194 {
195 NN_MATH_MINMAXLT_ASSERT(index, 0, ROW_COUNT);
196 return *reinterpret_cast<const VEC2*>(&this->v[index]);
197 }
198
199 //
GetColumn(int index)200 VEC2 GetColumn(int index) const
201 {
202 NN_MATH_MINMAXLT_ASSERT(index, 0, COLUMN_COUNT);
203 VEC2 column;
204 column.x = this->m[0][index];
205 column.y = this->m[1][index];
206 return column;
207 }
208
209 //
SetColumn(int index,const VEC2 & column)210 void SetColumn(int index, const VEC2& column)
211 {
212 NN_MATH_MINMAXLT_ASSERT(index, 0, COLUMN_COUNT);
213 this->m[0][index] = column.x;
214 this->m[1][index] = column.y;
215 }
216 //
217
218 //----------------------------------------
219 //
220 //
221
222 //
SetupIdentity()223 self_type& SetupIdentity() { return *MTX22Identity(this); }
224
225 //
226
227 //----------------------------------------
228 //
229 //
230
231 //
232 bool operator == (const self_type& rhs) const { return ::std::memcmp(this, &rhs, sizeof(MTX22)) == 0; }
233
234 //
235 bool operator != (const self_type& rhs) const { return ::std::memcmp(this, &rhs, sizeof(MTX22)) != 0; }
236
237 //
IsIdentity()238 bool IsIdentity() const { return MTX22IsIdentity(this); }
239
240 //
241
242 //
243 void Report(bool bNewline = true, const char* name = NULL) const;
244
245 private:
246 typedef void (self_type::*UnspecifiedBoolType)() const;
247 operator UnspecifiedBoolType() const;
248 operator UnspecifiedBoolType();
249 };
250
251 //
252 //
253
254 //
255 typedef class MTX22 Matrix22;
256
257 //
258
259 } // namespace math
260 } // namespace nn
261
262 namespace nn {
263 namespace math {
264
265 inline
MTX22(const f32 * p)266 MTX22::MTX22(const f32* p) { MTX22Copy(this, reinterpret_cast<const MTX22*>(p)); }
267
268 inline
MTX22(const MTX23 & rhs)269 MTX22::MTX22(const MTX23& rhs) { MTX23ToMTX22(this, &rhs); }
270
271 //Overload referencing the -- const argument
MTX22IsIdentity(const MTX22 & m)272 inline bool MTX22IsIdentity(const MTX22& m) { return MTX22IsIdentity( &m ); }
MTX22Copy(MTX22 * pOut,const MTX22 & m)273 inline MTX22* MTX22Copy(MTX22* pOut, const MTX22& m) { return MTX22Copy(pOut, &m); }
MTX22MAdd(MTX22 * pOut,f32 t,const MTX22 & m1,const MTX22 & m2)274 inline MTX22* MTX22MAdd(MTX22* pOut, f32 t, const MTX22& m1, const MTX22& m2) { return MTX22MAdd(pOut, t, &m1, &m2); }
275
276 } // namespace math
277 } // namespace nn
278
279 #if defined(NN_MATH_AS_INLINE)
280 #include <nn/math/inline/math_Matrix22.ipp>
281 #endif
282
283 #pragma pop
284
285 #endif
286