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