Created by Jaspreet Dhanjan.
- A 4x4 Matrix type. - 2D and 3D Vectors. - Utilities like orthographic and perspective matrices. - Well tested. - Fully documented. - No external libraries required. All operations on instances of the object are designed to modify the attributes of the object itself. Vec3 a = new Vec3(1, 2, 1);
Vec3 b = new Vec3(-1, 1, -1);
a.add(b);
The instance of Vec3 "a" has now been reassigned to a+b or [0, 3, 0].
The Vector-Math-Library overrides Java's clone
method. You can use this to create a "copy" of a vector to store the result of any operations:
Vec3 forward = new Vec3(0, 0, 1);
Vec3 right = new Vec3(1, 0, 0);
Vec3 up = forward.clone().cross(right);
Most operations return the instance of itself – this allows for a fluent interface style by decluttering lines of code:
float playerRotationX = 0.4245f;
Vec3 playerPosition = new Vec3(2, 0, 5);
Mat4 modelViewMatrix = new Mat4().translate(playerPosition).rotX(playerRotationX);
Within 3 lines of code a model-view matrix has been created ready to send to OpenGL.
The Matrix API has been inherently designed for OpenGL use:
FloatBuffer tmpBuffer = BufferUtils.createFloatBuffer(16);
modelViewMatrix.putInto(tmpBuffer);
glUniformMatrix4fv(mat4Location, false, tmpBuffer);