1/*---------------------------------------------------------------------------*
2  Project:  NintendoWare
3  File:     math_Matrix44.ipp
4
5  Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc.  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: 28766 $
14 *---------------------------------------------------------------------------*/
15
16#include <cmath>
17#include <nw/math/math_Vector3.h>
18
19namespace nw {
20namespace math {
21using namespace nn::math;
22
23/*!---------------------------------------------------------------------------*
24  @brief        Maya 用のテクスチャ座標変換行列を作成します。
25
26  @details 以下のような変換行列を作成します。
27
28  [S] [T] [t(0.5,0.5)] [R] [t(-0.5,-0.5)]
29
30  [S] = \n
31  | scaleS      0 0 0 |\n
32  |      0 scaleT 0 0 |\n
33  |      0      0 1 0 |\n
34  |      0      0 0 1 |\n
35  \n
36  [T] = t( -translateS , -translateT )\n
37  \n
38  [R] =\n
39  | rotateCos -rotateSin 0 0 |\n
40  | rotateSin  rotateCos 0 0 |\n
41  |         0          0 1 0 |\n
42  |         0          0 0 1 |
43
44  @param[out]   pOut  計算結果を受け取るバッファへのポインタ。
45  @param[in]    scaleS S 軸のスケール値です。
46  @param[in]    scaleT T 軸のスケール値です。
47  @param[in]    rotate 回転値です。
48  @param[in]    translateS S 軸の移動値です。
49  @param[in]    translateT T 軸の移動値です。
50
51  @return       pOut を返します。
52 *---------------------------------------------------------------------------*/
53NW_MATH_INLINE MTX44*
54MTX44TextureMatrixForMaya(MTX44* pOut,
55    float scaleS, float scaleT,
56    float rotate,
57    float translateS, float translateT)
58{
59    NW_NULL_ASSERT(pOut);
60
61    float rotateSin;
62    float rotateCos;
63    SinCosFIdx(&rotateSin, &rotateCos, NN_MATH_RAD_TO_FIDX(rotate));
64
65    pOut->m[0][0] =  scaleS * rotateCos;
66    pOut->m[0][1] = -scaleS * rotateSin;
67    pOut->m[0][3] =  scaleS * ( 0.5f * rotateSin - 0.5f * rotateCos + 0.5f - translateS);
68
69    pOut->m[1][0] = scaleT * rotateSin;
70    pOut->m[1][1] = scaleT * rotateCos;
71    pOut->m[1][3] = scaleT * (-0.5f * rotateSin - 0.5f * rotateCos + 0.5f - translateT);
72
73    pOut->m[0][2] = pOut->m[1][2] =
74    pOut->m[2][0] = pOut->m[2][1] = pOut->m[2][3] =
75    pOut->m[3][0] = pOut->m[3][1] = pOut->m[3][2] = 0.0f;
76    pOut->m[2][2] = pOut->m[3][3] = 1.0f;
77
78    return pOut;
79}
80
81/*!---------------------------------------------------------------------------*
82  @brief        Softimage 用のテクスチャ座標変換行列を作成します。
83
84  @details 以下のような変換行列を作成します。
85
86  [S] [R] [T]
87
88  [S] = \n
89  | scaleS      0 0 0 |\n
90  |      0 scaleT 0 0 |\n
91  |      0      0 1 0 |\n
92  |      0      0 0 1 |\n
93  \n
94  [R] = \n
95  |  rotateCos rotateSin 0 0 |\n
96  | -rotateSin rotateCos 0 0 |\n
97  |          0         0 1 0 |\n
98  |          0         0 0 1 |\n
99  \n
100  [T] = t( -translateS , -translateT) \n
101  \n
102  [R] の回転方向は Maya および Max とは逆方向が正になっています。
103
104
105  @param[out]   pOut  計算結果を受け取るバッファへのポインタ。
106  @param[in]    scaleS S 軸のスケール値です。
107  @param[in]    scaleT T 軸のスケール値です。
108  @param[in]    rotate 回転値です。
109  @param[in]    translateS S 軸の移動値です。
110  @param[in]    translateT T 軸の移動値です。
111
112  @return       pOut を返します。
113 *---------------------------------------------------------------------------*/
114NW_MATH_INLINE MTX44*
115MTX44TextureMatrixForSoftimage(MTX44* pOut,
116    float scaleS, float scaleT,
117    float rotate,
118    float translateS, float translateT)
119{
120    NW_NULL_ASSERT(pOut);
121
122    float rotateSin;
123    float rotateCos;
124    SinCosFIdx(&rotateSin, &rotateCos, NN_MATH_RAD_TO_FIDX(rotate));
125
126    pOut->m[0][0] = scaleS * rotateCos;
127    pOut->m[0][1] = scaleS * rotateSin;
128    pOut->m[0][3] = scaleS * (-rotateCos * translateS - rotateSin * translateT);
129
130    pOut->m[1][0] = -scaleT * rotateSin;
131    pOut->m[1][1] =  scaleT * rotateCos;
132    pOut->m[1][3] =  scaleT * ( rotateSin * translateS - rotateCos * translateT);
133
134    pOut->m[0][2] = pOut->m[1][2] =
135    pOut->m[2][0] = pOut->m[2][1] = pOut->m[2][3] =
136    pOut->m[3][0] = pOut->m[3][1] = pOut->m[3][2] = 0.0f;
137    pOut->m[2][2] = pOut->m[3][3] = 1.0f;
138
139    return pOut;
140}
141
142/*!---------------------------------------------------------------------------*
143  @brief        3ds Max 用のテクスチャ座標変換行列を作成します。
144
145  @details 以下のような変換行列を作成します。
146
147  [t(0.5,0.5)] [S] [R] [t(-0.5,-0.5)] [T]
148
149  [S] = \n
150  | scaleS      0 0 0 |\n
151  |      0 scaleT 0 0 |\n
152  |      0      0 1 0 |\n
153  |      0      0 0 1 |\n
154  \n
155  [R] = \n
156  | rotateCos -rotateSin 0 0 |\n
157  | rotateSin  rotateCos 0 0 |\n
158  |         0          0 1 0 |\n
159  |         0          0 0 1 |\n
160  \n
161  [T] = t( -translateS , translateT )
162
163  @param[out]   pOut  計算結果を受け取るバッファへのポインタ。
164  @param[in]    scaleS S 軸のスケール値です。
165  @param[in]    scaleT T 軸のスケール値です。
166  @param[in]    rotate 回転値です。
167  @param[in]    translateS S 軸の移動値です。
168  @param[in]    translateT T 軸の移動値です。
169
170  @return       pOut を返します。
171 *---------------------------------------------------------------------------*/
172NW_MATH_INLINE MTX44*
173MTX44TextureMatrixForMax(MTX44* pOut,
174    float scaleS, float scaleT,
175    float rotate,
176    float translateS, float translateT)
177{
178    NW_NULL_ASSERT(pOut);
179
180    float rotateSin;
181    float rotateCos;
182    SinCosFIdx(&rotateSin, &rotateCos, NN_MATH_RAD_TO_FIDX(rotate));
183
184    float scaleSSin = scaleS * rotateSin;
185    float scaleSCos = scaleS * rotateCos;
186    float scaleTSin = scaleT * rotateSin;
187    float scaleTCos = scaleT * rotateCos;
188    float ts = -translateS - 0.5f;
189    float tt =  translateT - 0.5f;
190
191    pOut->m[0][0] =  scaleSCos;
192    pOut->m[0][1] = -scaleSSin;
193    pOut->m[0][3] =  (scaleSCos * ts) - (scaleSSin * tt) + 0.5f;
194
195    pOut->m[1][0] =  scaleTSin;
196    pOut->m[1][1] =  scaleTCos;
197    pOut->m[1][3] =  (scaleTSin * ts) + (scaleTCos * tt) + 0.5f;
198
199    pOut->m[0][2] = pOut->m[1][2] =
200    pOut->m[2][0] = pOut->m[2][1] = pOut->m[2][3] =
201    pOut->m[3][0] = pOut->m[3][1] = pOut->m[3][2] = 0.0f;
202    pOut->m[2][2] = pOut->m[3][3] = 1.0f;
203
204    return pOut;
205}
206
207
208}  // namespace math
209}  // namespace nw
210