Last active
December 19, 2015 18:48
-
-
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 …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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