Skip to content

Matrix4x4

Jesusemora edited this page Mar 30, 2023 · 5 revisions

Matrix4x4

Variables

                                          
float pos[4][4] naked array containing the values of Matrix4x4. The values are stored as a matrix of float. this is mostly used internally, use x y z w whenever possible
Sub4 &x reference to pos[0]. can be used as myVector4.x.x. can be assigned an IVector4 (Vector4 or Quaternion) or a float[4] or the Sub4 reference from another Matrix4x4 (like myMatrix.x = myMatrix2.x) or a Vector3 or addition and subtraction of other Sub4 references from Matrix4x4.
Sub4 &y reference to pos[1]. can be used as myVector4.y.x. can be assigned an IVector4 (Vector4 or Quaternion) or a float[4] or the Sub4 reference from another Matrix4x4 (like myMatrix.x = myMatrix2.x) or a Vector3 or addition and subtraction of other Sub4 references from Matrix4x4.
Sub4 &z reference to pos[2]. can be used as myVector4.z.x. can be assigned an IVector4 (Vector4 or Quaternion) or a float[4] or the Sub4 reference from another Matrix4x4 (like myMatrix.x = myMatrix2.x) or a Vector3 or addition and subtraction of other Sub4 references from Matrix4x4.
Sub4 &w reference to pos[3]. can be used as myVector4.w.x. can be assigned an IVector4 (Vector4 or Quaternion) or a float[4] or the Sub4 reference from another Matrix4x4 (like myMatrix.x = myMatrix2.x) or a Vector3 or addition and subtraction of other Sub4 references from Matrix4x4.

it is posible to do MyMatrix.x.x to access individual elements of the matrix or MyMatrix.x to assign the values to a Vector4.

public methods

float *toArray() returns a float matrix of size [4][4] with the values of the current Matrix4x4
void Rotate(float phi, float theta, float psi) rotates current Matrix4x4 using euler axes, in ranges between -1 and 1
void Rotate(Vector3 euler) rotates current Matrix4x4 using euler axes, in ranges between -1 and 1
void Translate(Vector3 translation) translates the current Matrix4x4 in the directions given by Vector3
void Translate(float x, float y, float z) translates the current Matrix4x4 in the directions x, y and z

static variables

Matrix4x4 Identity

a Matrix4x4 containing an identity matrix.

static methods

Matrix4x4 Euler(float phi, float theta, float psi) generates and returns a Matrix4x4 given euler rotation in axes x, y and z
Matrix4x4 EulerRotation(float x, float y, float z) generates and returns a Matrix4x4 given euler rotation in axes x, y and z, but using values between -1 and 1 for rotation
Matrix4x4 QuaternionRotation(IVector4 quaternion) converts the Quaternion quaternion into a Matrix4x4 for use in opengl.
Matrix4x4 QuaternionRotation(float i, float j, float k, float L) converts the Quaternion formed by i, j, k, L into a Matrix4x4 for use in opengl.
Matrix4x4 QuaternionRotation(Vector3 euler) generates a Matrix4x4 from a quaternion generated from euler axes. for use in opengl.
Matrix4x4 QuaternionRotation(float rx, float ry, float rz) generates a Matrix4x4 from a quaternion generated from euler axes. for use in opengl.inefficient, it is better to calculate rotation between Quaternion and then transform into matrix once
Vector4 QuaternionEuler(Vector3 axes) generates a quaternion from euler axes. inefficient, it is better to calculate rotation between Quaternion and then transform into matrix once
Matrix4x4 Translation(float x, float y, float z) generates and returns a translation matrix
Matrix4x4 Translation(Vector3 translation) generates and returns a translation matrix
Matrix4x4 Scalation(float x, float y, float z) generates and returns an uneven scale matrix
Matrix4x4 Scalation(Vector3 scale) generates and returns an uneven scale matrix
Matrix4x4 Scalation(float scale) generates and returns an even scale matrix (equal in every direction).
Matrix4x4 Perspective(float FOV, float near, float far) generates and returns a Matrix4x4 to be used as a perspective matrix in opengl.
Matrix4x4 getIdentityMatrix() returns an identity matrix
Matrix4x4 LookAt(Vector3 position, Vector3 target, Vector3 upDirection) work in progress
Matrix4x4 Direction(float (&Mat)[4][4]) work in progress

constructors

Matrix4x4(Vector4 x, Vector4 y, Vector4 z, Vector4 w) generates a Matrix4x4 containing the Vector4s x, y, z and w.
Matrix4x4 generates a Matrix4x4 containing an identity matrix, without parameters
Matrix4x4(float (&obj)[4][4]) initializes Matrix4x4 from an matrix of float of size [4][4]
Matrix4x4(float (&x)[4], float (&y)[4], float (&z)[4], float (&w)[4]) initializes Matrix4x4 from 4 arrays of float of size 4
Matrix4x4(Quaternion quaternion) initializes Matrix4x4 from a quaternion, resulting in a rotation matrix

operators

operator+ adds two Matrix4x4s

operator- subtracts two Matrix4x4s

operator+= adds the values of Matrix4x4 to current

operator-= subtracts the values of Matrix4x4 from current

operator* multiplies a Matrix4x4 by another Matrix4x4, performing matrix multiplication.

operator* multiplies a Matrix4x4 by a matrix of float of size [4][4], performing matrix multiplication.

operator* multiplies a Matrix4x4 by a Vector4, performing matrix multiplication and returning a Vector4

operator*= multiplies the current Matrix4x4 by another Matrix4x4, performing matrix multiplication. this function adds the values to the current Matrix4x4.

operator== returns true if two Matrix4x4s are equal and false if they are different

operator= assigns a Matrix4x4 or matrix of float of size [4][4] to the current Matrix4x4

Clone this wiki locally