Jump to content

  • Log In with Google      Sign In   
  • Create Account


Lighting Problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 HyprLogik   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 July 2001 - 01:03 PM

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

Sponsor:

#2 mittens   Moderators   -  Reputation: 1315

Like
Likes
Like

Posted 09 July 2001 - 02:36 PM

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

#3 HyprLogik   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 July 2001 - 04:36 PM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS