Open GL rotation question!

Started by
2 comments, last by swiftcoder 15 years, 5 months ago
I have an OpenGL window with drawn coordinate sistem and lines. Lines are rotating around center point (0,0,0) with: glRotatef(xRotAng, 0, 1, 0) glRotatef(yRotAng, 1, 0, 0) and coordinate sistem is translated for: glTranslatef(0.0f, 2.0f, -10.0f) and it's rotating with lines... How can i make coordinate sistem to rotate with the same rotation as lines, only it must rotate around it's axis?! tnx for help
Advertisement
This is a question on order of operations. The last operation is "done" first.
So

glTranslatef(0.0f, 2.0f, -10.0f)
glRotatef(xRotAng, 0, 1, 0)
glRotatef(yRotAng, 1, 0, 0)

should work for you. It rotates around x axis, then y axis, then translate.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
I tried that and it doesn't work ... Coordinate system gets some weird rotation...

I also tried reseting the window with glLoadIdentity() and it still doesn't work...

Before and after drawing of any object i use glPushMatrix() and glPopMatrix()...

Should i use perhaps gluLookAt() function ?
Quote:Original post by u_r_b_a_n
Should i use perhaps gluLookAt() function?
gluLookAt won't help you much if you don't understand how transformations work - gluLookAt computes exactly the same translations and rotations internally. I would suggest that you pick up a book on geometrical transformation and matrices - Computer Graphics, Principles and Practice is a little dated, but the low-level stuff (including math) is very useful.

Along the same lines as V-man's point, it is often helpful to think about camera transformations as affecting the world, not the camera (you don't translate the camera by 5 units along the z-axis, instead you translate the world by -5 along the z-axis).

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement