PDA

View Full Version : glMatrix - Stupidly fast WebGL matricies



Toji
06-03-2010, 06:28 AM
I've just released a new javascript matrix library for use with WebGL called glMatrix. Though it wasn't an initial goal of the library, when all was said and done it appears to be the fastest matrix library available. (Though I would love for someone to prove me wrong on that!)

As a first release I fully expect a random bug or two to crop up, but I'm committed to squashing them as quickly as possible. Outside of that, though, I would love any feedback on ways that this library could be improved! Please take a moment and check it out!

Links:
glMatrix on Google Code (http://glmatrix.googlecode.com/)
Introductory blog post (http://tojicode.blogspot.com/2010/06/stupidly-fast-webgl-matricies.html)
Live Benchmark (http://glmatrix.googlecode.com/hg/benchmark/matrix_benchmark.html) (It takes a moment to run, be patient...)

miroslav_karpis
06-11-2010, 03:45 AM
Thank you for sharing - implemented + works nice :wink:

m.sirin
07-17-2010, 03:06 AM
hi, looks promising!
is there some docs, because the code is hard to read?

the tojicode blog does not work at the moment..

miroslav_karpis
07-17-2010, 03:52 AM
is there some docs, because the code is hard to read?

Hi, I think you are looking for this one (http://code.google.com/p/glmatrix/wiki/Usage) (glmatrix project page - google code)

m.sirin
07-17-2010, 05:13 AM
yes :D , thank you!

Toji
07-17-2010, 07:12 AM
the tojicode blog does not work at the moment..

Yeah, I'm switching hosts (again) and having some DNS problems. May take a bit to get working, sorry!

54LV47RUCH4
10-30-2010, 08:57 AM
good work thanks for that!

i will try the ortho function !

manixrock
11-03-2010, 06:34 AM
You are doing something in your functions which is very unsafe. You are using


if(!dest) { dest = mat; }

This is very bad because users won't expect that input matrix to be changed inside the function. For example:



var m1 = mat4.create(...);
var m2 = mat4.create(...);
var m3 = mat4.multiply(m1, m2);
var m4 = mat4.multiply(m1, m3); // will not work as expected since m1 is changed


Users will expect m1 to still have the value it had before the previous line, however m1 and m3 now point to the same object. This should not be the default behavior, and no parameters other than dest should be modified inside the function.

If the user wanted to explicitly use m1 to store the final value he could simply have done:



mat4.multiply(m1, m2, m1);


This way it's much clearer what he meant to do. It also makes the objects themselves behave as if they were immutable in some sense, since they are never modified inside the functions unless explicitly told to. No functionality or performance is lost, and it should make for a much safer coding practice. The solution is simple, instead of setting "dest = mat;" (or equivalent) it should set it to "mat4.create();" (or equivalent)

The affected functions include (but may not be limited to): vec3.negate(), vec3.normalize(), vec3.cross(), vec3.direction(), mat4.inverse(), mat4.multiply(), mat4.multiplyVec3(), mat4.multiplyVec4(), mat4.rotate(), mat4.rotateX(), mat4.rotateY(), mat4.rotateZ(), quat4.normalize(), quat4.multiply(), quat4.multiplyVec3().

gero3
12-28-2010, 05:33 AM
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.

This is out of the wiki of glmatrix