Exhibit 0 glMatrix
What are We Doing?
- We often have vectors and matrices to deal with in WebGL code. So far we have been storing
them in JavascriptLists and manually unpacking the values to pass them separately into WebGL
calls such as
gl.Uniform3f
.
- Many WebGL methods also come in
...v
versions that accept an array, so that you
don't need to manually unpack the values. For instance, gl.Uniform3fv
.
- These methods want Javascript typed arrays and will do a potentially slow
conversion if you pass them normal Javascript arrays. Sadly, such arrays are a hassle
to generate and work with. Also, if we are going to store vectors (and soon matrices) in arrays
we would like to have a library for doing math on these objects, rather than writing out
error-prone elementwise equations.
- There are various pacakges for doing this, and a good one is glMatrix.
It has types that mirror the GLSL types
vec2
, vec3
, etc.
Demo
This page has a WebGL program that draws a cat. Take a look at the code; it is similar to
other such programs we've written recently, but it uses glMatrix to store vectors.