简体   繁体   中英

How to get Rotation around world axis Three js

I would like to get the rotation values form an Object3D according to world axises such as

roation.x, rotation.y, rotation.z

currently when I call

object.rotation.x 

I get the rotation value according to the objects local axises.

Thanks.

Sorry for the thread necro.

I had the same problematic, and couldn't find a solution until I read some ThreeJS doc about Euler angles . It became clear all of a sudden.

Three.js uses intrinsic (Tait-Bryan) ordering, also known as yaw, pitch and roll. This means that rotations are performed with respect to the local coordinate system. That is, for order 'XYZ', the rotation is first around world-X, then around local-Y (which may now be different from the world Y-axis), then local-Z (which may be different from the world Z-axis).

Some implementations may use extrinsic (proper) ordering, in which case rotations are performed with respect to the world coordinate system, so that for order 'XYZ', the rotations are around world-X, world-Y, and world-Z.

Converting between the two types is relatively straightforward, you just need to reverse the order and the rotation, so that an intrinsic (three.js) Euler rotation of angles a, b, c about XYZ will be equivalent to to an extrinsic Euler rotation of angles c, b, a about ZYX.

If you need to get the world rotations in XYZ order I suppose you can do the following :

var worldRot = new THREE.Euler();
obj.getWorldRotation().copy(worldRot);
worldRot.reorder("ZYX");
// use worldRot.x, worldRot.y, worldRot.z

To rotate an object in world axis, you can use below function

var rtWorldMatrix;
function rotateAroundWorldAxis(object, axis, radians)
{
    rtWorldMatrix= new THREE.Matrix4();
    rtWorldMatrix.makeRotationAxis(axis.normalize(), radians);
    rtWorldMatrix.multiplySelf(object.matrix);
    object.matrix = rtWorldMatrix;
    object.rotation.getRotationFromMatrix(object.matrix, object.scale);
}

And call rotateAroundWorldAxis(objectToRotate, new THREE.Vector3(1,0,0), 90 * Math.PI/180);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM