Skip to content

Instantly share code, notes, and snippets.

@mmassing
Last active March 8, 2019 11:05
Show Gist options
  • Save mmassing/1e35f931621835d833088961c34d4ad9 to your computer and use it in GitHub Desktop.
Save mmassing/1e35f931621835d833088961c34d4ad9 to your computer and use it in GitHub Desktop.
ENU basis
function ENUBasis(p)
{
// Up is vector from origin
var z = vec3.create();
vec3.normalize(z, p);
var y = vec3.create();
vec3.set(y, 0, 1, 0);
var x = vec3.create();
vec3.cross(x, z, y);
vec3.normalize(x, x);
vec3.cross(y, x, z);
vec3.normalize(y, y);
// Create basis matrix
var basis = mat3.create();
basis[0] = x[0];
basis[1] = x[1];
basis[2] = x[2];
basis[3] = y[0];
basis[4] = y[1];
basis[5] = y[2];
basis[6] = z[0];
basis[7] = z[1];
basis[8] = z[2];
return basis;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment