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