How to get the Euler angles of a body from its MotionState?

Post Reply
cirosantilli
Posts: 1
Joined: Thu May 05, 2016 6:44 am
Contact:

How to get the Euler angles of a body from its MotionState?

Post by cirosantilli »

The official hello world https://github.com/bulletphysics/bullet ... d.cpp#L134 prints the x, y and z positions of a falling object, which are extracted via `body->getMotionState()->getWorldTransform(trans)`.

But how would I get the three Euler angles that represent the rotation?

I am able to get the quaternion that represents the rotation with `btTransform::getRotation()` http://bulletphysics.org/Bullet/BulletF ... 98507b7520 , but is there a convenient way to convert them to Euler angles?

I could re-implement the conversion formula as mentioned at Rotating Objects Using Quaternions http://www.gamasutra.com/view/feature/1 ... rnions.php , but I'd expect Bullet to have a built-in method for it.

I have seen http://stackoverflow.com/questions/2986 ... rigid-body but it does not use MotionState, which I've read is the preferred method (but I don't understand why yet).

Xpost at: http://stackoverflow.com/questions/3698 ... et-physics
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: How to get the Euler angles of a body from its MotionSta

Post by benelot »

Why exactly do you need Euler angles?The problem is that there is no exact definition for the rotations to be applied defined euler angles.

Read here:
http://www.bulletphysics.org/Bullet/php ... f=9&t=3404

So if you can, try to avoid euler angles. But if you need them, then you will have to implement the conversion by yourself. And you will have to deal with the problems they cause (gimbal lock being one of them, ask NASA, they have a nice story to tell) :)
Post Reply