Skip to main content
gamedev.net
🔒 Locked

Quaternions

Started by tiutiu 1 reply 550+ views
Original Post
tiutiu
tiutiu
I have a problem with matrices. I use quaternions to draw a sphere rotation about X-axis and following a line that rotates about Y-axis, like the railgun in quake But now i want the sphere not to follow the line, i thought using glLoadIdentity() before DrawSphere(), but if i do that, it doesnt draws the sphere. That''s the original code:
CQuaternion qRotationY;
qRotationY.CreateFromAxisAngle(0, 1, 0, rotation);
qRotationY.CreateMatrix(matrix);
glMultMatrixf(matrix);
DrawLine();
CQuaternion qSphereRotation;
gSphereRotation.CreateFromAxisAngle(1, 0, 0, rotation * 8);
qSphereRotation.CreateMatrix(matrix);
glMultMatrixf(matrix);
DrawSphere();
rotation++
 
It''s a tutorial from gametutorials.com. I hope you can understand and help me :D Thank you
Fruny
Fruny
First guess.


glPushMatrix();
CQuaternion qRotationY;
qRotationY.CreateFromAxisAngle(0, 1, 0, rotation);
qRotationY.CreateMatrix(matrix);
glMultMatrixf(matrix);
DrawLine();
glPopMatrix();
glPushMatrix();
CQuaternion qSphereRotation;
gSphereRotation.CreateFromAxisAngle(1, 0, 0, rotation * 8);
qSphereRotation.CreateMatrix(matrix);
glMultMatrixf(matrix);
DrawSphere();
glPopMatrix();
rotation++


glLoadIdentity() will reset your matrix to the identity matrix, thus drawing your sphere in (0, 0, 0)... you don't want that.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]


[edited by - Fruny on June 17, 2002 5:35:56 AM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
tiutiu
tiutiu
It works fine, that was what i wanted Thank you, but why if i use glLoadIdentity it DOESN''T draws anything? i think it should draw the sphere in (0,0,0). Well, thank you, now i have a better concept from matrices

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.