/*---------------------------------------------------------------------------* Project: Horizon File: math_Matrix22.h Copyright (C)2009-2010 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. 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. $Revision: 18951 $ *---------------------------------------------------------------------------*/ #ifndef NN_MATH_MATRIX22_H_ #define NN_MATH_MATRIX22_H_ #include #include #pragma push #pragma Otime namespace nn { namespace math { struct MTX22; struct MTX23; /* ------------------------------------------------------------------------ MTX22用の関数 ------------------------------------------------------------------------ */ NN_MATH_INLINE MTX22* MTX22Identity(MTX22* pOut); NN_MATH_INLINE bool MTX22IsIdentity(const MTX22* p); NN_MATH_INLINE MTX22* MTX22Copy(MTX22* pOut, const MTX22* p); NN_MATH_INLINE MTX22* MTX22Zero(MTX22* pOut); NN_MATH_INLINE MTX22* MTX23ToMTX22(MTX22* pOut, const MTX23* pM); NN_MATH_INLINE MTX22* MTX22MAdd(MTX22* pOut, f32 t, const MTX22* p1, const MTX22* p2); /* ======================================================================= クラスの定義 ======================================================================== */ struct MTX22_ { struct BaseData { f32 _00, _01; f32 _10, _11; }; union { #if defined(NN_MATH_USE_ANONYMOUS_STRUCT) struct { f32 _00, _01; f32 _10, _11; }; #endif BaseData f; f32 m[2][2]; f32 a[4]; VEC2_ v[2]; }; }; /*!--------------------------------------------------------------------------* @brief 2行2列の行列クラスです *---------------------------------------------------------------------------*/ struct MTX22 : public MTX22_ { public: static const int ROW_COUNT = 2; //!< 行数です。 static const int COLUMN_COUNT = 2; //!< 列数です。 //! @brief 単位行列です。 static const MTX22& Identity() { static const MTX22 identity( 1.0f, 0.0f, 0.0f, 1.0f); return identity; } typedef MTX22 self_type; //!< 自分の型です typedef f32 value_type; //!< 要素の型です。 public: //---------------------------------------- //! @name 作成 //@{ //! @brief コンストラクタです。 MTX22() {} //! @brief コンストラクタです。 MTX22(const f32* p); //! @brief コンストラクタです。 MTX22(const MTX23& rhs); //! @brief コンストラクタです。 MTX22(f32 x00, f32 x01, f32 x10, f32 x11) { f._00 = x00; f._01 = x01; f._10 = x10; f._11 = x11; } //@} //---------------------------------------- //! @name 変換 //@{ //! @brief f32 型へのキャストです。 operator f32*() { return this->a; } //! @brief f32 型へのキャストです。 operator const f32*() const { return this->a; } //! @brief VEC2 型として行を取得します。 VEC2& GetRow(int index) { NN_MATH_MINMAXLT_ASSERT(index, 0, ROW_COUNT); return *reinterpret_cast(&this->v[index]); } //! @brief VEC2 型として行を取得します。 const VEC2& GetRow(int index) const { NN_MATH_MINMAXLT_ASSERT(index, 0, ROW_COUNT); return *reinterpret_cast(&this->v[index]); } //! @brief VEC2 型として列を取得します。 VEC2 GetColumn(int index) const { NN_MATH_MINMAXLT_ASSERT(index, 0, COLUMN_COUNT); VEC2 column; column.x = this->m[0][index]; column.y = this->m[1][index]; return column; } //! @brief VEC2 型で列を設定します。 void SetColumn(int index, const VEC2& column) { NN_MATH_MINMAXLT_ASSERT(index, 0, COLUMN_COUNT); this->m[0][index] = column.x; this->m[1][index] = column.y; } //@} //---------------------------------------- //! @name 設定 //@{ //! @brief 単位行列に設定します。 self_type& SetupIdentity() { return *MTX22Identity(this); } //@} //---------------------------------------- //! @name 比較 //@{ //! @brief 同値であれば true を返します。 bool operator == (const self_type& rhs) const { return ::std::memcmp(this, &rhs, sizeof(MTX22)) == 0; } //! @brief 同値でなければ true を返します。 bool operator != (const self_type& rhs) const { return ::std::memcmp(this, &rhs, sizeof(MTX22)) != 0; } //! @brief 単位行列であれば true を返します。 bool IsIdentity() const { return MTX22IsIdentity(this); } //@} //! @brief 状態を出力します。 void Report(bool bNewline = true, const char* name = NULL) const; }; typedef struct MTX22 Matrix22; } // namespace math } // namespace nn namespace nn { namespace math { inline MTX22::MTX22(const f32* p) { MTX22Copy(this, reinterpret_cast(p)); } inline MTX22::MTX22(const MTX23& rhs) { MTX23ToMTX22(this, &rhs); } //-- const 引数を参照にしたオーバーロード inline bool MTX22IsIdentity(const MTX22& m) { return MTX22IsIdentity( &m ); } inline MTX22* MTX22Copy(MTX22* pOut, const MTX22& m) { return MTX22Copy(pOut, &m); } inline MTX22* MTX23ToMTX22(MTX22* pOut, const MTX23& m) { return MTX23ToMTX22(pOut, &m); } inline MTX22* MTX22MAdd(MTX22* pOut, f32 t, const MTX22& m1, const MTX22& m2) { return MTX22MAdd(pOut, t, &m1, &m2); } } // namespace math } // namespace nn #if defined(NN_MATH_AS_INLINE) #include #endif #pragma pop #endif