Advertisement

Lighting problem (static) when moving Camera

Started by July 02, 2004 02:28 PM
3 comments, last by Luke Miklos 20 years, 5 months ago
I seem to be running into a problem with lighting and my camera system. I have modified Nehe's 7th tutorial slightly to accomodate for my free-flying camera. And it works!.... sort of. It seems that the normals are working, in a way, but they are behaving strangely. I have the light's position set up at 0,0,2 the camera set up at 0,0,5 and the box being drawn at 0,0,0. The anomoly seems to be that if you move the camera from looking at the bright "front" of the box to the left or right, the left/right sides are as bright as the front O.o It seems like when I'm using glMultMatrixf(), the light's position is not changed along with the rest of the scene. It appears that the light still remains 3 units in front of the camera, lighting up whatever side of the box is facing the cam. My code is as follows:



GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 0.0f };				 // Light Position ( NEW )

//***

	glMultMatrixf(cam.GetMatrix()->mat);

	glBegin(GL_QUADS);							// Start Drawing Quads

		// Front Face
		glNormal3f( 0.0f, 0.0f, 1.0f);					// Normal Pointing Towards Viewer
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Point 1 (Front)
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Point 2 (Front)
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Point 3 (Front)
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Point 4 (Front)
Is it the fault of the MultMatrix, or does it have something to do with my code/the properties of gl lights?
I do real things with imaginary numbers
The problem is that you have to load the identity, set the light's position, then translate the camera.
- fyhuang [ site ]
Advertisement
::smacks himself in the head::

Duh! Thanks :)
I do real things with imaginary numbers
order should be when rendering:


set projection matrix


load identity for modelview

set modelview camera position (glLoadMatrix, glRotate, glWhatnot)

set lights (setting a light is just like drawing a vertex, the position will be translated)

for each object:

glPushMatrix()

glMultMatrix or glRotate, etc

draw object...

{
if there is a child object attached
push,mult,draw,pop again
}

glPopMatrix()

repeat

swap :)

okey. :)

that should make sure the lighting is uniform over the entire scene.
riptorn,

That was a great explanation. I like it.

Has anybody voted on you for points yet? You should have some/more : )

you & darkwing, vincoof, & who else am I forgetting ???


Luke
Whatsoever you do, do it heartily as to the Lord, and not unto men.

This topic is closed to new replies.

Advertisement