Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
30
rated 0 times [  32] [ 2]  / answers: 1 / hits: 28135  / 12 Years ago, wed, june 20, 2012, 12:00:00

Is it possible to do rotations taking axis of the world and not of the object?



I need to do some rotations of an object, but after the first rotation, I can't do other rotations like i want.



If it's not possible to do rotation on the axis of the world, my second option is to reset the axis after the first rotation. Is there some function for this?



I can't use object.eulerOrder because it changes the orientation of my object when I set object.eulerOrder=YZX after some rotations.


More From » three.js

 Answers
19

UPDATED: THREE - 0.125.2


DEMO: codesandbox.io


const THREE = require("three");

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000
);
camera.position.z = 5;

const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

const geometry = new THREE.BoxGeometry(1, 1, 1, 4, 4, 4);
const material = new THREE.MeshBasicMaterial({
color: 0x628297,
wireframe: true
});
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);

// select the Z world axis
const myAxis = new THREE.Vector3(0, 0, 1);
// rotate the mesh 45 on this axis
cube.rotateOnWorldAxis(myAxis, THREE.Math.degToRad(45));

function animate() {
// rotate our object on its Y axis,
// but notice the cube has been transformed on world axis, so it will be tilted 45deg.
cube.rotation.y += 0.008;
requestAnimationFrame(animate);
renderer.render(scene, camera);
}

animate();

[#84782] Tuesday, June 19, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
loganl

Total Points: 424
Total Questions: 86
Total Answers: 112

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
;