Created
November 24, 2012 04:36
-
-
Save clavis-magna/4138387 to your computer and use it in GitHub Desktop.
local and global rotation functions for THREE.js objects updated for recent revisions of THREE.js
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
//following two rotation functions are updated versions of code from: https://github.com/mrdoob/three.js/issues/1219 | |
//updated to work in latest versions (r52 tested) of THREE.js | |
// Rotate an object around an axis in object space | |
var rotationMatrix | |
function rotateAroundObjectAxis( object, axis, radians ) { | |
rotationMatrix = new THREE.Matrix4(); | |
rotationMatrix.makeRotationAxis( axis.normalize(), radians ); | |
object.matrix.multiplySelf( rotationMatrix ); // post-multiply | |
object.rotation.setEulerFromRotationMatrix(object.matrix, object.order); | |
} | |
// Rotate an object around an axis in world space (the axis passes through the object's position) | |
var rotWorldMatrix; | |
function rotateAroundWorldAxis( object, axis, radians ) { | |
rotWorldMatrix = new THREE.Matrix4(); | |
rotWorldMatrix.makeRotationAxis(axis.normalize(), radians); | |
rotWorldMatrix.multiplySelf(object.matrix); // pre-multiply | |
object.matrix = rotWorldMatrix; | |
object.rotation.setEulerFromRotationMatrix(object.matrix, object.order); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In case anyone needs this, I managed to solve it like this
you need to call
object.updateWorldMatrix(true)
in order to get up to date results fromobject.getWorldQuaternion()