This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Emma's profile picture

Matrix4 and Vector4 APIs

Started by Emma, 02 June 2016 - 04:35 AM
Emma #1
Posted 02 June 2016 - 06:35 AM
So I just got done porting a Matrix4f and a Vector4f api to lua. Decided to release the source in case anyone else needed them. So, here you go.
Matrix4: ewsWU1RZ
Vector4: M45y8y5z

They are created OOP style for your convenience
Usage:
  1. Load them in with dofile
    Spoiler
    dofile("matrix4f")
  2. To create a matrix4 or vector4 just call Matrix4f() or Vector4f() and an object will be returned
    Spoiler
    local myNewMatrix = Matrix4f()
    local myNewVector = Vector4f(3,5,6,1)	
Available functions:

Matrix4f:
Spoiler
  • Matrix4f()
  • Matrix4f:InitIdentity()
  • Matrix4f:InitScreenSpaceTransform(float halfWidth, float halfHeight)
  • Matrix4f:InitTranslation(float x, float y, float z)
  • Matrix4f:InitRotation(float x, float y, float z, float angle)
  • Matrix4f:InitRotation(float x, float y, float z)
  • Matrix4f:InitScale(float x, float y, float z)
  • Matrix4f:InitPerspective(float fov, float aspectRatio, float zNear, float zFar)
  • Matrix4f:InitOrthographic(float left, float right, float bottom, float top, float near, float far)
  • Matrix4f:InitRotation(Vector4f forward, Vector4f up)
  • Matrix4f:InitRotation(Vector4f forward, Vector4f up, Vector4f right)
  • Matrix4f:Transform(Vector4f r)
  • Matrix4f:Mul(Matrix4f r)
  • Matrix4f:GetM()
  • Matrix4f:Get(int x, int y)
  • Matrix4f:SetM(float[][] m)
  • Matrix4f:Set(int x, int y, float value)

Vector4f:
Spoiler
  • Vector4f(float x, float y, float z, float w)
  • Vector4f:Length()
  • Vector4f:Max()
  • Vector4f:Dot(Vector4f r)
  • Vector4f:Cross(Vector4f r)
  • Vector4f:Normalized()
  • Vector4f:Rotate(Vector4f axis, float angle)
  • Vector4f:Lerp(Vector4f dest, float lerpFactor)
  • Vector4f:Add(Vector4f r)
  • Vector4f:Add(float r)
  • Vector4f:Sub(Vector4f r)
  • Vector4f:Sub(float r)
  • Vector4f:Mul(Vector4f r)
  • Vector4f:Mul(float r)
  • Vector4f:Div(Vector4f r)
  • Vector4f:Div(float r)
  • Vector4f:Abs()
  • Vector4f:toString()
  • Vector4f:GetX()
  • Vector4f:GetY()
  • Vector4f:GetZ()
  • Vector4f:GetW()
  • Vector4f:equals(Vector4f r)

PS: If you don't know what these functions do, then you probably don't need these APIs.

Note: These apis were ported from this github repo

Please report any bugs you find here and I will fix them! :D/> Thanks!
Creator #2
Posted 02 June 2016 - 04:54 PM
Dude, awesome!
jv110 #3
Posted 05 June 2016 - 07:19 PM
Well… VertexGL had that (+ quaternion). Not complaining tho, it's pretty good.
Emma #4
Posted 07 June 2016 - 02:38 AM
Well… VertexGL had that (+ quaternion). Not complaining tho, it's pretty good.
K.

Well, the libraries that are included in VertexGL are packaged with VertexGL and would need to be seperated from it for use. I posted this purely as a convenience for others. Also, I ended up adding quaternion to this, but I haven't updated the pastebin/op yet.
Thanks though! :)/>
apemanzilla #5
Posted 07 June 2016 - 03:44 AM
Psst, return the API tables instead of loading them into _G!


matrix4 = dofile "matrix4"
Edited on 07 June 2016 - 01:44 AM
Emma #6
Posted 07 June 2016 - 03:57 AM
Psst, return the API tables instead of loading them into _G!


matrix4 = dofile "matrix4"

Yeah, bad habit of mine that I really should stop doing. :P/>

Edit: Updated pastebins to return the tables
Edited on 07 June 2016 - 02:23 AM