View Full Version : glRotatef???

badwhorsey

12-05-2003, 07:28 AM

Morning all,

I am doing a project for my graphics class and I am getting my butt kicked by the glRotatef function. I am trying to rotate a polygon 90 degrees towards the viewer. I understand that glRotatef takes 4 parameters; angle, x, y, z. How does this function use the angle? For a polygon should I be picking a point in the middle of it for my x, y, z coordinates? Is there a different command I can use that will just move the polygon in relation to where it is on the screen without coordinates? Any help/information would be most appreciated. Thanks.

Wes

ZbuffeR

12-05-2003, 07:40 AM

Read the man pages : http://pyopengl.sourceforge.net/documentation/manual/glRotate.3G.xml

glRotate takes an angle and a vector. Why ? Because you need to specify around WHAT you need to rotate.

glRotated( angle_z, 0.0, 0.0, 1.0 );

will rotate 'angle_z' degrees around the 'z' axis.

badwhorsey

12-05-2003, 07:51 AM

So does that mean I don't need the actual coordinates, do I just need to pick the axis to rotate on by setting it to 1?

Wes

badwhorsey

12-05-2003, 07:53 AM

http://pyopengl.sourceforge.net/documentation/manual/glRotate.3G.xml

That link doesn't work, I'll hunt around that site and see what I can come up with.

nexusone

12-05-2003, 08:01 AM

There are a few things about openGL and rotations and translations that you should know and maybe hard to grasp at first.

First all openGL operations start at 0,0,0 as the axis point.

glRotate( Angle of rotation(0-360), X, Y, Z) Where XYZ is what axis to rotate, 0 = No-rotation, 1 = rotation per Angle.

The rotation is done around 0,0,0 as the axis, so if your object is not draw with 0,0,0 being is center then it rotates with an offset.

Let's say you have a cube it has one corner as 0,0,0 and the far corner is 1,1,1. In order to rotate the cube around it's center we must move it's center to 0,0,0.

glRotate(angle, 1, 0, 0); // Rotate around X axis

glTranslate(-0.5, -0.5, -0.5); // Move cubes center from 0.5,0.5,0.5 to 0.0, 0.0, 0.0;

Draw_cube();

Now also remember openGL does operations work in reverse, so that the glTranslate is done frist even though we called it last.

So what happens is the cube has it center translated to 0,0,0, then we rotated around it's center.

Hope this helps.

Originally posted by badwhorsey:

So does that mean I don't need the actual coordinates, do I just need to pick the axis to rotate on by setting it to 1?

Wes

badwhorsey

12-05-2003, 08:08 AM

nexusone,

Thanks! That definately cleared a lot up for me.

Wes

karx01

07-06-2012, 12:29 PM

.

..

Draw_cube();

Now also remember openGL does operations work in reverse, so that the glTranslate is done frist even though we called it last.

So what happens is the cube has it center translated to 0,0,0, then we rotated around it's center.

Hope this helps.

Thanks !! bt i could not understand why reverse ??

could you please elaborate abi. I am new to openGL too. So far

aqnuep

07-06-2012, 01:47 PM

It's simple:

M = A * B * C * D

Where M is your modelview matrix, A, B, C and D are transformation matrices corresponding to the rotations/translations you make.

Now vertex position is calculated as follows:

p = M * v

From this, you can derive the following:

p = M * v = (A * B * C * D) * v = A * (B * (C * (D * v)))

Thus you can see that logically the last transformation matrix gets applied to your vertex first.

This is just simple linear algebra. You have to get familiar with it if you want to do graphics programming.

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.