gl Matrixについての紹介


引用:https://github.com/toji/gl-matrix
gl Matrix
With the increase popurrity of WebGL compes the need for javascript libries that handle martrix and vector operations.glMatrix is designed to handle those operation s ap stupudily fast speeds!
General Matrix Operations
Most marix operations share a simiar format:
mat4.operation(srcMatrix, otherOperands, destMatrix (optional));
For all functions follwing this format the operation will be appied to the values in srch Matrix and the result will be written destMatrix,which will also be returned.If deststtrix is not specifield the
Any 4 x 4 matix functions expect sequences at least 16 elemens in length as input when tarix.
Function Dcumentation
Dcumentation for the individual functions can be found here
Examples
Creating and using a perspective matix
var persp = mat4.create();
mat4.perspective(45, 4/3, 1, 100, persp);

gl.uniformMatrix4fv(perspectiveUniform, false, persp);
Performing multiple transforms on a matix
var modelView = mat4.create();

mat4.identity(modelView); // Set to identity
mat4.translate(modelView, [0, 0, -10]); // Translate back 10 units
mat4.rotate(modelView, Math.PI/2, [0, 1, 0]); // Rotate 90 degrees around the Y axis
mat4.scale(modelView, [2, 2, 2]); // Scale by 200%
Updating a destination matrix
var modelViewPersp = mat4.create();

mat4.multiply(modelView, persp, modelViewPersp); // Sets modelViewPersp to modelView * persp 
Tranforming a point
var cameraPos = [0, 0, 0];
var newPos = [0, 0, 0];

mat4.multiplyVec3(modelView, cameraPos); // Result is written into cameraPos
mat4.multiplyVec3(modelView, cameraPos, newPos); // Result is written into newPos