1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: math_Transform.h
4
5 Copyright (C)2009-2010 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 $Revision: 12449 $
14 *---------------------------------------------------------------------------*/
15
16 #ifndef NN_MATH_TRANSFORM_H_
17 #define NN_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 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 // (x, y, z, 1)として変換
118 NN_MATH_INLINE VEC3* VEC3Transform(VEC3* pOut, const MTX33* pM, const VEC3* pV);
119 NN_MATH_INLINE VEC3* VEC3Transform(VEC3* pOut, const MTX34* pM, const VEC3* pV);
120 NN_MATH_INLINE VEC4* VEC3Transform(VEC4* pOut, const MTX44* pM, const VEC3* pV);
121 NN_MATH_INLINE VEC3* VEC3TransformArray(VEC3* pOut, const MTX34* pM, const VEC3* pV, s32 count);
122 NN_MATH_INLINE VEC4* VEC3TransformArray(VEC4* pOut, const MTX44* pM, const VEC3* pV, u32 count);
123
124 NN_MATH_INLINE VEC3* VEC3TransformNormal(VEC3* pOut, const MTX34* pM, const VEC3* pV);
125 NN_MATH_INLINE VEC3* VEC3TransformNormalArray(VEC3* pOutArray, const MTX34* pM, const VEC3* pArray, u32 n);
126
127 NN_MATH_INLINE VEC3* VEC3TransformCoord(VEC3* pOut, const MTX44* pM, const VEC3* pV);
128 NN_MATH_INLINE VEC3* VEC3TransformCoordArray(VEC3* pOut, const MTX44* pM, const VEC3* pV, u32 count);
129
130 NN_MATH_INLINE VEC4* VEC4Transform(VEC4* pOut, const MTX44* pM, const VEC4* pV);
131 NN_MATH_INLINE VEC4* VEC4TransformArray(VEC4* pOut, const MTX44* pM, const VEC4* pV, u32 n);
132
133
134 //-- const 引数を参照にしたオーバーロード
VEC3Transform(VEC3 * pOut,const MTX33 & m,const VEC3 & v)135 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)136 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)137 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)138 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)139 inline VEC4* VEC3TransformArray(VEC4* pOutArray, const MTX44& m, const VEC3* pArray, u32 count) { return VEC3TransformArray( pOutArray, &m, pArray, count ); }
140
VEC3TransformNormal(VEC3 * pOut,const MTX34 & m,const VEC3 & v)141 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)142 inline VEC3* VEC3TransformNormalArray(VEC3* pOutArray, const MTX34& m, const VEC3* pArray, u32 n) { return VEC3TransformNormalArray( pOutArray, &m, pArray, n ); }
143
VEC3TransformCoord(VEC3 * pOut,const MTX44 & m,const VEC3 & v)144 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)145 inline VEC3* VEC3TransformCoordArray(VEC3* pOutArray, const MTX44& m, const VEC3* pArray, u32 count) { return VEC3TransformCoordArray( pOutArray, &m, pArray, count ); }
146
VEC4Transform(VEC4 * pOut,const MTX44 & m,const VEC4 & v)147 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)148 inline VEC4* VEC4TransformArray(VEC4* pOutArray, const MTX44& m, const VEC4* pArray, u32 n) { return VEC4TransformArray( pOutArray, &m, pArray, n ); }
149
150
151 }} // nn::math
152
153
154 /* NN_MATH_TRANSFORM_H_ */
155 #endif
156
157