Skip to content

Instantly share code, notes, and snippets.

@humbletim
Last active November 7, 2015 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save humbletim/54ba84a38d0600fa1661 to your computer and use it in GitHub Desktop.
Save humbletim/54ba84a38d0600fa1661 to your computer and use it in GitHub Desktop.

download and run polyfill-hifi-glm.js (or paste its snippet into the Script Editor) and then once loaded you can verify glm functionality like so:

> glm.version
< 0.0.4

> glm.vec3(MyAvatar.position)
< fvec3(1598.819946, 263.487000, 1879.310059)

> glm.vec3(0,0,1)['*'](glm.inverse(glm.quat(Camera.orientation)))
< fvec3(-0.499926, -0.866012, -0.009918)

> m = glm.mat4()
< mat4x4( (1.000000, 0.000000, 0.000000, 0.000000), (0.000000, 1.000000, 0.000000, 0.000000), (0.000000, 0.000000, 1.000000, 0.000000), (0.000000, 0.000000, 0.000000, 1.000000) )

// convenient reference-based swizzles
> m[3].xyz = [1,2,3]; glm.$to_glsl(m)
< mat4(1,0,0,0,0,1,0,0,0,0,1,0,1,2,3,1)

// transparent support for using external array buffers or typed arrays as the backing store
> var f = new Float32Array(16), m = new glm.mat4(f); m[3].xyz['+='](glm.vec3(1,2,3));  [].slice.call(f)
0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,0
Function.prototype.bind=function(){var fn=this,a=[].slice.call(arguments),o=a.shift();return function(){return fn.apply(o,a.concat([].slice.call(arguments)));};};
$GLM_console_log = function() { print(["[glm]"].concat([].slice.call(arguments)).join(" ")); };
Script.include('http://humbletim.github.io/glm-js/code/build/glm-gl-matrix.min.js')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment