FrostyCat
Redemption Seeker
GMLinear 2
Easy matrix and vector operations for GMS 2.3.3+
Overview
GMLinear is an implementation of matrix and vector operations in pure GML. You can use it to simplify many common calculations in 2D and 3D geometry and implement algorithms/formulas involving linear algebra.
Features
GMS 2.3.3+: YoYo Marketplace | Download | GitHub | Documentation
Older Versions
GMS 2.2: Download | Documentation
GMS 1.4: Download | Documentation
Example
Find the intersection point between the plane containing the point (0, 0, 1) with a normal of (1, 0, 0), and the line containing the point (4, 9, -4) and pointing in the direction (-1, 3, 0.5). (see: Line-plane intersection)
With GMLinear:
Without GMLinear:
Feedback Welcome!
If you have any suggestions for new constructors/use cases or bug reports, please open an issue or contribute on GitHub.
Easy matrix and vector operations for GMS 2.3.3+
Overview
GMLinear is an implementation of matrix and vector operations in pure GML. You can use it to simplify many common calculations in 2D and 3D geometry and implement algorithms/formulas involving linear algebra.
Features
- Easy to use, intuitive constructors for building vectors and matrices quickly
- Vector operations: Addition, subtraction, dot product, cross product, scalar-vector product, norms, distances, unit vectors, linear interpolation, projection/rejection, coordinate system conversions
- Matrix operations: Addition, subtraction, scalar-matrix product, matrix-matrix product, matrix-vector product, transpose, inverse
- Hard-coded optimized functions available for 2D, 3D and 4D vectors and 2x2, 3x3 and 4x4 matrices
GMS 2.3.3+: YoYo Marketplace | Download | GitHub | Documentation
Older Versions
GMS 2.2: Download | Documentation
GMS 1.4: Download | Documentation
Example
Find the intersection point between the plane containing the point (0, 0, 1) with a normal of (1, 0, 0), and the line containing the point (4, 9, -4) and pointing in the direction (-1, 3, 0.5). (see: Line-plane intersection)
With GMLinear:
Code:
p_0 = [0, 0, 1];
n = [1, 0, 0];
l_0 = [4, 9, -4];
l = [-1, 3, 0.5];
d = r3_dot(r3_subtract(p_0, l_0), n)/r3_dot(l, n);
intersection = r3_add(l_0, r3_scale(l, d));
show_message("Intersection point is: " + string(intersection));
Code:
p_0x = 0;
p_0y = 0;
p_0z = 1;
nx = 1;
ny = 0;
nz = 0;
l_0x = 4;
l_0y = 9;
l_0z = -4;
lx = -1;
ly = 3;
lz = 0.5;
d = (((p_0x-l_0x)*nx)+((p_0y-l_0y)*ny)+((p_0z-l_0z)*nz))/(lx*nx+ly*ny+lz*nz);
intersectionx = l_0x+d*lx;
intersectiony = l_0y+d*ly;
intersectionz = l_0z+d*lz;
show_message("Intersection point is: [" + string(intersectionx) + ", " + string(intersectiony) + ", " + string(intersectionz) + "]");
Feedback Welcome!
If you have any suggestions for new constructors/use cases or bug reports, please open an issue or contribute on GitHub.
Last edited: