52 Mat3t(
const std::array<T, 9>& e):
84 s <<
"[" << e[0] <<
", " << e[1] <<
", " << e[2] << std::endl <<
85 " " << e[3] <<
", " << e[4] <<
", " << e[5] << std::endl <<
86 " " << e[6] <<
", " << e[7] <<
", " << e[8] <<
"]";
110 operator const T*(void)
const{
117 return Mat3t{e[0]*scalar,e[1]*scalar,e[2]*scalar,
118 e[3]*scalar,e[4]*scalar,e[5]*scalar,
119 e[6]*scalar,e[7]*scalar,e[8]*scalar};
123 return Mat3t{e[0]+scalar,e[1]+scalar,e[2]+scalar,e[3]+scalar,
124 e[4]+scalar,e[5]+scalar,e[6]+scalar,e[7]+scalar,
129 return Mat3t{e[0]-scalar,e[1]-scalar,e[2]-scalar,e[3]-scalar,
130 e[4]-scalar,e[5]-scalar,e[6]-scalar,e[7]-scalar,
135 return Mat3t{e[0]/scalar,e[1]/scalar,e[2]/scalar,e[3]/scalar,
136 e[4]/scalar,e[5]/scalar,e[6]/scalar,e[7]/scalar,
146 for (uint8_t x = 0;x<9;x+=3)
147 for (uint8_t y = 0;y<3;y++)
148 result.e[x+y] = e[0+x] * other.e[0+y]+
149 e[1+x] * other.e[3+y]+
150 e[2+x] * other.e[6+y];
158 return Vec3t<T>{(other.
x*e[0]+other.
y*e[1]+other.
z*e[2]),
159 (other.
x*e[3]+other.
y*e[4]+other.
z*e[5]),
160 (other.
x*e[6]+other.
y*e[7]+other.
z*e[8])};
176 const T angle{deg2Rad(degree)};
177 const T cosAngle = cosf(angle);
178 const T sinAngle = sinf(angle);
181 0, cosAngle, sinAngle,
182 0, -sinAngle, cosAngle};
186 const T angle{deg2Rad(degree)};
187 const T cosAngle{cosf(angle)};
188 const T sinAngle{sinf(angle)};
190 return {cosAngle, 0, -sinAngle,
192 sinAngle, 0, cosAngle};
196 const T angle{deg2Rad(degree)};
197 const T cosAngle{cosf(angle)};
198 const T sinAngle{sinf(angle)};
200 return {cosAngle, sinAngle, 0,
201 -sinAngle, cosAngle, 0,
207 return {m.e[0],m.e[3],m.e[6],
208 m.e[1],m.e[4],m.e[7],
209 m.e[2],m.e[5],m.e[8]};
214 return m.e[0]*(m.e[4]*m.e[8]-m.e[5]*m.e[7])-m.e[1]*(m.e[3]*m.e[8]-m.e[5]*m.e[6])+m.e[2]*(m.e[3]*m.e[7]-m.e[4]*m.e[6]);
228 (m.e[4]*m.e[8]-m.e[5]*m.e[7])*Q, (m.e[2]*m.e[7]-m.e[1]*m.e[8])*Q, (m.e[1]*m.e[5]-m.e[2]*m.e[4])*Q,
229 (m.e[5]*m.e[6]-m.e[3]*m.e[8])*Q, (m.e[0]*m.e[8]-m.e[2]*m.e[6])*Q, (m.e[2]*m.e[3]-m.e[0]*m.e[5])*Q,
230 (m.e[3]*m.e[7]-m.e[4]*m.e[6])*Q, (m.e[1]*m.e[6]-m.e[0]*m.e[7])*Q, (m.e[0]*m.e[4]-m.e[1]*m.e[3])*Q
248 static T deg2Rad(
const T d) {
249 return T(3.14159265358979323846)*d/T(180);
Mat3t< float > Mat3
Single-precision 3×3 matrix.
Definition Mat3.h:254
3D vector template with arithmetic, geometry helpers, and RNG utilities.
Mat3t(const std::array< T, 9 > &e)
Construct from a raw array of 9 elements.
Definition Mat3.h:52
Mat3t()
Construct the identity matrix.
Definition Mat3.h:29
Mat3t(const Vec3t< T > &e1, const Vec3t< T > &e2, const Vec3t< T > &e3)
Construct from three column vectors.
Definition Mat3.h:63
const std::string toString() const
String representation (pretty-printed rows).
Definition Mat3.h:82
Mat3t(const Mat3t &other)
Copy-construct from another matrix.
Definition Mat3.h:73
static Mat3t scaling(const Vec3t< T > &scale)
Non-uniform scaling by components of scale.
Definition Mat3.h:165
static Mat3t inverse(const Mat3t &m, T det)
Matrix inverse with precomputed determinant.
Definition Mat3.h:224
Mat3t operator*(T scalar) const
Component-wise multiplication by scalar.
Definition Mat3.h:116
static Mat3t scaling(T x, T y, T z)
Non-uniform scaling by components.
Definition Mat3.h:169
static Mat3t inverse(const Mat3t &m)
Matrix inverse computed via adjugate and determinant.
Definition Mat3.h:239
static Mat3t rotationZ(T degree)
Rotation about the Z-axis by degree (degrees).
Definition Mat3.h:195
Mat3t(T m11, T m12, T m13, T m21, T m22, T m23, T m31, T m32, T m33)
Construct from 9 elements (column-major order).
Definition Mat3.h:39
Mat3t operator/(T scalar) const
Component-wise division by scalar.
Definition Mat3.h:134
static Mat3t rotationY(T degree)
Rotation about the Y-axis by degree (degrees).
Definition Mat3.h:185
static Mat3t transpose(const Mat3t &m)
Transpose of a 3×3 matrix.
Definition Mat3.h:206
Mat3t operator+(T scalar) const
Component-wise addition of scalar.
Definition Mat3.h:122
Mat3t operator-(T scalar) const
Component-wise subtraction of scalar.
Definition Mat3.h:128
friend std::ostream & operator<<(std::ostream &os, const Mat3t &m)
Stream insertion using toString().
Definition Mat3.h:93
static Mat3t rotationX(T degree)
Rotation about the X-axis by degree (degrees).
Definition Mat3.h:175
static T det(const Mat3t &m)
Determinant of a 3×3 matrix.
Definition Mat3.h:213