Mat4x4 Library For Computer Graphics

https://www.roblox.com/library/8174230233/Matrix4x4Tools

Check out these if you are confused how to use the module

https://www.scratchapixel.com/lessons/3d-basic-rendering/rasterization-practical-implementation/rasterization-stage

all transformations are assumed to be in a format of column vectors with clipping being on a range of -1 to 1

function: mat4x4.new(matrix (2d array), isAVector (bool) )
The idea is you want to represent your vector like a 2d matrix, I think it is kinda self-explanatory but if you are tripped out you can see in the code. If you do do that set isAVector to false, else if you just want to convert your roblox vector to a column vector just pass the roblox vector into matrix and set isAVector to true.

function: multiply(a,b)
Performs matrix-matrix multiplication. I found getting rid of the metamethod for multiplication improved performance, though if you MUST have it, it is pretty simple to implement.

function: m2v3
Perform the perspective-divide on a given coloumn vector.

function: rotate(string, “x” | “y” | “z”)
The way I did templates was kinda weird, and it is probably just my fault for not understanding lua prototypes enough. Basically you have to do something like this

local rotateYTransform = mat4x4.new():rotate("Y", os.clock())

function: perspective(fov, n, f)
Transform your world-space coords to a range where they will be “visible” assuming using a view matrix if each entry is between -1 to 1. Also manipulates them to make them smaller far away. In the code change frustum_h* (script.Parent.Dimensions.Value.X/script.Parent.Dimensions.Value.Y) to your aspect ratio of your render target (most of the times is 1.

function: scale(x,y,z)
Scale transformation.

function: lookAt(eye, target)
Affectively does what robloxs cframe class does. Eye and target need to be column vectors

14 Likes

so, this is supposed to be like processors right?

Real cool

oh wow. No longer do I have to use CFrames in my renderers. So good to see that this is now an option!

oh no no no no no DO NOT DO THIS!!! it will make it super slow dude. you wanna use cframes and precompute the values for the projection matrix and the normal matrix, remember that the bottom row is assumed to be 0,0,0,1

1 Like