34 #include "../System/cl_platform.h"
57 template<
typename Type>
60 template<
typename Type>
63 template<
typename Type>
66 template<
typename Type>
69 template<
typename Type>
77 template<
typename Type>
94 for (
int i=0;
i<16;
i++)
105 explicit Mat4(
const float *init_matrix)
107 for (
int i=0;
i<16;
i++)
112 explicit Mat4(
const double *init_matrix)
114 for (
int i=0;
i<16;
i++)
119 explicit Mat4(
const int64_t *init_matrix)
121 for (
int i=0;
i<16;
i++)
126 explicit Mat4(
const int32_t *init_matrix)
128 for (
int i=0;
i<16;
i++)
133 explicit Mat4(
const int16_t *init_matrix)
135 for (
int i=0;
i<16;
i++)
140 explicit Mat4(
const int8_t *init_matrix)
142 for (
int i=0;
i<16;
i++)
166 Type field_of_view_y_degrees,
205 return rotate(angle, rotation.
x, rotation.
y, rotation.
z, normalize);
265 Type eye_x, Type eye_y, Type eye_z,
266 Type center_x, Type center_y, Type center_z,
267 Type up_x, Type up_y, Type up_z);
281 return look_at(eye.
x, eye.
y, eye.
z, center.
x, center.
y, center.
z, up.
x, up.
y, up.
z);
338 for (
int i=0;
i<16;
i++)
341 if (diff < -epsilon || diff > epsilon)
return false;
472 operator Type
const*()
const {
return matrix; }
510 for (
int i=0;
i<16;
i++)
511 if (matrix[
i] != other.
matrix[
i])
return false;
526 template<
typename Type>
529 template<
typename Type>
532 template<
typename Type>
535 template<
typename Type>
538 template<
typename Type>
541 template<
typename Type>
544 template<
typename Type>
547 template<
typename Type>
Mat4< Type > & scale_self(const Vec3< Type > &scale)
Scale this matrix.
Definition: mat4.h:390
Mat4(const int32_t *init_matrix)
Constructs a 4x4 matrix (copied from a array of 32 bit integers)
Definition: mat4.h:126
Mat4< Type > & set_translate(Type x, Type y, Type z)
Set this matrix translation values.
Definition: mat4.h:424
static Mat4< Type > ortho(Type left, Type right, Type bottom, Type top, Type z_near, Type z_far, Handedness handedness, ClipZRange clip_z)
Create a ortho matrix.
double det() const
Calculate the matrix determinant of this matrix.
Type x
Definition: vec3.h:80
Mat4(const double *init_matrix)
Constructs a 4x4 matrix (copied from a array of doubles)
Definition: mat4.h:112
Mat4< Type > & set_translate(const Vec3< Type > &translation)
Set this matrix translation values.
Definition: mat4.h:434
Mat4< Type > & translate_self(Type x, Type y, Type z)
Translate this matrix.
Angle class.
Definition: angle.h:62
Mat4< Type > operator-(const Mat4< Type > &sub_matrix) const
Subtraction operator.
Type y
Definition: vec3.h:81
static Mat4< Type > subtract(const Mat4< Type > &matrix_1, const Mat4< Type > &matrix_2)
Subtract 2 matrices.
Definition: mat4.h:539
Mat4(const Mat4< Type > ©)
Constructs a 4x4 matrix (copied)
Definition: mat4.h:92
Mat4(const int8_t *init_matrix)
Constructs a 4x4 matrix (copied from a array of 8 bit integers)
Definition: mat4.h:140
static Mat4< Type > look_at(Type eye_x, Type eye_y, Type eye_z, Type center_x, Type center_y, Type center_z, Type up_x, Type up_y, Type up_z)
Create the "look at" matrix.
Vec3< Type > get_translate() const
Returns the translation coordinates for this matrix (in column-major format)
Definition: mat4.h:355
Mat4< Type > & operator=(const Mat4< Type > ©)
Copy assignment operator.
Definition: mat4.h:490
Mat4< Type > operator+(const Mat4< Type > &add_matrix) const
Addition operator.
Vec3< Type > get_transformed_point(const Vec3< Type > &vector) const
Get a transformed point from the matrix (in column-major format)
ClipZRange
Definition: mat4.h:51
static Mat4< Type > translate(const Vec3< Type > &xyz)
Create a translation matrix.
Definition: mat4.h:246
Mat4(const int16_t *init_matrix)
Constructs a 4x4 matrix (copied from a array of 16 bit integers)
Definition: mat4.h:133
static Mat4< Type > identity()
Create the identity matrix.
Definition: mat4.h:530
static Mat4< Type > null()
Create a zero matrix.
Definition: mat4.h:527
Mat4< Type > & translate_self(const Vec3< Type > &translation)
Translate this matrix.
Definition: mat4.h:412
Mat4(const int64_t *init_matrix)
Constructs a 4x4 matrix (copied from a array of 64 bit integers)
Definition: mat4.h:119
Handedness
Definition: mat4.h:45
static Mat4< Type > look_at(Vec3< Type > eye, Vec3< Type > center, Vec3< Type > up)
Create the "look at" matrix.
Definition: mat4.h:276
static Mat4< Type > adjoint(const Mat4< Type > &matrix)
Calculate the adjoint (or known as Adjugate or Conjugate Transpose) of a matrix.
Definition: mat4.h:542
bool operator!=(const Mat4< Type > &other)
Not-equal operator.
Definition: mat4.h:516
static Mat4< Type > rotate(const Angle &angle, Vec3< Type > rotation, bool normalize=true)
Create a rotation matrix.
Definition: mat4.h:203
Quaternion.
Definition: mat4.h:70
Mat4()
Constructs a 4x4 matrix (zero'ed)
Definition: mat4.h:85
static Mat4< Type > multiply(const Mat4< Type > &matrix_1, const Mat4< Type > &matrix_2)
Multiply 2 matrices.
Definition: mat4.h:533
2D matrix
Definition: mat2.h:45
Mat4< Type > operator*(const Mat4< Type > &mult) const
Multiplication operator.
Type & operator[](int i)
Operator that returns the matrix cell at the given index.
Definition: mat4.h:478
Mat4(const float *init_matrix)
Constructs a 4x4 matrix (copied from a array of floats)
Definition: mat4.h:105
Mat4< Type > & transpose()
Calculate the transpose of this matrix.
3D matrix
Definition: mat2.h:48
void decompose(Vec3< Type > &out_position, Quaternionx< Type > &out_orientation, Vec3< Type > &out_scale) const
Decompose matrix into position, orientation/rotation and scale.
static bool is_equal(const Mat4< Type > &first, const Mat4< Type > &second, Type epsilon)
Returns true if equal within the bounds of an epsilon.
Definition: mat4.h:336
3D vector
Definition: line_ray.h:48
static Mat4< Type > scale(Type x, Type y, Type z)
Create a scale matrix.
static Mat4< Type > translate(Type x, Type y, Type z)
Create a translation matrix.
static Mat4< Type > rotate(const Angle &angle, Type x, Type y, Type z, bool normalize=true)
Create a rotation matrix.
Type & operator[](unsigned int i)
Operator that returns the matrix cell at the given index.
Definition: mat4.h:484
bool operator==(const Mat4< Type > &other) const
Equality operator.
Definition: mat4.h:508
EulerOrder
Euler angle rotation order.
Definition: angle.h:50
Mat4< double > Mat4d
Definition: mat4.h:552
static Mat4< Type > ortho_2d(Type left, Type right, Type bottom, Type top, Handedness handedness, ClipZRange clip_z)
Create a ortho_2d matrix.
static Mat4< Type > transpose(const Mat4< Type > &matrix)
Calculate the transpose of a matrix.
Definition: mat4.h:548
static Mat4< Type > inverse(const Mat4< Type > &matrix)
Calculate the matrix inverse of a matrix.
Definition: mat4.h:545
Mat4< float > Mat4f
Definition: mat4.h:551
bool is_equal(const Mat4< Type > &other, Type epsilon) const
Returns true if equal within the bounds of an epsilon.
Definition: mat4.h:464
4D matrix
Definition: mat2.h:51
const Type & operator[](unsigned int i) const
Operator that returns the matrix cell at the given index.
Definition: mat4.h:487
Type matrix[16]
The matrix (in column-major format)
Definition: mat4.h:352
Vec3< Type > get_euler(EulerOrder order) const
Extract the euler angles (in radians) from a matrix (in column-major format)
Mat4< int > Mat4i
Definition: mat4.h:550
Mat4< Type > & adjoint()
Calculate the adjoint (or known as adjugate) of this matrix.
Mat4< Type > & scale_self(Type x, Type y, Type z)
Scale this matrix.
static Mat4< Type > frustum(Type left, Type right, Type bottom, Type top, Type z_near, Type z_far, Handedness handedness, ClipZRange clip_z)
Create a frustum matrix.
const Type & operator[](int i) const
Operator that returns the matrix cell at the given index.
Definition: mat4.h:481
static Mat4< Type > scale(const Vec3< Type > &xyz)
Create a scale matrix.
Definition: mat4.h:227
Type z
Definition: vec3.h:82
Mat4< Type > & inverse()
Calculate the matrix inverse of this matrix.
static Mat4< Type > add(const Mat4< Type > &matrix_1, const Mat4< Type > &matrix_2)
Add 2 matrices.
Definition: mat4.h:536
static Mat4< Type > perspective(Type field_of_view_y_degrees, Type aspect, Type z_near, Type z_far, Handedness handedness, ClipZRange clip_z)
Create a perspective matrix.