Last active
August 29, 2015 14:02
-
-
Save kumavis/57144f2d72f46d1cac4b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Utility - changes the parent but preserves global position + rotation | |
function orientUnderParent( target, parent ) { | |
// calculate new pos | |
var newPos = new THREE.Vector3() | |
newPos.setFromMatrixPosition( target.matrixWorld ) | |
parent.worldToLocal( newPos ) | |
target.position = newPos | |
// calculate new rot | |
var newRot = new THREE.Quaternion() | |
newRot.setFromRotationMatrix( target.matrixWorld ) | |
newRot.multiply( parent.quaternion.clone().inverse() ) | |
target.quaternion.copy( newRot ) | |
// attach to parent | |
parent.add( target ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
revised: