Advertisement Jump to content
Sign in to follow this  

[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.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

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 this post

Link to post
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 this post

Link to post
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... smile.png 

EDIT: What up axis does bullet use?


If so, the conversion isn't too hard. []

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) 

C1 = cos(heading)
C2 = cos(attitude)
C3 = cos(bank)
S1 = sin(heading)
S2 = sin(attitude)
S3 = sin(bank)

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

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. wink.png


Hope this helps you.


Edited by Migi0027

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!