View Full Version : How to rotate a normal?How to control the light better

04-25-2001, 06:34 AM
Dear Sirs

Im taking my first steps in using Opengl for various 3d visualizations,experimentally for the time. Problems often arise, so here i go with the questions.


You can specify a normal per vertex.
You can rotate,translate or scale a matrix.
I CAN rotate a normal using this code:
-In practice
The above code does not produce what i expect in a per vertex basis. If i use it once (not per vertex) it seems to be working with all the vertices.(Rendering is done in GL_POINTS)
Assuming that everything else is correct (I can be sure for that, im not THAT begginer)
Will the above code rotate the normal around y axis?


You can setup a spotlight with all these opengl commands.
You can rotate it,make it point elsewhere and turn it on and off.
I can setup the lights position to 5,5,5 and make it point to 0,0,0 by calling glLightfv with GL_POSITION and then specify a normal pointing to 0,0,0 (i apply it using glLightfv with GL_SPOT_DIRECTION).
To keep it steady i call glLoadIdentity everytime i set up my scene.
-In Practice
Everything works fine but when i use glLoadIdentity the position remains the same but the spotlights "character" changes.
If i dont use glLoadidentity the light is moving as the modelview matrix is rotated but the spotlights "character" is closer to what i have set (The cuttoff for example is sharper)

Can someone help me with all this?

Thanks in advance.

04-26-2001, 05:51 AM
why do you want to rotate the normal?
I assume that you are applying normals to the poly vertex's for lighting.....
rotate using rotatef (...)or matrixmult(...)
glNormal3f(x, y, z)
glVertex3f(i, j, k)

04-26-2001, 11:41 PM
First of all thanks for replying....

I have distinct directions of the normals so i decided to have one set, and rotate it to fit the direction i want....It think this can be done right?

How about lighting?
The model that Opengl uses confuses me a bit..
Is there a way to set the lights position and direction the same way i set the cameras position and direction? Something like gluLookat()....
I tryed this.....

GLfloat lightPos[]={-5.0,2.0,-3.0,1.0};
GLfloat lightDir[]={0.0,0.0,0.0,1.0};
GLfloat final[]={0.0,0.0,0.0,1.0};
int i;
float distance;

for (i=0;i<4;i++)


for (i=0;i<4;i++) final[i]/=distance;

When i want to place the light i use this:


Can the above code be used so i can set up the position of the light and the point it lights on?

Thanks in advance....to anybody wants to help.

04-29-2001, 07:50 AM
You have to think of OpenGL as a state machine. When you use glNormal* you are setting the current normal state that will get used for any future glVertex calls. It will only change by doing another glNormal* call. It might help to think of it as a global variable. If you don't change it, it will stay the same for the next vertex...

The glLight* calls for setting direction/orientation are affected by the current model-view matrix. So if you do something like..


You are going to get a differet result than using


In the first example, the light will be static. In the second example, the light will move with the objects.