Lighting Problem

Started by
1 comment, last by HyprLogik 22 years, 9 months ago
Hi, I seem to be in quite a jam here.... I've generated terrain with a flashlight-type light in front of the viewer at all times. The problem is that when I rotate the scene, the light seems to rotate as well to keep up with the viewer, but it slowly fades out; then when I'm facing in back, it's completely out. Then when I continue to rotate, it comes back again. Since it's a directional spotlight, I tried to fix the direction by updating it every frame, but that doesn't work. Here's the drawScene() source:
      
int DrawGLScene( GLvoid )	//	all drawing is done here

{
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );	//	clear the screen and the depth buffer

	
	glLoadIdentity();
	glRotatef( yRot, 0.0f, 1.0f, 0.0f );	//	rotate on the Y axis

	glTranslatef( 0.0f, yMove, zMove );	//	move into the screen according to whether up or down key is being pressed

	
	GLfloat	LightDirection[] =	{
                          0.8f * (float)sin( yRot*PI/180 ),
                          -0.4f,
                          -0.8f * (float)cos( yRot*PI/180 )
                                        };	//	diffuse light direction

	
	
	glLightfv( GL_LIGHT2, GL_SPOT_DIRECTION, LightDirection );	//	direction of the light

	
	glBegin( GL_QUADS );	//	start drawing

		for( int j, i = 0; i < (TERRAIN_LENGTH - 1); i++ )	//	loop through all the grid points

			for( j = 0; j < (TERRAIN_WIDTH - 1); j++ )
			{
				glNormal3f( 0.0f, 0.0f, 1.0f ); 
				glTexCoord2f( 0.0f, 0.0f );	glVertex3f( (float)(j - TERRAIN_WIDTH/2), (float)(groundPoint[i][j] - 1), (float)(TERRAIN_LENGTH/2 - i) );
				glTexCoord2f( 0.0f, 1.0f );	glVertex3f( (float)(j - TERRAIN_WIDTH/2), (float)(groundPoint[i+1][j] - 1), (float)(TERRAIN_LENGTH/2 - 1 - i) );
				glTexCoord2f( 1.0f, 1.0f ); glVertex3f( (float)(j + 1 - TERRAIN_WIDTH/2), (float)(groundPoint[i+1][j+1] - 1), (float)(TERRAIN_LENGTH/2 - 1 - i) );
				glTexCoord2f( 1.0f, 0.0f );	glVertex3f( (float)(j + 1 - TERRAIN_WIDTH/2), (float)(groundPoint[i][j+1] - 1), (float)(TERRAIN_LENGTH/2 - i) );
			}
		
	glEnd();	//	done drawing the quad


	return TRUE;	//	everything is ok

}
      
Edited by - HyprLogik on July 9, 2001 8:16:38 PM Edited by - HyprLogik on July 9, 2001 8:19:08 PM
|-|A[k3R$Z R //|-|AT |V|Ak3 t|-|3 //0R|_D g0 R0|_|||D!!
Advertisement
You are assuming that every normal is (0.0f, 0.0f, 0.0f), to correctly get the normal, you have a little more math to do. I could give you the exact code to calculate a normal, but my newest code is on my dev comp (not this one), so do some searches for it!

------------------------------
Trent (ShiningKnight)
E-mail me
OpenGL Game Programming Tutorials
I figured it out, thanx
Damn, after weeks of thinking it out, too
Oh well, now on to my next problematic task, hehe.

Edited by - HyprLogik on July 9, 2001 11:40:16 PM
|-|A[k3R$Z R //|-|AT |V|Ak3 t|-|3 //0R|_D g0 R0|_|||D!!

This topic is closed to new replies.

Advertisement