1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: math_Transform.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: 47689 $
14 *---------------------------------------------------------------------------*/
15
16 #ifndef NN_MATH_MATH_TRANSFORM_H_
17 #define NN_MATH_MATH_TRANSFORM_H_
18
19 #include <nn/math/math_Config.h>
20 #include <nn/math/math_Vector2.h>
21 #include <nn/math/math_Vector3.h>
22 #include <nn/math/math_Vector4.h>
23
24 namespace nn { namespace math {
25
26 /* ------------------------------------------------------------------------
27 Transform
28 Class for controlling position via SRT.
29 ------------------------------------------------------------------------ */
30 struct _Transform2
31 {
32 VEC2 scale;
33 VEC2 rotate;
34 VEC2 translate;
35 };
36
37 struct _Transform3
38 {
39 VEC3 scale;
40 VEC3 rotate;
41 VEC3 translate;
42 };
43
44 struct Transform2 : public _Transform2
45 {
46 public:
47 typedef Transform2 self_type;
48 typedef f32 value_type;
49 public:
Transform2Transform250 Transform2() {}
Transform2Transform251 /* implicit */ Transform2(const _Transform2& t)
52 {
53 scale = t.scale;
54 rotate = t.rotate;
55 translate = t.translate;
56 }
Transform2Transform257 Transform2(const VEC2& s, const VEC2& r, const VEC2& t)
58 {
59 scale = s;
60 rotate = r;
61 translate = t;
62 }
63
64 bool operator == (const self_type& rhs) const { return ::std::memcmp(this, &rhs, sizeof(Transform2)) == 0; }
65 bool operator != (const self_type& rhs) const { return ::std::memcmp(this, &rhs, sizeof(Transform2)) != 0; }
66
67
68 void Report(bool bNewline = true, const char* name = NULL) const;
69 };
70
71 struct Transform3 : public _Transform3
72 {
73 public:
74 typedef Transform3 self_type;
75 typedef f32 value_type;
76 public:
Transform3Transform377 Transform3() {}
Transform3Transform378 /* implicit */ Transform3(const _Transform3& t)
79 {
80 scale = t.scale;
81 rotate = t.rotate;
82 translate = t.translate;
83 }
Transform3Transform384 Transform3(const VEC3& s, const VEC3& r, const VEC3& t)
85 {
86 scale = s;
87 rotate = r;
88 translate = t;
89 }
90
91 bool operator == (const self_type& rhs) const { return ::std::memcmp(this, &rhs, sizeof(Transform3)) == 0; }
92 bool operator != (const self_type& rhs) const { return ::std::memcmp(this, &rhs, sizeof(Transform3)) != 0; }
93
94 void Report(bool bNewline = true, const char* name = NULL) const;
95 };
96
97 inline Transform2*
Transform2Identity(Transform2 * pOut)98 Transform2Identity(Transform2* pOut)
99 {
100 NN_NULL_ASSERT(pOut);
101 pOut->scale = VEC2(1.f, 1.f);
102 pOut->rotate = VEC2(0.f, 0.f);
103 pOut->translate = VEC2(0.f, 0.f);
104 return pOut;
105 }
106
107 inline Transform3*
Transform3Identity(Transform3 * pOut)108 Transform3Identity(Transform3* pOut)
109 {
110 NN_NULL_ASSERT(pOut);
111 pOut->scale = VEC3(1.f, 1.f, 1.f);
112 pOut->rotate = VEC3(0.f, 0.f, 0.f);
113 pOut->translate = VEC3(0.f, 0.f, 0.f);
114 return pOut;
115 }
116
117 /* Please see man pages for details
118
119
120 */
121
122 // Transformed as (x, y, z, 1)
123
124 /*
125
126
127
128
129
130
131
132 */
133 NN_MATH_INLINE VEC2* VEC2Transform(VEC2* pOut, const MTX23* pM, const VEC2* pV);
134
135 /*
136
137
138
139
140
141
142
143 */
144 NN_MATH_INLINE VEC3* VEC3Transform(VEC3* pOut, const MTX33* pM, const VEC3* pV);
145
146 /*
147
148
149
150
151
152
153
154
155 */
156 NN_MATH_INLINE VEC3* VEC3Transform(VEC3* pOut, const MTX34* pM, const VEC3* pV);
157
158 /*
159
160
161
162
163
164
165
166 */
167 NN_MATH_INLINE VEC4* VEC3Transform(VEC4* pOut, const MTX44* pM, const VEC3* pV);
168
169 /*
170
171
172
173
174
175
176
177
178 */
179 NN_MATH_INLINE VEC3* VEC3TransformArray(VEC3* pOut, const MTX34* pM, const VEC3* pV, s32 count);
180
181 /*
182
183
184
185
186
187
188
189
190 */
191 NN_MATH_INLINE VEC4* VEC3TransformArray(VEC4* pOut, const MTX44* pM, const VEC3* pV, u32 count);
192
193 /*
194
195
196
197
198
199
200
201 */
202 NN_MATH_INLINE VEC3* VEC3TransformNormal(VEC3* pOut, const MTX34* pM, const VEC3* pV);
203
204 /*
205
206
207
208
209
210
211
212
213 */
214 NN_MATH_INLINE VEC3* VEC3TransformNormalArray(VEC3* pOutArray, const MTX34* pM, const VEC3* pArray, u32 n);
215
216 /*
217
218
219
220
221
222
223
224 */
225 NN_MATH_INLINE VEC3* VEC3TransformCoord(VEC3* pOut, const MTX44* pM, const VEC3* pV);
226
227 /*
228
229
230
231
232
233
234
235
236 */
237 NN_MATH_INLINE VEC3* VEC3TransformCoordArray(VEC3* pOut, const MTX44* pM, const VEC3* pV, u32 count);
238
239 /*
240
241
242
243
244
245
246
247 */
248 NN_MATH_INLINE VEC4* VEC4Transform(VEC4* pOut, const MTX44* pM, const VEC4* pV);
249
250 /*
251
252
253
254
255
256
257
258
259 */
260 NN_MATH_INLINE VEC4* VEC4TransformArray(VEC4* pOut, const MTX44* pM, const VEC4* pV, u32 n);
261
262 /*
263
264 */
265
266 //Overload referencing the -- const argument
VEC2Transform(VEC2 * pOut,const MTX23 & m,const VEC2 & v)267 inline VEC2* VEC2Transform(VEC2* pOut, const MTX23& m, const VEC2& v) { return VEC2Transform( pOut, &m, &v ); }
268
VEC3Transform(VEC3 * pOut,const MTX33 & m,const VEC3 & v)269 inline VEC3* VEC3Transform(VEC3* pOut, const MTX33& m, const VEC3& v) { return VEC3Transform( pOut, &m, &v ); }
VEC3Transform(VEC3 * pOut,const MTX34 & m,const VEC3 & v)270 inline VEC3* VEC3Transform(VEC3* pOut, const MTX34& m, const VEC3& v) { return VEC3Transform( pOut, &m, &v ); }
VEC3Transform(VEC4 * pOut,const MTX44 & m,const VEC3 & v)271 inline VEC4* VEC3Transform(VEC4* pOut, const MTX44& m, const VEC3& v) { return VEC3Transform( pOut, &m, &v ); }
VEC3TransformArray(VEC3 * pOutArray,const MTX34 & m,const VEC3 * pArray,s32 count)272 inline VEC3* VEC3TransformArray(VEC3* pOutArray, const MTX34& m, const VEC3* pArray, s32 count) { return VEC3TransformArray( pOutArray, &m, pArray, count ); }
VEC3TransformArray(VEC4 * pOutArray,const MTX44 & m,const VEC3 * pArray,u32 count)273 inline VEC4* VEC3TransformArray(VEC4* pOutArray, const MTX44& m, const VEC3* pArray, u32 count) { return VEC3TransformArray( pOutArray, &m, pArray, count ); }
274
VEC3TransformNormal(VEC3 * pOut,const MTX34 & m,const VEC3 & v)275 inline VEC3* VEC3TransformNormal(VEC3* pOut, const MTX34& m, const VEC3& v) { return VEC3TransformNormal( pOut, &m, &v ); }
VEC3TransformNormalArray(VEC3 * pOutArray,const MTX34 & m,const VEC3 * pArray,u32 n)276 inline VEC3* VEC3TransformNormalArray(VEC3* pOutArray, const MTX34& m, const VEC3* pArray, u32 n) { return VEC3TransformNormalArray( pOutArray, &m, pArray, n ); }
277
VEC3TransformCoord(VEC3 * pOut,const MTX44 & m,const VEC3 & v)278 inline VEC3* VEC3TransformCoord(VEC3* pOut, const MTX44& m, const VEC3& v) { return VEC3TransformCoord( pOut, &m, &v ); }
VEC3TransformCoordArray(VEC3 * pOutArray,const MTX44 & m,const VEC3 * pArray,u32 count)279 inline VEC3* VEC3TransformCoordArray(VEC3* pOutArray, const MTX44& m, const VEC3* pArray, u32 count) { return VEC3TransformCoordArray( pOutArray, &m, pArray, count ); }
280
VEC4Transform(VEC4 * pOut,const MTX44 & m,const VEC4 & v)281 inline VEC4* VEC4Transform(VEC4* pOut, const MTX44& m, const VEC4& v) { return VEC4Transform( pOut, &m, &v ); }
VEC4TransformArray(VEC4 * pOutArray,const MTX44 & m,const VEC4 * pArray,u32 n)282 inline VEC4* VEC4TransformArray(VEC4* pOutArray, const MTX44& m, const VEC4* pArray, u32 n) { return VEC4TransformArray( pOutArray, &m, pArray, n ); }
283
284
285 }} // nn::math
286
287
288 /* NN_MATH_MATH_TRANSFORM_H_ */
289 #endif
290
291