RmR
RmR

Reputation: 2303

Getting Global Rotation position of object in ThreeJS

Just like we have getWorldPosition(), is there a way we can get the absolute Rotation angle of an object. This will be relevant when the object is under another object; both of which could be rotated.

Thanks

Upvotes: 0

Views: 2103

Answers (1)

Garrett Johnson
Garrett Johnson

Reputation: 2534

You can use the matrixWorld property on objects and use the setFromRotationMatrix function on Euler to get the angles:

// make sure the matrix world is up to date
obj.updateMatrixWorld();

// extract the rotation matrix
const rotMat = new THREE.Matrix4();
obj.matrixWorld.extractRotation(rotMat);

// extract the rotation
const euler = new THREE.Euler();
euler.setFromRotationMatrix(rotMat);

There are equivalent function for quaternions

Hope that helps!

Upvotes: 3

Related Questions