Advertisement

Quaternions Again

Started by May 24, 2000 01:07 AM
10 comments, last by a2k 24 years, 6 months ago
i''m testing out Jeff Lander''s quaternion code, and i figured if it works in his demo, it should work in my code. it turns out that when i convert to matrices and rotate in my program, it does some totally funky stuff, like it "springs" back into place when stopping, or if you give it an extreme angle, (not necessarily at a 90 deg angle) it goes schizo, and finally uncontrollably unrecognizable. this is actually a continuation off a quaternions topic i had posted, and now i''m outta finals and all those projects, i''ve had time to get back to quaternions. the code goes something like this: quaternion qpitch quaternion qroll quaternion qyaw quaternion qtemp axisangletoquat(&pitchaxis, pitchangle, &qpitch) axisangletoquat(&yawaxis, yawangle, &qyaw) axisangletoquat(&rollaxis, rollangle, &qroll) multiplyquaternions(&qpitch, &qroll, &qtemp) multiplyquaternions(&qtemp, &qyaw, &qtemp) Matrix matrix quattomatrix(&qtemp, matrix) //the axes are also initialized to these values rollaxis = {0,0,-1} yawaxis = {0,1,0} pitchaxis = {1,0,0} rollaxis = rollaxis * matrix; yawaxis = yawaxis * matrix; pitchaxis = pitchaxis * matrix; help is gladly appreciated, and to those who know of my dilemma already, i''ve utilized the code, (except tc''s getpresentangles so far) just to get an object rotating on arbitrary axes. it works fine if i load in the world coord axes into the axisangletoquat function, but it gets screwed up when i put in an arbitrary axis generated from the matrices... a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
Check your mail

WickedMystic
Advertisement
WickedMystic: Is there any posibility that you could post the answer to this problem on the messageboard. Im sure others will benefit from the answer, me included.

Edited by - StereoMike on May 24, 2000 3:52:57 AM
-Sex on the television doesn't hurt... unless you fall off.
StereoMike,

There is another thread in this forum about Quaternions. Basically all the info you need to get your code working is in there. I just send a2k some source code of a little program I made when I was figuring out how to do it.

but here it goes anyway:

1.) define 3 vectors that represent the pitch, yaw and roll axi for the object you want to rotate. Initially these would for example be:

(0,0,-1) forward vector (or roll axis)
(0,1,0) top vector (or yaw axis)
(1,0,0) side vector (or pitch axis)

if you want to for example pitch the object, create a quaternion:
axis: pitch axis
angle: the amount of degrees/rads you want to pitch the object (this frame). (angle velocity, not absolute angle)

then create a rotation matrix from the quaternion.

rotate the yaw and roll axis by multiplying them with this matrix.

store the new vectors! in the next frame use these 'new' vectors to rotate around(not the original ones)

U should now be able to update the objects orientation every frame.

next problem: find the euler angles(or matrix) from the orientation vectors to rotate the mesh/object. TC posted some code in the other thread on how to do this.

then rotate the object/mesh by these euler angles and voila!!

If this still produces weird results then make sure that when rotating the object/mesh with the euler angles that you do this in the correct order. For TC's code it was I think:

glRotatef(euler.x, 1, 0 ,0);
glRotatef(euler.y, 0, 1, 0);
glRotatef(euler.z, 0, 0, 1);


I hope this helped, I am not really good at explaining this stuff

WickedMystic







Edited by - WickedMystic on May 24, 2000 4:56:11 AM
I''ve looked at the other thread about quaternions but i still had the same problem as a2k. I think i know the solution to the problem now though.

Thanks alot for taking your time.

-Sex on the television doesn't hurt... unless you fall off.
sorry about the anon post. It was just me.
-Sex on the television doesn't hurt... unless you fall off.
Advertisement
A2k,

Looking at your code, I couldn''t find anything wrong with it....

just one thing worries me:

multiplyquaternions(&qtemp, &qyaw, &qtemp)

you are multiplying qyaw with qtemp and putting it back into qtemp and since that functions takes pointers as parameters....i smell a bug, could be wrong tho...

since you didnt include the code for that function I can''t see if that''s the problem but I would try using:

multiplyquaternions(&qtemp, &qyaw, &qtemp2)

and see if that works.

WickedMystic



thanks, wicked mystic. i tried out your quaternion code, and it works. i think it''s merely matrix math problems with my code, so i may just have to multiply correctly. we''ll see...

a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
hey, wicked mystic, thanks for your help. i have a question: why is it that we have to use the code that TC had used for the opengl rotate functions? i mean, i KNOW that it doesn't work if you use the data supplied from the quaternion, and so the angles from the resultant direction vector have to be generated (TC's code), but why is this so? (i mean, why doesn't the code for "quattoeulerangles" from the quaternion faq work) i hope you understand my questioning... it's kinda funky.

a2k

oh, and another thing, your name's going in the credits. (not that my games gonna be big or anything, but you receive lots of credit)

Edited by - a2k on May 25, 2000 11:31:33 PM
------------------General Equation, this is Private Function reporting for duty, sir!a2k
The matrix from the faq and Jeff codes have some minor errors..

I have posted a Opengl quaternion article.. should appear in a few more days..

This topic is closed to new replies.

Advertisement