#### Archived

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

# gluLookAt

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

## Recommended Posts

Is it me, or does gluLookAt also mess up your lighting??

##### Share on other sites
It''s just you, assuming you use it correct.

##### Share on other sites
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 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 on other sites

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

##### Share on other sites

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 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 on other sites
ah now THAT is what I didnt know. I figured opengl would leave the lights alone...

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002274
×