I have rotation values (roll, pitch, yaw). I would like to apply that rotation to a body, but I have no idea how to do that.
Asked
Active
Viewed 1.1k times
3

Ciro Santilli OurBigBook.com
- 347,512
- 102
- 1,199
- 985

Ricardo Sanchez
- 4,935
- 11
- 56
- 86
-
@felipemaia - I'm using the Bullet Physics Engine for 3D rigid body collision detection, I'm not trying to manipulate ballistic trajectories, all I need is to rotate a body lets say a box with the provided rotation values – Ricardo Sanchez Nov 19 '11 at 19:45
-
2Yup. Agreed. Stupidy is indeed priceless. – felipemaia Nov 19 '11 at 20:01
1 Answers
4
The most straightforward way would be to directly set the world transform for a rigid body, either through a motion state or by direct setting. To get a transform from roll, pitch, and yaw, you could use:
btRigidBody * rigidBody = //...
btTransform tr;
tr.setIdentity();
btQuaternion quat;
quat.setEuler(yaw,pitch,roll); //or quat.setEulerZYX depending on the ordering you want
tr.setRotation(quat);
rigidBody->setCenterOfMassTransform(tr);

nonVirtualThunk
- 2,842
- 20
- 20
-
Is this transformation saved when the world is saved to a .bullet file by using btDefaultSerializer? – rraallvv Jan 21 '13 at 00:57
-
@rraallvv I would definitely expect the transforms for the rigid body would be serialized, so unless I'm missing something (which is possible, it's been a while since I worked with bullet), yes. – nonVirtualThunk Jan 23 '13 at 18:48