Advertisement

Quaternions

Started by September 10, 2002 11:19 AM
2 comments, last by shakazed 22 years, 3 months ago
Is there anyone out there that can give me a basic undersanding on how quaternions work. I´ve tried a myriad of places but they describe it using just math. I simply want to know how to make a rotation around an arbitrary axis (for my camera). PS I´m really stupid so I could use some "simple" help. [edited by - shakazed on September 10, 2002 12:20:06 PM] [edited by - shakazed on September 10, 2002 12:20:45 PM]
www.gametutorials.com has a sample opengl programming to show quartenions.

maybe you dont get it by reading, maybe an example of a running program would help.

the sample is just a ball rotating around a moving axis.

Advertisement
Lets try this, I didn''t know what a quaternion was a week ago, so I''m no expert.

First, lets define some vectors:
- p is the position of the camera.
- v is the position of the target that the camera is looking at.
- u is the position of the target that the camera should rotate toward.
- v'' = v - p; the offset vector of the target that the camera is looking at.
- u'' = u - p; the offset vector of the target that the camera should rotate toward.
- A = v'' x u''; the crossproduct of v'' and u'', the arbitrary axis to rotate around, should also be normalized.

Secondly, lets define the rotation:
- t is the rotation from v toward u.

Next, lets define some quaternions:
- qv = (x(v''), y(v''), z(v''), 1); the v'' vector as a quaternion.
- qt = (x(A)*sin(t/2), y(A)*sin(t/2), z(A)*sin(t/2), cos(t/2)); the quaternion for the rotation operation.
- qr = qt * qv * inverse(qt); the result of the rotation.

Finally, extract the new position from the resulting quaternion, qr.
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Thanks both of you. I think I have a basic understanding of them now. Really appreciated!

This topic is closed to new replies.

Advertisement