OSDN Git Service

create mat fix
[moflib/moflib.git] / src / mof / math / matrix3.hpp
1 #pragma once
2 #include <mof/math/basic_matrix.hpp>
3
4 namespace mof
5 {
6 namespace math
7 {
8         class vector3;
9
10         /**
11          * @brief 3次元アフィン同次座標変換行列クラス
12          */
13         class matrix3 : public basic_matrix<3, matrix3, vector3>
14         {
15         public:
16 //{{{ constructor
17                 /**
18                  * @brief デフォルトコンストラクタ.最後の要素以外を0で初期化する.
19                  */
20                 matrix3()
21                 {
22                         for (size_t i = 0; i <= last_index() - 1; ++i) {
23                                 components_[i] = 0;
24                         }
25                         components_[last_index()] = 1;
26                 }
27
28                 /**
29                  * @brief 指定した値で初期化する.
30                  * @tparam     T   配列型(operator[]をオーバーロードしていること)
31                  * @param[in]  arr 初期化用配列
32                  */
33                 template <class T>
34                 explicit matrix3(const T& arr)
35                 {
36                         for (size_t i = 0; i <= last_index() - 1; ++i) {
37                                 components_[i] = arr[i];
38                         }
39                         components_[last_index()] = 1;
40                 }
41
42                 /**
43                  * @brief 指定した値で初期化する.
44                  */
45                 matrix3
46                 (
47                         float m11, float m12, float m13, float m14,
48                         float m21, float m22, float m23, float m24,
49                         float m31, float m32, float m33, float m34,
50                         float m41, float m42, float m43
51                 )
52                 {
53                         const float* table[] =
54                                 {
55                                         &m11, &m12, &m13, &m14,
56                                         &m21, &m22, &m23, &m24,
57                                         &m31, &m32, &m33, &m34,
58                                         &m41, &m42, &m43
59                                 };
60                         for (size_t i = 0; i <= last_index() - 1; ++i) {
61                                 components_[i] = *table[i];
62                         }
63                         components_[last_index()] = 1;
64                 }
65
66 //}}}
67 //{{{ copy constructor
68         matrix3(const matrix3& rhs)
69         {
70                 for (size_t i = 0; i < last_index(); ++i) {
71                         components_[i] = rhs.components_[i];
72                 }
73         }
74 //}}}
75 //{{{ operator =
76         /**
77          * @note コピーのパフォーマンスのためにこの関数の定義は重要
78          */
79         matrix3& operator = (const matrix3& rhs)
80         {
81                 for (size_t i = 0; i < last_index(); ++i) {
82                         components_[i] = rhs.components_[i];
83                 }
84                 return *this;
85         }
86 //}}}
87         };
88
89 }// namespace math
90 }// namespace mof