Created
January 25, 2013 01:23
-
-
Save lazd/4630739 to your computer and use it in GitHub Desktop.
THREE.JS: Rotate an object in 3D space given the position of the axes of a gamepad
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 xRot = gamepad.y; | |
var yRot = gamepad.x; | |
// Rotate X relative to model axis | |
object.matrix.rotateX(xRot); | |
// Rotate Y relative to world axis | |
var axis = new THREE.Vector3(0,1,0); | |
var rotWorldMatrix = new THREE.Matrix4(); | |
rotWorldMatrix.makeRotationAxis(axis.normalize(), yRot); | |
rotWorldMatrix.multiplySelf(object.matrix); // pre-multiply | |
object.matrix = rotWorldMatrix; | |
object.rotation.setEulerFromRotationMatrix(object.matrix, 'XYZ'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment