hapticdata
hapticdata

Reputation: 1671

What is the correct way, using THREE.js methods to calculate the yaw of the camera?

How can I calculate a 2d (aerial-view) representation of an object's rotation (yaw) in my 3d scene using built-in THREE.js methods?

I have this working correctly using the solution from How to derive "standard" rotations from three.js when using quaternions? (same as http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/); but I would prefer to use built-in methods if available.

Upvotes: 0

Views: 2532

Answers (1)

WestLangley
WestLangley

Reputation: 104833

To orient the camera using natural yaw (heading), pitch, and roll, set:

camera.rotation.order = 'YXZ'. // the default is `XYZ`

Now you can set the cameras's orientation like so:

camera.rotation.set( pitch_radians, yaw_radians, roll_radians );

Consequently, camera.rotation.y would be the yaw (heading) in radians.

This method applies equally-well to any three.js Object3D.

For more information about an object's rotation in three.js see this answer.

three.js r.69

Upvotes: 4

Related Questions