2025年关于glMatrix的介绍

关于glMatrix的介绍引自 https github com toji gl matrix glMatrix With the the increasing popularity of WebGL comes the need for javascript libraries that handle matrix and vector operations glMatrix is

大家好,我是讯享网,很高兴认识大家。

引自:https://github.com/toji/gl-matrix

glMatrix

With the the increasing popularity of WebGL comes the need for javascript libraries that handle matrix and vector operations. glMatrix is designed to handle those operations at stupidly fast speeds!

General Matrix Operations

Most matrix operations share a similar format:

mat4.operation(srcMatrix, otherOperands, destMatrix (optional)); 

讯享网

For all functions following this format the operation will be applied to the values in srcMatrix and the result will be written into destMatrix, which will also be returned. If destMatrix is not specified the result will be written into srcMatrix, if destMatrix is specified srcMatrix will not be altered.


讯享网

Any 4x4 matrix functions expect sequences at least 16 elements in length as inputs when taking a matrix.

Function Documentation

Documentation for the individual functions can be found here

Examples

Creating and using a perspective matrix

讯享网var persp = mat4.create(); mat4.perspective(45, 4/3, 1, 100, persp); gl.uniformMatrix4fv(perspectiveUniform, false, persp); 

Performing multiple transforms on a matrix

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

小讯
上一篇 2025-01-14 22:58
下一篇 2025-02-27 16:09

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/97285.html