sculpto
matr3.h
Go to the documentation of this file.
1/*!****************************************************************//*!*
2 * \file matr4.h
3 * \brief Math 3x3 matrix implementation module.
4 *
5 * \author Sabitov Kirill
6 * \date 19 June 2022
7 *********************************************************************/
8
9#pragma once
10
11#include "angle_measure.h"
12
13namespace scl::math
14{
16 template<class T> class matr4;
17
19 template<class T>
21 {
22 public:
24 T A[3][3];
25
28 A { {1, 0, 0},
29 {0, 1, 0},
30 {0, 0, 1} } {}
31
32 /*!*
33 * Matrix data constructor by 9 values.
34 *
35 * \param A00-A22 - matrx valeus.
36 */
37 matr3_data(T A00, T A01, T A02,
38 T A10, T A11, T A12,
39 T A20, T A21, T A22) :
40 A { {A00, A01, A02},
41 {A10, A11, A12},
42 {A20, A21, A22} } {}
43
44 /*!*
45 * Matrix data constructor by 1 value.
46 *
47 * \param A00 - calue to set to all matrix cells.
48 */
49 matr3_data(T A00) :
50 A { {A00, A00, A00 },
51 {A00, A00, A00 },
52 {A00, A00, A00 } } {}
53
54 /*!*
55 * Getting pointer to first component of natrix operator.
56 * Need to pass vector to shader.
57 *
58 * \return pointer to first component of matrix.
59 */
60 operator T *()
61 {
62 return A[0];
63 }
64 };
65
67 template <typename T>
68 class matr3: public matr3_data<T>
69 {
70 public:
71 /*!*
72 * Default matrix constructor.
73 * Set identity matrix.
74 *
75 * \param None.
76 */
77 matr3() : matr4_data<T>() {}
78
79 /*!*
80 * Matrix constructor bt 16 values.
81 *
82 * \param A00-A33 - matrx valeus.
83 */
84 matr3(T A00, T A01, T A02,
85 T A10, T A11, T A12,
86 T A20, T A21, T A22) :
87 matr3_data<T>(A00, A01, A02,
88 A10, A11, A12,
89 A20, A21, A22) {}
90
91 /*!*
92 * Matrix contructor by array of values.
93 *
94 * \param A - array of values to set in matrix
95 */
96 matr3(T A[3][3]) { memcpy(this->A, A, 3 * 3 * sizeof(T)); }
97
98 /*!*
99 * Matrix constructor by 1 value.
100 *
101 * \param A00 - calue to set to all matrix cells.
102 */
103 matr3(T A00) : matr3_data<T>(A00) {}
104
105 matr3(const matr4<T> Matr4x4) :
106 matr3_data<T>(Matr4x4.A[0][0], Matr4x4.A[0][1], Matr4x4.A[0][2],
107 Matr4x4.A[1][0], Matr4x4.A[1][1], Matr4x4.A[1][2],
108 Matr4x4.A[2][0], Matr4x4.A[2][1], Matr4x4.A[2][2]) {}
109
110 /*!*
111 * Calculate determinant of 3x3 Matrix.
112 *
113 * \param A11-A33 - matrix components.
114 * \return matrix determinant.
115 */
117 {
118 return (this->A[0][0] * this->A[1][1] * this->A[2][2] -
119 this->A[0][0] * this->A[1][2] * this->A[2][1] -
120 this->A[0][1] * this->A[1][0] * this->A[2][2] +
121 this->A[0][1] * this->A[1][2] * this->A[2][0] +
122 this->A[0][2] * this->A[1][0] * this->A[2][1] -
123 this->A[0][2] * this->A[1][1] * this->A[2][0]);
124 }
125
126 /*!*
127 * Calculate determinant of 3x3 Matrix.
128 *
129 * \param A11-A33 - matrix components.
130 * \return matrix determinant.
131 */
132 static T Det(T A11, T A12, T A13,
133 T A21, T A22, T A23,
134 T A31, T A32, T A33)
135 {
136 return (A11 * A22 * A33 - A11 * A23 * A32 - A12 * A21 * A33 +
137 A12 * A23 * A31 + A13 * A21 * A32 - A13 * A22 * A31);
138 }
139
140 /*!*
141 * Getting matrix cell value operator overloading.
142 *
143 * \param Index - cell index.
144 * \return vector cartesian coordinate.
145 */
146 T &operator [](int Index)
147 {
148 return this->A[math::Clamp(Index, 0, 8)];
149 }
150
151 /*!*
152 * Getting coordinate operator overloading.
153 *
154 * \param Index - coordinate index.
155 * \return vector cartesian coordinate.
156 */
157 T operator [](int Index) const
158 {
159 return this->A[math::Clamp(Index, 0, 8)];
160 }
161 };
162}
Angle measures types implementatino module.
matr3_data(T A00)
Definition: matr3.h:49
matr3_data(T A00, T A01, T A02, T A10, T A11, T A12, T A20, T A21, T A22)
Definition: matr3.h:37
static T Det(T A11, T A12, T A13, T A21, T A22, T A23, T A31, T A32, T A33)
Definition: matr3.h:132
matr3(T A[3][3])
Definition: matr3.h:96
matr3(T A00)
Definition: matr3.h:103
matr3(const matr4< T > Matr4x4)
Definition: matr3.h:105
matr3(T A00, T A01, T A02, T A10, T A11, T A12, T A20, T A21, T A22)
Definition: matr3.h:84
T Clamp(T Num, T Min=0, T Max=1)
Definition: math_common.h:77
math::matr4< float > matr4
Definition: base.h:48