Skip to content

Matrices (Mat4)

Juptian edited this page Oct 13, 2020 · 2 revisions

Matrices (aka Mat4s)

Matrices are used for things like rotation, translation, scale, aswell as projections!

The include for it is:

#include "Source/Code/Maths/Math.h"

Variables

float elements[16];

Vector4 columns[4];

These arrays are 4x4 arrays of values, used to make matrices usable. an element is used for each individual part of the array, the columns are used to get an entire column.

Functions

Here are the functions with definitions:

Mat4()

This is a general constructor, it will always return a matrices with all its elements equal to 1.

Mat4(float diagonal)

This is a constructor, where you can set the diagonal set elements number 1, 6, 11, and 16 (or 0, 5, 10, 15 if you start at 0) to the same value.

Mat4 Identity()

This function will return a Mat4 with a diagonal set to 1.

Mat4 Orthographic(float left, float right, float bottom, float top, float near, float far)

This is a projection matrix where all objects will maintain their current size regardless of distance it will return a Mat4 with the result of the matrix math required for it to accomplish its job.

Mat4 Perspective(float fov, float aspectRatio, float near, float far)

This is a projection matrix where all objects will get smaller as you get further. it will return you a Mat4 with the result of the math required.

Mat4 Translation(const Vector3& translation)

This is used to translate an object's location to another point while maintaining rotation.

Mat4 Rotation(float angle, const Vector3& axis)

This is used to rotate an object around the specified axis in the Vector3

Mat4 Scale(const Vector3& scale)

This will return a matrix result of the object with its specific scale. You can use this to scale objects