Click here to Skip to main content
15,947,389 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm modelling a ship in 3D in wpf. I have functions to change pitch, heading and roll, (model's x,y,z), by degrees. These use individual transforms, such as:

RotateTransform.Rotation = new AxisAngleRotation3D(new Vector3D(1, 0, 0), pitchangle);

Its obvious when I apply for instance a heading/y transform then a roll/z transform the rotation axis isn't right as it's rotating round the 3D space's z axis not the models (now changed) z axis.

How do keep track of the correct rotation axis for the model?
Posted

1 solution

Use quaternions instead. You'll run into all sorts of weird behaviour, including gimbal lock[^] when using Euler angles.

http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation[^]

http://www.gamedev.net/page/resources/_/technical/math-and-physics/quaternion-powers-r1095[^]


It might seem like a big step to move to Quaternions, but trust me, it will pay off.

Hope this helps,
Fredrik
 
Share this answer
 
Comments
brian_bloke 17-Feb-12 10:08am    
Thank you - at the brief look I had at quaternions I was hoping to avoid them! Will read on...
Fredrik Bornander 17-Feb-12 10:33am    
I had the same feeling the first time I looked at them, but they really do make everything a lot easier as soon as you get past the initial hurdle of understanding them.
brian_bloke 21-Feb-12 5:29am    
ok I get the basics of what quaternions are - I still don't see how to apply them to my situation? After applying one I'd still need to know the new rotation axis for the next rotation? Or have I missed something?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900