34 #include "../api_core.h"
35 #include "../System/cl_platform.h"
58 template<
typename Type>
61 template<
typename Type>
64 template<
typename Type>
67 template<
typename Type>
70 template<
typename Type>
78 template<
typename Type>
88 for (
int i=0; i<16; i++)
95 for (
int i=0; i<16; i++)
106 explicit Mat4(
const float *init_matrix)
108 for (
int i=0; i<16; i++)
109 matrix[i] = (Type) init_matrix[i];
113 explicit Mat4(
const double *init_matrix)
115 for (
int i=0; i<16; i++)
116 matrix[i] = (Type) init_matrix[i];
122 for (
int i=0; i<16; i++)
123 matrix[i] = (Type) init_matrix[i];
129 for (
int i=0; i<16; i++)
130 matrix[i] = (Type) init_matrix[i];
136 for (
int i=0; i<16; i++)
137 matrix[i] = (Type) init_matrix[i];
143 for (
int i=0; i<16; i++)
144 matrix[i] = (Type) init_matrix[i];
167 Type field_of_view_y_degrees,
206 return rotate(angle, rotation.
x, rotation.
y, rotation.
z, normalize);
266 Type eye_x, Type eye_y, Type eye_z,
267 Type center_x, Type center_y, Type center_z,
268 Type up_x, Type up_y, Type up_z);
282 return look_at(eye.
x, eye.
y, eye.
z, center.
x, center.
y, center.
z, up.
x, up.
y, up.
z);
339 for (
int i=0; i<16; i++)
342 if (diff < -epsilon || diff > epsilon)
return false;
438 operator Type
const*()
const {
return matrix; }
476 for (
int i=0; i<16; i++)
492 template<
typename Type>
495 template<
typename Type>
498 template<
typename Type>
501 template<
typename Type>
504 template<
typename Type>
507 template<
typename Type>
510 template<
typename Type>
513 template<
typename Type>
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:81
Mat4(const double *init_matrix)
Constructs a 4x4 matrix (copied from a array of doubles)
Definition: mat4.h:113
Mat4< Type > & translate_self(Type x, Type y, Type z)
Translate this matrix.
Angle class.
Definition: angle.h:63
Mat4< Type > operator-(const Mat4< Type > &sub_matrix) const
Subtraction operator.
Type y
Definition: vec3.h:82
static Mat4< Type > subtract(const Mat4< Type > &matrix_1, const Mat4< Type > &matrix_2)
Subtract 2 matrices.
Definition: mat4.h:505
Mat4(const Mat4< Type > ©)
Constructs a 4x4 matrix (copied)
Definition: mat4.h:93
char byte8
Definition: cl_platform.h:59
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.
Mat4< Type > & operator=(const Mat4< Type > ©)
Copy assignment operator.
Definition: mat4.h:456
Mat4< Type > operator+(const Mat4< Type > &add_matrix) const
Addition operator.
Mat4(const byte64 *init_matrix)
Constructs a 4x4 matrix (copied from a array of 64 bit integers)
Definition: mat4.h:120
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:52
Type get_origin_y() const
Returns the y coordinate for the point (0,0,0) multiplied with this matrix.
Definition: mat4.h:359
Mat4(const byte16 *init_matrix)
Constructs a 4x4 matrix (copied from a array of 16 bit integers)
Definition: mat4.h:134
static Mat4< Type > identity()
Create the identity matrix.
Definition: mat4.h:496
static Mat4< Type > null()
Create a zero matrix.
Definition: mat4.h:493
static Mat4< Type > scale(Vec3< Type > xyz)
Create a scale matrix.
Definition: mat4.h:228
Handedness
Definition: mat4.h:46
Mat4(const byte32 *init_matrix)
Constructs a 4x4 matrix (copied from a array of 32 bit integers)
Definition: mat4.h:127
static Mat4< Type > look_at(Vec3< Type > eye, Vec3< Type > center, Vec3< Type > up)
Create the "look at" matrix.
Definition: mat4.h:277
static Mat4< Type > adjoint(const Mat4< Type > &matrix)
Calculate the adjoint (or known as Adjugate or Conjugate Transpose) of a matrix.
Definition: mat4.h:508
bool operator!=(const Mat4< Type > &other)
Not-equal operator.
Definition: mat4.h:482
static Mat4< Type > rotate(const Angle &angle, Vec3< Type > rotation, bool normalize=true)
Create a rotation matrix.
Definition: mat4.h:204
Quaternion.
Definition: mat4.h:71
Mat4()
Constructs a 4x4 matrix (null)
Definition: mat4.h:86
static Mat4< Type > multiply(const Mat4< Type > &matrix_1, const Mat4< Type > &matrix_2)
Multiply 2 matrices.
Definition: mat4.h:499
2D matrix
Definition: mat2.h:46
Type get_origin_z() const
Returns the z coordinate for the point (0,0,0) multiplied with this matrix.
Definition: mat4.h:362
Mat4< Type > operator*(const Mat4< Type > &mult) const
Multiplication operator.
Mat4(const byte8 *init_matrix)
Constructs a 4x4 matrix (copied from a array of 8 bit integers)
Definition: mat4.h:141
Type & operator[](int i)
Operator that returns the matrix cell at the given index.
Definition: mat4.h:444
Mat4(const float *init_matrix)
Constructs a 4x4 matrix (copied from a array of floats)
Definition: mat4.h:106
Mat4< Type > & transpose()
Calculate the transpose of this matrix.
3D matrix
Definition: mat2.h:49
int byte32
Definition: cl_platform.h:63
long long byte64
Definition: cl_platform.h:65
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:337
3D vector
Definition: line_ray.h:49
static Mat4< Type > scale(Type x, Type y, Type z)
Create a scale matrix.
Type get_origin_x() const
Returns the x coordinate for the point (0,0,0) multiplied with this matrix.
Definition: mat4.h:356
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:450
bool operator==(const Mat4< Type > &other) const
Equality operator.
Definition: mat4.h:474
EulerOrder
Euler angle rotation order.
Definition: angle.h:51
Mat4< double > Mat4d
Definition: mat4.h:518
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:514
static Mat4< Type > inverse(const Mat4< Type > &matrix)
Calculate the matrix inverse of a matrix.
Definition: mat4.h:511
Mat4< float > Mat4f
Definition: mat4.h:517
bool is_equal(const Mat4< Type > &other, Type epsilon) const
Returns true if equal within the bounds of an epsilon.
Definition: mat4.h:430
4D matrix
Definition: mat2.h:52
const Type & operator[](unsigned int i) const
Operator that returns the matrix cell at the given index.
Definition: mat4.h:453
Type matrix[16]
The matrix (in column-major format)
Definition: mat4.h:353
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:516
Mat4< Type > & adjoint()
Calculate the adjoint (or known as adjugate) of this matrix.
static Mat4< Type > translate(Vec3< Type > xyz)
Create a translation matrix.
Definition: mat4.h:247
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:447
Type z
Definition: vec3.h:83
short byte16
Definition: cl_platform.h:61
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:502
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.