Advertisement

Updating RigidBody Pitch Yaw Roll in Bullet Physics

Started by October 27, 2012 04:27 PM
5 comments, last by Medo Mex 12 years, 3 months ago
I am using the following to update RigidBody translation:
body->activate(true);
btTransform trans;
body->getMotionState()->getWorldTransform(trans);
body->translate(btVector3(newX - trans.getOrigin().getX(), newY - trans.getOrigin().getY(), newZ - trans.getOrigin().getZ()));


I want to update the rotation as well, I have Pitch, Yaw, Roll values, how do I update the rotation in Bullet Physics?

I tried to use the following, but it doesn't work:
body->activate(true);
btTransform trans;
body->getMotionState()->getWorldTransform(trans);
btQuaternion quat;
quat.setEuler(x, y, z);
trans.setRotation(quat);
body->setCenterOfMassTransform(trans);


I am also looking for a way to update Pitch, Yaw, Roll when Bullet Physics change it, something similar to the following (but for rotation):

// The following works for translation
model->X = float(trans.getOrigin().getX());
model->Y = float(trans.getOrigin().getY());
model->Z = float(trans.getOrigin().getZ());

I am using the following to update RigidBody translation:
body->activate(true);
btTransform trans;
body->getMotionState()->getWorldTransform(trans);
body->translate(btVector3(newX - trans.getOrigin().getX(), newY - trans.getOrigin().getY(), newZ - trans.getOrigin().getZ()));


I want to update the rotation as well, I have Pitch, Yaw, Roll values, how do I update the rotation in Bullet Physics?


I think you would apply the translation and rotation to your trans object and then pass it back to body through the setCenterOfMassTransform function.

-Josh

--www.physicaluncertainty.com
--linkedin
--irc.freenode.net#gdnet

Advertisement
Hi jjd,

I have updated my initial post, please check it now.

I am looking for a code sample to set rotation and get rotation (Pitch, Yaw, Roll) of a RigidBody in Bullet Physics.

I found out how to get the rotation from Bullet Physics, I used the following:
btQuaternion quat = trans.getRotation();
D3DXQUATERNION *dxQuat = new D3DXQUATERNION(quat.getX(), quat.getY(), quat.getZ(), quat.getW());
D3DXVECTOR3 rotVector3 = QuaternionToEuler(*dxQuat);
model[j]->rotationX = rotVector3.x;
model[j]->rotationX = rotVector3.y;
model[j]->rotationX = rotVector3.z;


Now, How can I change the rotation if I only have the values Pitch, Yaw, Roll?

The following doesn't work as expected:
body->activate(true);
btTransform tr;
body->getMotionState()->getWorldTransform(tr);
btQuaternion quat;
quat.setEuler(yaw, pitch, roll);
tr.setRotation(quat);
body->setCenterOfMassTransform(tr);



model[j]->rotationX = rotVector3.x;
model[j]->rotationX = rotVector3.y;
model[j]->rotationX = rotVector3.z;



You have an error here -- you're only setting the X component.

-Josh

--www.physicaluncertainty.com
--linkedin
--irc.freenode.net#gdnet


The following doesn't work as expected:
body->activate(true);
btTransform tr;
body->getMotionState()->getWorldTransform(tr);
btQuaternion quat;
quat.setEuler(yaw, pitch, roll);
tr.setRotation(quat);
body->setCenterOfMassTransform(tr);





It isn't? What numbers are you putting in and what numbers are you getting out?

-Josh

--www.physicaluncertainty.com
--linkedin
--irc.freenode.net#gdnet

Advertisement
I am just trying to increase any of the values (pitch, yaw, roll), but I see the mesh rotate weirdly when I use the above code.

This topic is closed to new replies.

Advertisement