I'm implementing Bullet Physics into a D3D Engine I've been working on for a while. All my geo's nodes have a D3DXVECTOR3 position and rotation member. I'm getting the position like this:
btVector3 btPosition = trans.getOrigin();
cSTATIC_NODE::SetPosition((D3DXVECTOR3*)&btPosition);
works great.
now how do I do this:
btQuaternion btQuat = trans.getRotation();
cSTATIC_NODE::SetRotation((D3DXVECTOR3*)& ?????)
I'm not ready to convert my engine to quaternions yet, so any help with my meager math skills would be appreciated.
Hello world to D3D help
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Hello world to D3D help
Can you deal with a 3x3 rotation matrix? If so, please use trans.getBasis();
Cheers,
Erwin
Cheers,
Erwin
-
- Posts: 3
- Joined: Tue Dec 22, 2009 2:37 am
Re: Hello world to D3D help
Thanks!
Here's the code I implemented. I think it's working!
btScalar yaw;
btScalar pitch;
btScalar roll;
btMatrix3x3 btMatrix = trans.getBasis();
btMatrix.getEulerZYX(yaw, pitch, roll);
cSTATIC_NODE::SetRotation(&D3DXVECTOR3(pitch, yaw, roll));
Here's the code I implemented. I think it's working!
btScalar yaw;
btScalar pitch;
btScalar roll;
btMatrix3x3 btMatrix = trans.getBasis();
btMatrix.getEulerZYX(yaw, pitch, roll);
cSTATIC_NODE::SetRotation(&D3DXVECTOR3(pitch, yaw, roll));
-
- Posts: 1
- Joined: Wed Jan 06, 2010 8:15 pm
Re: Hello world to D3D help
I am using the suggested code snippet, however I seem to be rotating about the X axis instead of the y. My code to set the rotation was borrowed and modified from the Character Demo:
Where yaw, pitch, roll are rotations about the Y,X,Z axis respectively, and colBody is an already initialized btRigidBody.
Code: Select all
void SetRotation(float yaw, float pitch, float roll) {
btTransform xform;
this->colBody->getMotionState()->getWorldTransform(xform);
xform.setRotation(btQuaternion(yaw, pitch, roll));
this->colBody->getMotionState()->setWorldTransform(xform);
this->colBody->setCenterOfMassTransform(xform);
}