Skip to content

Instantly share code, notes, and snippets.

@joates
Last active December 19, 2015 18:48
Show Gist options
  • Save joates/6001353 to your computer and use it in GitHub Desktop.
Save joates/6001353 to your computer and use it in GitHub Desktop.
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment