1/*---------------------------------------------------------------------------*
2  Project:  Horizon
3  File:     math_Matrix22.ipp
4
5  Copyright (C)2009-2010 Nintendo Co., Ltd.  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: 13623 $
14 *---------------------------------------------------------------------------*/
15namespace nn {
16namespace math {
17
18/* ------------------------------------------------------------------------
19        MTX22
20   ------------------------------------------------------------------------ */
21/*!
22    @name    行列
23    @{
24*/
25
26/*!--------------------------------------------------------------------------*
27  @brief        行列が単位行列かどうか判定します。
28
29  @param[in]    p  判定対象の行列へのポインタ。
30
31  @return       p が単位行列であれば true そうでなければ false を返します。
32 *---------------------------------------------------------------------------*/
33NN_MATH_INLINE bool
34MTX22IsIdentity(const MTX22* p)
35{
36    return p->f._00 == 1.f && p->f._01 == 0.f &&
37           p->f._10 == 0.f && p->f._11 == 1.f;
38}
39
40/*!--------------------------------------------------------------------------*
41  @brief        2x2 行列をコピーします。
42
43  @param[out]   pOut    コピー先の行列のポインタです。
44  @param[in]    p       コピー元の行列のポインタです。
45
46  @return       pOut を返します。
47 *---------------------------------------------------------------------------*/
48NN_MATH_INLINE MTX22*
49MTX22Copy(MTX22* pOut, const MTX22* p)
50{
51    NN_NULL_ASSERT( pOut );
52    NN_NULL_ASSERT( p );
53
54    if (pOut != p)
55    {
56        *pOut = *p;
57    }
58
59    return pOut;
60}
61
62/*!--------------------------------------------------------------------------*
63  @brief        ゼロ行列を作成します。
64
65  @param[out]   pOut    ゼロ行列を格納するバッファへのポインタです。
66
67  @return       pOut を返します。
68 *---------------------------------------------------------------------------*/
69NN_MATH_INLINE MTX22*
70MTX22Zero(MTX22* pOut)
71{
72    NN_NULL_ASSERT( pOut );
73
74    pOut->f._00 = pOut->f._01 =
75    pOut->f._10 = pOut->f._11 = 0.f;
76    return pOut;
77}
78
79/*!--------------------------------------------------------------------------*
80  @brief        2x2 の単位行列を作成します。
81
82  @param[out]   pOut    単位行列を格納するバッファへのポインタです。
83
84  @return       pOut を返します。
85 *---------------------------------------------------------------------------*/
86NN_MATH_INLINE MTX22*
87MTX22Identity(MTX22* pOut)
88{
89    NN_NULL_ASSERT( pOut );
90
91    MTX22Copy(pOut, MTX22::Identity());
92
93    return pOut;
94}
95
96/*!--------------------------------------------------------------------------*
97  @brief        行列を実数倍して、別の行列を足します。
98
99  @param[out]   pOut    計算結果を受け取るバッファへのポインタ。p1, p2 と同じ行列を指しても構いません。
100  @param[in]    t       かける数です。
101  @param[in]    p1      元の行列へのポインタです。
102  @param[in]    p2      足す行列へのポインタです。
103
104  @return       pOut を返します。
105 *---------------------------------------------------------------------------*/
106NN_MATH_INLINE MTX22*
107MTX22MAdd(MTX22* pOut, f32 t, const MTX22* p1, const MTX22* p2)
108{
109    NN_NULL_ASSERT( pOut );
110    NN_NULL_ASSERT( p1 );
111    NN_NULL_ASSERT( p2 );
112
113    pOut->f._00 = t * p1->f._00 + p2->f._00;
114    pOut->f._01 = t * p1->f._01 + p2->f._01;
115
116    pOut->f._10 = t * p1->f._10 + p2->f._10;
117    pOut->f._11 = t * p1->f._11 + p2->f._11;
118
119    return pOut;
120}
121
122/*!
123    @}
124*/
125
126}  // namespace math
127}  // namespace nn
128