PDA

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

04-25-2001, 05: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.

1.Normals......

-Theory
You can specify a normal per vertex.
You can rotate,translate or scale a matrix.
-Conclusion
I CAN rotate a normal using this code:
glRotatef(RotAngle,0.0,1.0,0.0);
glNormal3f(0.0,0.0,1.0);
-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)
-Question.
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?

Spotlights!!!!!

-Theory
You can setup a spotlight with all these opengl commands.
You can rotate it,make it point elsewhere and turn it on and off.
-Conclusion
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?

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

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

Secondly.....
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?

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++)
final[i]=lightDir[i]-lightPos[i];

distance=sqrt(pow(final[0],2.0)+pow(final[1],2.0)+pow(final[2],2.0));

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

When i want to place the light i use this:

glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,final);

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.

Deiussum
04-29-2001, 06: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..