#1 Members - Reputation: 359
Posted 29 November 2012 - 05:40 AM
void RotateLeft(float timeElapsed)
{
btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[0];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->getMotionState())
{
btTransform worldTrans;
worldTrans = body->getCenterOfMassTransform();
// ***** Need the rest of the code to rotate the tank *****
}
}
#2 Members - Reputation: 359
Posted 29 November 2012 - 08:16 AM
btMatrix3x3 orn = m_pRigidBody->getWorldTransform().getBasis(); //get basis of world transformation orn *= btMatrix3x3(btQuaternion(axis, radians)); //Multiply it by rotation matrix m_pRigidBody->getWorldTransform().setBasis(orn); //set new rotation for the object
m_pRigidBody is an object of btRigidBody*. To represent rotation all you need is 3x3 matrix (4th row and column are to enable translation). So you get basis of world transform and then multiply it by rotation matrix( created with the help of quaternion, where the axis is axis of rotation and radians is angle in radians). After that all you have to do is to update basis of your world transform.
For more information about quaternions I would recommend visiting this link.
I hope it helps;)
Edited by DgekGD, 29 November 2012 - 08:18 AM.
#5 Members - Reputation: 359
Posted 29 November 2012 - 02:42 PM
Get current physics object transform:
XMMATRIX transform = btTransform_to_XMMATRIX(m_pRigidBody->getWorldTransform() ); //get basis of world transformation
Create rotation you need:
XMMATRIX rotation = XMMatrixRotationRollPitchYaw(angle, angle, angle);
//Get final transform
btTransform finalTransform = XMMATRIX_to_btTansform(transform * rotation);
Finally, apply your transform
m_pRigidBody->setWorldTransform(finalTransform);
Here, take a look at conversion methods:
static btTransform XMMATRIX_to_btTransform( XMMATRIX const & mat )
{
// convert from XMMATRIX to btTransform (Bullet Physics)
btMatrix3x3 bulletRotation;
btVector3 bulletPosition;
// copy rotation matrix
for ( int row=0; row<3; ++row )
for ( int column=0; column<3; ++column )
bulletRotation[row][column] = mat.m[column][row];
// copy position
for ( int column=0; column<3; ++column )
bulletPosition[column] = mat.m[3][column];
return btTransform( bulletRotation, bulletPosition );
}
static XMMATRIX btTransform_to_XMMATRIX( XMMATRIX const & trans )
{
XMMATRIX returnValue;
// convert from btTransform (BulletPhysics) to XMMATRIX
btMatrix3x3 const & bulletRotation = trans.getBasis();
btVector3 const & bulletPosition = trans.getOrigin();
// copy rotation matrix
for ( int row=0; row<3; ++row )
for ( int column=0; column<3; ++column )
returnValue.m[row][column] = bulletRotation[column][row];
// copy position
for ( int column=0; column<3; ++column )
returnValue.m[3][column] = bulletPosition[column];
return returnValue;
}
Take a note, that XMMATRIX is in row-major format and btTransform is column-major, that's why you swap column/row in these methods!
#6 Members - Reputation: 359
Posted 29 November 2012 - 02:48 PM
Here is what I'm looking for:
float pitch, yaw, roll; // Code to get pitch, yaw, roll from rigidbody here... yaw+=0.1; // Code to apply the new pitch, yaw, roll to the rigidbody here...
#7 Members - Reputation: 359
Posted 29 November 2012 - 03:02 PM
Anyway, to apply new pitch, yaw and roll to your body you have to create transformation matrix!
Using:
XMMatrixRotationRollPitchYaw(Pitch, Yaw, Roll); or
D3DXMatrixRotationYawPitchRoll(pResultMatrix, Yaw, Pitch, Roll) or maybe your own math library class.
Then you'll have to convert this class to btTransform(matrix class which Bullet Physics uses for computation);
That's how you would increment yaw:
yaw+= 0.1; XMMATRIX rotation = XMMatrixRotationRollPitchYaw(pitch, yaw, roll);
#8 Members - Reputation: 1673
Posted 29 November 2012 - 03:03 PM
xnamath is a library for directx, actually, not referring to the XNA framework for .NET.@DgekGD: I'm not using XNA, I'm using DirectX 9 and Bullet Physics.
Anyway, you can use D3DXMatrixRotationYawPitchRoll:
http://msdn.microsof...1(v=vs.85).aspx
Edit: DAH, too slow.
Edited by BCullis, 29 November 2012 - 03:04 PM.
#9 Members - Reputation: 359
Posted 29 November 2012 - 03:21 PM
So here is EXACTLY what I mean:
// Add code to get pitch, yaw, roll from btRigidBody
pitch+=0.1f;
yaw+=0.2f;
roll+=0.1f;
// Add code to apply the new pitch, yaw, roll to btRigidBody
If someone could update the two commented lines with the appropriate code, it will be exactly what I want.
Edited by Medo3337, 29 November 2012 - 03:22 PM.
#10 Members - Reputation: 359
Posted 29 November 2012 - 03:32 PM
Multiplying current transformation matrix with this one will exactly do what you want: Apply
pitch+=0.1f;
yaw+=0.2f;
roll+=0.1f;
to btRigidBody.
Edited by DgekGD, 29 November 2012 - 03:34 PM.
#11 Members - Reputation: 1673
Posted 29 November 2012 - 04:11 PM
btMatrix3x3::setEulerYPR ( const btScalar & yaw,
const btScalar & pitch,
const btScalar & roll
)
So I'm assuming you could use that to create a btMatrix3x3, and then apply that to a btTransform's origin that can be applied to the btRigidBody.
If someone could update the two commented lines with the appropriate code, it will be exactly what I want.
No one is here to just write your code for you. You're explicitly asking people to do that. Try and have a little courtesy, it's a forum for information sharing, not task orders.
Edited by BCullis, 29 November 2012 - 04:13 PM.
#12 Members - Reputation: 1229
Posted 29 November 2012 - 04:29 PM
Here its modified with setting yaw, pitch and roll:
btMatrix3x3 orn = m_pRigidBody->getWorldTransform().getBasis(); //get basis of world transformation
btMatrix ypr;
ypr.setEulerYPR(0.2f,0.1f,0.1f);
orn *= ypr //Multiply it by rotation matrix, yaw, pitch, roll
m_pRigidBody->getWorldTransform().setBasis(orn); //set new rotation for the object
Edit:
No one is here to just write your code for you
Oops
Edited by Olof Hedman, 29 November 2012 - 04:31 PM.






