What is gl-matrix?
The gl-matrix npm package is a high-performance matrix and vector operations library for WebGL and other JavaScript applications that require mathematical operations on vectors and matrices. It is optimized for performance and memory usage and provides a clean API for a variety of mathematical operations.
What are gl-matrix's main functionalities?
Matrix Operations
Perform operations on 4x4 matrices such as creation, translation, rotation, scaling, and more.
const mat4 = require('gl-matrix').mat4;
let matrix = mat4.create();
mat4.translate(matrix, matrix, [2, 3, 4]);
mat4.rotateX(matrix, matrix, Math.PI / 4);
Vector Operations
Perform operations on 3D vectors such as setting values, normalization, cross product, dot product, and more.
const vec3 = require('gl-matrix').vec3;
let vector = vec3.create();
vec3.set(vector, 1, 2, 3);
vec3.normalize(vector, vector);
Quaternion Operations
Perform operations on quaternions for representing rotations such as creating a quaternion, rotating it, inverting it, and more.
const quat = require('gl-matrix').quat;
let quaternion = quat.create();
quat.rotateX(quaternion, quaternion, Math.PI / 2);
quat.invert(quaternion, quaternion);
Other packages similar to gl-matrix
three
Three.js is a comprehensive 3D graphics library for JavaScript that includes its own set of vector and matrix math utilities. It is more feature-rich than gl-matrix as it is a full 3D engine, but it is also larger and less focused solely on math operations.
math.gl
Math.gl is a suite of math modules for WebGL-focused applications, offering similar functionalities to gl-matrix. It provides a wider set of math utilities, including additional classes for working with geometries, cameras, and more.
vecmath
Vecmath is a vector and matrix math library for JavaScript that is similar to gl-matrix but with a different API design. It may not be as optimized for performance as gl-matrix.
glMatrix
Javascript has evolved into a language capable of handling realtime 3D graphics,
via WebGL, and computationally intensive tasks such as physics simulations.
These types of applications demand high performance vector and matrix math,
which is something that Javascript doesn't provide by default.
glMatrix to the rescue!
glMatrix is designed to perform vector and matrix operations stupidly fast! By
hand-tuning each function for maximum performance and encouraging efficient
usage patterns through API conventions, glMatrix will help you get the most out
of your browsers Javascript engine.
Learn More
For documentation and news, visit the glMatrix Homepage
For a tutorial, see the "introducing glMatrix" section of Introduction to Computer Graphics by David J. Eck
For a babel plugin to make writing the API nicer, see babel-plugin-transfrom-gl-matrix
Regarding the current performance in modern web browsers, calling glMatrix.setMatrixArrayType(Array)
to use normal arrays instead of Float32Arrays can greatly increase the performance.
Contributing Guidelines
See CONTRIBUTING.md
Building
See BUILDING.md