Skip to content

Instantly share code, notes, and snippets.

@joates
joates / index.js
Last active December 19, 2015 18:48
now that three.js (r59) uses quaternions for rotation by default this is how i extracted player heading in degrees. the player object spawns facing due North and i want compass reading zero to be due North so i have to apply the quaternion rotation to a unit vector pointing due East (along positive X-axis) to implement the 90 degree offset that …
var q = player.quaternion;
var pVec = new THREE.Vector3( 1, 0, 0 ).applyQuaternion( q );
heading = Math.atan2( pVec.z, pVec.x );
heading *= 180 / Math.PI;
heading = heading > 0 ? heading : heading + 360;
heading = Math.floor(heading % 360);