/*---------------------------------------------------------------------------* Project: NintendoWare File: math_Matrix44.ipp Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #include #include namespace nw { namespace math { using namespace nn::math; /*!---------------------------------------------------------------------------* @brief Maya 用のテクスチャ座標変換行列を作成します。 @details 以下のような変換行列を作成します。 [S] [T] [t(0.5,0.5)] [R] [t(-0.5,-0.5)] [S] = \n | scaleS 0 0 0 |\n | 0 scaleT 0 0 |\n | 0 0 1 0 |\n | 0 0 0 1 |\n \n [T] = t( -translateS , -translateT )\n \n [R] =\n | rotateCos -rotateSin 0 0 |\n | rotateSin rotateCos 0 0 |\n | 0 0 1 0 |\n | 0 0 0 1 | @param[out] pOut 計算結果を受け取るバッファへのポインタ。 @param[in] scaleS S 軸のスケール値です。 @param[in] scaleT T 軸のスケール値です。 @param[in] rotate 回転値です。 @param[in] translateS S 軸の移動値です。 @param[in] translateT T 軸の移動値です。 @return pOut を返します。 *---------------------------------------------------------------------------*/ NW_MATH_INLINE MTX44* MTX44TextureMatrixForMaya(MTX44* pOut, float scaleS, float scaleT, float rotate, float translateS, float translateT) { NW_NULL_ASSERT(pOut); float rotateSin; float rotateCos; SinCosFIdx(&rotateSin, &rotateCos, NN_MATH_RAD_TO_FIDX(rotate)); pOut->m[0][0] = scaleS * rotateCos; pOut->m[0][1] = -scaleS * rotateSin; pOut->m[0][3] = scaleS * ( 0.5f * rotateSin - 0.5f * rotateCos + 0.5f - translateS); pOut->m[1][0] = scaleT * rotateSin; pOut->m[1][1] = scaleT * rotateCos; pOut->m[1][3] = scaleT * (-0.5f * rotateSin - 0.5f * rotateCos + 0.5f - translateT); pOut->m[0][2] = pOut->m[1][2] = pOut->m[2][0] = pOut->m[2][1] = pOut->m[2][3] = pOut->m[3][0] = pOut->m[3][1] = pOut->m[3][2] = 0.0f; pOut->m[2][2] = pOut->m[3][3] = 1.0f; return pOut; } /*!---------------------------------------------------------------------------* @brief Softimage 用のテクスチャ座標変換行列を作成します。 @details 以下のような変換行列を作成します。 [S] [R] [T] [S] = \n | scaleS 0 0 0 |\n | 0 scaleT 0 0 |\n | 0 0 1 0 |\n | 0 0 0 1 |\n \n [R] = \n | rotateCos rotateSin 0 0 |\n | -rotateSin rotateCos 0 0 |\n | 0 0 1 0 |\n | 0 0 0 1 |\n \n [T] = t( -translateS , -translateT) \n \n [R] の回転方向は Maya および Max とは逆方向が正になっています。 @param[out] pOut 計算結果を受け取るバッファへのポインタ。 @param[in] scaleS S 軸のスケール値です。 @param[in] scaleT T 軸のスケール値です。 @param[in] rotate 回転値です。 @param[in] translateS S 軸の移動値です。 @param[in] translateT T 軸の移動値です。 @return pOut を返します。 *---------------------------------------------------------------------------*/ NW_MATH_INLINE MTX44* MTX44TextureMatrixForSoftimage(MTX44* pOut, float scaleS, float scaleT, float rotate, float translateS, float translateT) { NW_NULL_ASSERT(pOut); float rotateSin; float rotateCos; SinCosFIdx(&rotateSin, &rotateCos, NN_MATH_RAD_TO_FIDX(rotate)); pOut->m[0][0] = scaleS * rotateCos; pOut->m[0][1] = scaleS * rotateSin; pOut->m[0][3] = scaleS * (-rotateCos * translateS - rotateSin * translateT); pOut->m[1][0] = -scaleT * rotateSin; pOut->m[1][1] = scaleT * rotateCos; pOut->m[1][3] = scaleT * ( rotateSin * translateS - rotateCos * translateT); pOut->m[0][2] = pOut->m[1][2] = pOut->m[2][0] = pOut->m[2][1] = pOut->m[2][3] = pOut->m[3][0] = pOut->m[3][1] = pOut->m[3][2] = 0.0f; pOut->m[2][2] = pOut->m[3][3] = 1.0f; return pOut; } /*!---------------------------------------------------------------------------* @brief 3ds Max 用のテクスチャ座標変換行列を作成します。 @details 以下のような変換行列を作成します。 [t(0.5,0.5)] [S] [R] [t(-0.5,-0.5)] [T] [S] = \n | scaleS 0 0 0 |\n | 0 scaleT 0 0 |\n | 0 0 1 0 |\n | 0 0 0 1 |\n \n [R] = \n | rotateCos -rotateSin 0 0 |\n | rotateSin rotateCos 0 0 |\n | 0 0 1 0 |\n | 0 0 0 1 |\n \n [T] = t( -translateS , translateT ) @param[out] pOut 計算結果を受け取るバッファへのポインタ。 @param[in] scaleS S 軸のスケール値です。 @param[in] scaleT T 軸のスケール値です。 @param[in] rotate 回転値です。 @param[in] translateS S 軸の移動値です。 @param[in] translateT T 軸の移動値です。 @return pOut を返します。 *---------------------------------------------------------------------------*/ NW_MATH_INLINE MTX44* MTX44TextureMatrixForMax(MTX44* pOut, float scaleS, float scaleT, float rotate, float translateS, float translateT) { NW_NULL_ASSERT(pOut); float rotateSin; float rotateCos; SinCosFIdx(&rotateSin, &rotateCos, NN_MATH_RAD_TO_FIDX(rotate)); float scaleSSin = scaleS * rotateSin; float scaleSCos = scaleS * rotateCos; float scaleTSin = scaleT * rotateSin; float scaleTCos = scaleT * rotateCos; float ts = -translateS - 0.5f; float tt = translateT - 0.5f; pOut->m[0][0] = scaleSCos; pOut->m[0][1] = -scaleSSin; pOut->m[0][3] = (scaleSCos * ts) - (scaleSSin * tt) + 0.5f; pOut->m[1][0] = scaleTSin; pOut->m[1][1] = scaleTCos; pOut->m[1][3] = (scaleTSin * ts) + (scaleTCos * tt) + 0.5f; pOut->m[0][2] = pOut->m[1][2] = pOut->m[2][0] = pOut->m[2][1] = pOut->m[2][3] = pOut->m[3][0] = pOut->m[3][1] = pOut->m[3][2] = 0.0f; pOut->m[2][2] = pOut->m[3][3] = 1.0f; return pOut; } } // namespace math } // namespace nw