Advertisement

Quaternions and stuff.

Started by October 30, 2003 03:50 PM
4 comments, last by DuncanBojangles 21 years, 4 months ago
Hey everyone, I''m not quite sure how to implement what I want to do. Just so we''re all on the same boat, I''m using the Quaternion class from the book "Physics for Game Developers". Let''s say, for instance, that I have a helicopter. I have three rotations, rot_x, rot_y, and rot_z, all representing the rotation around their respective axis. I want to take those rotations and move along the vector that they would create. To do this, I make a quaternion from the three angles, grab the vector portion of the quaternion, normalize it, then multiply it by the size I want it to be. Here''s the code: (heading is my heading vector, temp_heading is a temporary heading vector, position is a vector used to represent a point, and speed is the desired magnitude of the final vector.) temp_heading = MakeQFromEulerAngles(rot_x, rot_y, rot_z); heading = temp_heading.GetVector(); heading.Normalize(); heading *= speed; position += heading; If anyone sees anything wrong with this, please tell me. It almost works, but it''s not quite right. Thanks in advance! "Donkey, if it were me, you''d be dead." I cna ytpe 300 wrods pre mniute.
"Donkey, if it were me, you'd be dead."I cna ytpe 300 wrods pre mniute.
The advantage to using Quaternions is that they can properly handle changes in orientation in ways that the Euler angles can not do easily. If you''re just doing all your math with the Euler angles and then converting to the Quaternion at the very last step you''re not getting any of the advanteges of using the quaternions in the first place. (Direction vectors can easily be gotten with trigonometry.)

You didn''t really specify, but I''m going to assume that your problem is that it works great in a straight line, but rotations don''t happen the way you say think they would. (If that''s not it, then I don''t know, perhaps you could be more specific…)<br><br>Instead of seting the angle right before grabbing the vector each time, Why not do something more like this?<br><br>New_Heading_Q = Old_Heading_Q * ChangeInDirectionQ<br>heading_V = New_Heading_Q .GetVector() </b>
Advertisement
I tried the code you posted and I didn''t have much luck with it. To be clear, I''m rotating about the three axes on the local coordinate plane of the helicopter. These are rot_x, rot_y, and rot_z. Speed is the desired magnitude of the final vector. I''m using the following code, and it works just like I''d like it, but all the rotations seem to be acting half-ly. What I mean is, to rotate the final vector 180 degrees, the helicopter must rotate 360 degrees. I''m not sure exaclty what to do, ''cayse just multiplying the rotations by two gives unexpected results. Here''s the code.

headingQ = MakeQFromEulerAngles(rot_x, rot_y, rot_z);
headingV = headingQ.GetVector();
positionV += headingV * speed;

That''s what works the best so far. I should know, I spent about two months trying to do three axis rotation -> vector using basic trig and no matrices. Not easy.


"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.
"Donkey, if it were me, you'd be dead."I cna ytpe 300 wrods pre mniute.
Previously posted code does not work. Started playing with it more and the more I rotate the figure on multiple axes, the more erratic the transformations become. Should I use matrices for this problem? Can anyone give me a clear description of exactly what quaternions are and how they are used? I still have not found a straight definition. Will try matrices, will post later.

"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.
"Donkey, if it were me, you'd be dead."I cna ytpe 300 wrods pre mniute.
http://www.gametutorials.com/Tutorials/opengl/OpenGL_Pg4.htm

Read it and change it, break it and fix it. I myself don''t understand what quaternions are, but I do understand how they work. And also, make sure your quaternion is normalized.
First of all, I am fairly sure that to calculate new heading you should do:
New_Heading_Q = Direction_Change_Q * Old_Heading_Q
not
New_Heading_Q = Old_Heading_Q * Direction_Change_Q
as previous post described, the order of multiplcation matters.

Secondly, I think the fact that the rotation are getting more erratic could be that you are ignoring the orignal orientation since i don''t see any code taking that into account
Just because it is not nice, doesn''t mean it is not miraculous.

This topic is closed to new replies.

Advertisement