Archived

This topic is now archived and is closed to further replies.

gluLookAt

This topic is 5176 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have set up a directional light, and when I move around, the surfaces that are lit change. That shouldnt happen since the light and the object are still in the same position...

Share this post


Link to post
Share on other sites
i guess there is something wrong with this

GLfloat LightPosition[]= { 0.0f, 1.0f, 1.0f, 0.0f }; // Light Position ( NEW )
glLightfv(GL_LIGHT0, GL_POSITION, LightPosition); // Position The Light

GLfloat LightAmbient[]= { 0.3f, 0.3f, 0.3f, 0.0f }; // Light Position ( NEW )
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);

glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);

I wanted a directional light coming under an 45 degree angle to get some nice shades, kindof like the angle of the sun... I know I forgot to set the diffuse lighting, but its white by default. I dont get my angle though, but a light that comes straight down. In addition I dont get ambient lighting either

Whats wrong?

Share this post


Link to post
Share on other sites
Try to add this

glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);

Share this post


Link to post
Share on other sites
Read up on the specular component of your lighting equation.

You''ll find the viewing angle DOES make a difference.

If you are lazy you can just set the light and materials specular components to 0.0 to get rid of it, but I suggest reading up on it. Read the opengl programming guide at least.

http://fly.cc.fer.hr/~unreal/theredbook/chapter06.html

bear in mind the defaults for GL_SPECULAR component of light and material are different (for LIGHT0 at least)

Share this post


Link to post
Share on other sites
When you set the light position, it will be transformed by the modelview matrix. So it matters whether you set it before or after setting the viewpoint transform (which is basicalyl what gluLookAt does). That means if you want the light to be fixed in the scene, you have to set it after you set the viewpoint transform. The same way any fixed objects in the scene are drawn after the viewpoint transform.

If you set it before the viewpoint transform is set, the light will appear to move with the viewpoint. Think of it like this. For the example, right is positive X, up us positive Y, and front is positive Z.

You have a viewpoint placed at the origin (at (0,0,0)), an object 1 unit infront of the viewpoint (at (0,0,1)), and a light 1 unit above the viewpoint (at (0,1,0)). Now you want to move the viewpoint x unit to the left (to (-x,0,0)). But as OpenGL have no concept of a moving viewpoint, only a fixed one, you have to move the scene 1 unit to the right instead (translate modelview matrix by (x,0,0)). So lets see what happens if we set the light before or after the viepwoint transform.

Before: Set light 1 unit above the viepwoint, the light is now located at (0,1,0). Transtale by (x,0,0) and draw object, which ends up at (x,0,1). The object to light vector is now (x,1,1)

After: Translate by (x,0,0) and place light, which ends up at (x,1,0). Draw object, which ends up at (x,0,1). Object to light vector is no (0,1,1). That means the light will shine on the object from the same direction independent of the viewpoints position.

You can see that setting the lights position after viewpoint transform makes the light follow the same transformations as the objects, and appearing to be fixed in the scene.

[edited by - Brother Bob on October 14, 2003 9:48:37 AM]

Share this post


Link to post
Share on other sites