PDA

View Full Version : Working with GlTranslate and glRotatef



Rajesh
05-22-2002, 07:48 PM
Dear All,
I am beginner to Opengl.I am always confused with glRotatef and glTranslatef.Is their any specific way by which we assign translation and rotational coordinates to glTranslate and glRotatef before drawing.Whenever I am assiging coordinate it usually somewhere else.How to solve this problem

Thanks in advance
RAJESH.R

JeeTriX
05-23-2002, 01:18 AM
glRotatef and glTranslatef are moving your scene around, so if you want to move the camera, you should inverse your values.. f.e:

glTranslatef(0.0,0.0,5.0) moves the scene 5 along the Z-axis.

other example:
you wish to move your camera 7 units along the x axis:
glTranslatef(-7.0,0,0); (notice the negative value for a positive cameramovement)

you have to do the same with the values for rotatef: if you rotate the camera, take the negative value.

You have to be carefull with rotations tough. Rotating works ok for the first time, but if you start combining rotations, the sequence gets very important, if you don't understand what you're doing you'll probably mess it up with rotation-combinations.

f.e.:
glRotatef(70,1.0,0.0,0.0) rotates the camera -70 degr. around the x-axis

mikael_aronsson
05-23-2002, 02:55 AM
Hi !

Have a look at:
http://www.opengl.org/developers/faqs/technical.html#indx0080

Mikael

JeeTriX
05-23-2002, 04:08 AM
My god, tnx http://www.opengl.org/discussion_boards/ubb/wink.gif had not found that huge monstruous section yet

Jambolo
05-23-2002, 11:36 PM
If you think about it using these three rules you will not be confused:

1. glRotate rotates the coordinate system around an axis at the origin in the current coordinate system.
2. glTranslate translates the coordinate system.
3. Transformations are cumulative (except when push and pop are used).

So...

glTranslate before glRotate will translate the current coordinate system, then rotate around the axis at the translated origin.

glRotate before glTranslate will rotate the current coordinate system, then translate in the rotated coordinate system.

glRotate followed by glRotate will rotate the current coordinate system, then rotate the coordinate system again around an axis rotated by the first glRotate.

MickeyMouse
05-24-2002, 12:32 AM
if you don't want to learn linear algebra standing behind all that stuff, just note 2 things:

1st - as mentioned above if you want to transform your camera's position you should instead transform your world by negative transformations

2nd - transformations are applied in order from "drawing code" up to the first transformation function call (the first will be last and the last will be the first http://www.opengl.org/discussion_boards/ubb/smile.gif