Hello, everyone. The rigidbodies can turn around on an axis of world coordinate when btRigidBody::applyTorque is called, now the rigidbodies are expected to turn around on an axis of local coordinate, so how can I realize it?
Thank you. Your suggestions will be greatly appreciated
Jet
Can Rigidbodies Turn Around on an Axis of Local Coordinate ?
-
- Posts: 21
- Joined: Tue Nov 03, 2009 8:33 am
-
- Posts: 21
- Joined: Tue Nov 03, 2009 8:33 am
Re: Can Rigidbodies Turn Around on an Axis of Local Coordinate ?
Anybody know that?I tried to realize it by using multithread, btRigidBody::applyTorque still cannot make the rigidbody turn around on an axis of local coordinate, while btRigidBody::applyCentralForce can move the rigidbody on an axis of local coordinate. My method is as following: I get the angle that the rigidbody rotated, and then make the axis(this is an axis of world coordinate ,such as x axis)which is the parameter of btRigidBody::applyTorque or btRigidBody::applyCentralForce rotate the same angle to reach the same direction as the local coordinate. Here are my codes:zjl19870808 wrote:Hello, everyone. The rigidbodies can turn around on an axis of world coordinate when btRigidBody::applyTorque is called, now the rigidbodies are expected to turn around on an axis of local coordinate, so how can I realize it?
Thank you. Your suggestions will be greatly appreciated
Jet
Code: Select all
void ConstraintDemo::driveControl()
{
btScalar rotatevalue[3];
btVector3 basicVec;
while (true)
{
basicVec = btVector3(0,0,100);
rotatevalue[0]=body1->getWorldTransform().getRotation().getX();
rotatevalue[1]=body1->getWorldTransform().getRotation().getY();
rotatevalue[2]=body1->getWorldTransform().getRotation().getZ();
for (int i=0; i<3; i++)
{
if (rotatevalue[i]>M_PI && rotatevalue[i]<M_PI*2)
{
rotatevalue[i] = M_PI - rotatevalue[i];
}
else if (rotatevalue[i]>-2*M_PI && rotatevalue[i]<=-M_PI)
{
rotatevalue[i] = M_PI*2 + rotatevalue[i];
}
else if (rotatevalue[i] >= 2*M_PI)
{
while(!(rotatevalue[i]<M_PI || rotatevalue[i]>-M_PI))
{
rotatevalue[i] -= M_PI*2;
}
}
else if (rotatevalue[i] <= -2*M_PI)
{
while(!(rotatevalue[i]<M_PI || rotatevalue[i]>-M_PI))
{
rotatevalue[i] += 2*M_PI;
}
}
else
{}
btAssert((rotatevalue[i]<=M_PI && rotatevalue[i]>=-M_PI));
}
basicVec = basicVec.rotate(btVector3(1,0,0),(btAsin(rotatevalue[0]))*2);
basicVec = basicVec.rotate(btVector3(0,1,0),(btAsin(rotatevalue[1]))*2);
TorqueVec = basicVec.rotate(btVector3(0,0,1),(btAsin(rotatevalue[2]))*2);
}
}
Only btRigidbody::applyCentralForce works well. Anybody can give me some suggestions? thank you very much.
Jet
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Can Rigidbodies Turn Around on an Axis of Local Coordinate ?
If you want to apply a local torque, you need to transform the local torque (or force) into world torque.
This can be done by pre-multiplying by the orientation (or post multiply by its inverse):
See also http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=2366
Thanks,
Erwin
This can be done by pre-multiplying by the orientation (or post multiply by its inverse):
Code: Select all
btVector3 worldTorque = body->getWorldTransform().getBasis() * localTorque;
or
btVector3 worldTorque = localTorque * body->getWorldTransform().getBasis().inverse();
See also http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=2366
Thanks,
Erwin
-
- Posts: 21
- Joined: Tue Nov 03, 2009 8:33 am
Re: Can Rigidbodies Turn Around on an Axis of Local Coordinate ?
Thank you very much! I have solved my problem perfectly.Erwin Coumans wrote:If you want to apply a local torque, you need to transform the local torque (or force) into world torque.
This can be done by pre-multiplying by the orientation (or post multiply by its inverse):
Code: Select all
btVector3 worldTorque = body->getWorldTransform().getBasis() * localTorque; or btVector3 worldTorque = localTorque * body->getWorldTransform().getBasis().inverse();
See also http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=2366
Thanks,
Erwin
Jet