Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

rileyriley

Gimbal lock sucks. Euler tricks or Quaternions?

This topic is 5998 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 trying to rotate a little thingy around in 3d space, using Euler angles, and of course run into gimbal lock. Now for about the last week I''ve been perusing articles about quaternions, and have a question for the forum - if I''m planning on writing a pretty large scale game with objects that need to be rotated around every axis you can think of, is it worth it to create a quaternion engine, or should I struggle through the hoops of making the Euler angles work correctly? Thanks for any feedback - - riley

Share this post


Link to post
Share on other sites
Advertisement
Quaternions are great - but have one major downfall: they''re completely impossible to visualise.

When the code works, using quaternions is a breeze, but when your trying to track down bugs it''s very difficult to get a feel for what''s happening.

Also, much of the documentation that I''ve downloaded tends to be either plain wrong or right-but-with-so-many-preconditions as to be less than useless.

Share this post


Link to post
Share on other sites
Yes, that is what I''m having the biggest problem with .. they seem to be ENTIRELY unintuitive.

Anyway, I''ve decided to take a shot at using them. I have all of the basic operations (multiplying, etc) worked into a neat little class - but I have no idea how to use the class! I don''t understand how to use quaternions to, say, rotate an object 40 degrees around the x axis and 50 around the y axis.

I have an idea that all I have to do is:

Quaternion q1(40, Vector(1, 0, 0));
Quaternion q2(50, Vector(0, 1, 0));
q1.normalize();
q2.normalize();

Quaternion q3 = q1*q2;
glRotated(q3.w, q3.v.x, q3.v.y, q3.v.z);

but that doesn''t seem to be working, and I have no idea if that''s because my Quaternion operations are wrong or because that is not, in fact, how you even use Quaternions at all. Does anyone know of any resources that give actual examples of using quaternions instead of just a lot of the same basic theory over and over again?

Thanks -
- riley

Share this post


Link to post
Share on other sites
i suggest you look at several sources to make sure that you''re using the right quaternion functions. i remember i had run into several different versions, and i had to spend a while flipping signs around to get it working. the closest "intuitive" feel you can get to quaternions is the axis-angle relationship. if you look at the conversion between quaternion and axis-angle representations, you''ll see that it is a straightforward trigonometric function. so, i haven''t tried this yet, but if you did an axis angle representation first, then perhaps the quaternion conversion will not be so hard.

a2k

Share this post


Link to post
Share on other sites
The way I tested my quaternion class was to implement rotation based on a vector (which it looks like you''ve done) then convert it back to a matrix. I then use multiply the current modelview matrix by the quaternion matrix. I could comment out that code and use my matrix class instead, as soon as both produced the same output, I knew I did it correctly.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
Alright, thanks for the suggestion. I''m at work now so I can''t test anything (arggghhagh) but I''ll do that as soon as I get home.

My only fear is that the two methods _won''t_ match up, and that I won''t have any idea what to change to get the quaternions working properly, you know what I mean? Right now I''m just blindly hacking away, calling multiplications and whatnot willy nilly without any real Idea of what''s going on. Does anyone know of any resources that really explain the entire process of representing a rotation and then _applying_ it, say with the vector/angle notation used by OpenGL?

Thanks -
- riley

Share this post


Link to post
Share on other sites
quote:
Original post by rileyriley
Quaternion q3 = q1*q2;
glRotated(q3.w, q3.v.x, q3.v.y, q3.v.z);

but that doesn''t seem to be working, and I have no idea if that''s because my Quaternion operations are wrong or because that is not, in fact, how you even use Quaternions at all.


I would say that''s the problem. q3.w is a value that is the cosine of half the rotation angle. OpenGL expects a rotation angle as degrees. So you''d first have to convert the cosine into the actual angle. Then double the result and convert it degrees. Sort of like this:

  
#define PI 3.1415926535897932384626433832795
double aRadians = acos (q3.w);
double aDegrees = aRadians * PI / 90.0f;


(If you''re wondering about the division by 90, it''s just a division by 180 and multiplying by 2, of course).

Share this post


Link to post
Share on other sites
You mean it doesn''t figure out what I''m trying to do and automatically convert from one arbitrarily defined measurement to another?! I''M SCREWED!

lol.. Thanks for your help. ;x

- riley

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!