# [Bullet physics] converting quaternion,to dx quaternion

This topic is 1823 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm just trying to extract the rotation data out of the world matrix,like this:

D3DXQUATERNION tempq;
tempq.x = trans.getRotation().x();
tempq.y = trans.getRotation().y();
tempq.z = trans.getRotation().z();
tempq.w = trans.getRotation().w();


tempq is a directx quaternion,and trans is the bullet world matrix.

The problem is,I can't figure a way to convert the btscalar data from xyzw,to something else.

##### Share on other sites

I suppose there's a way to convert directly a LH quaternion to a RH one, personally I just go through the whole matrix flipping to incentivate my mental sanity. So far, no performance issues will arise in this part of the code.

##### Share on other sites

I'm not familiar with Bullet Physics, does the GetRotation() return the euler angles?

EDIT: I just learned that it returns a quaternion, sorry for the confusion, but hey, euler to quaternion conversions are still good to know...

EDIT: What up axis does bullet use?

If so, the conversion isn't too hard. [ http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm]

w = Math.sqrt(1.0 + C1 * C2 + C1*C3 - S1 * S2 * S3 + C2*C3) / 2
x = (C2 * S3 + C1 * S3 + S1 * S2 * C3) / (4.0 * w)
y = (S1 * C2 + S1 * C3 + C1 * S2 * S3) / (4.0 * w)
z = (-S1 * S3 + C1 * S2 * C3 + S2) /(4.0 * w)
where:

C2 = cos(attitude)
C3 = cos(bank)
S2 = sin(attitude)
S3 = sin(bank)


But I think you're in luck, as DirectX already has some alternative methods for you to use.

D3DXQUATERNION tempq;
auto vec = trans.getRotation(); // I'm not aware of the type
D3DXQuaternionRotationYawPitchRoll(&tempq, vec.x, vec.y, vec.z);

If I'm not wrong this does the job.

Hope this helps you.

-MIGI0027

Edited by Migi0027

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634111
• Total Posts
3015573
×