Advertisement

Rotating lighting

Started by April 04, 2005 03:46 AM
4 comments, last by traiger 19 years, 7 months ago
For some reason my light seems to rotate around my object as the object rotates does anyone have ideas why. Heres the draw source.

void cls_OBJECT::Draw(void)
{
	glLoadIdentity();									// Reset The Modelview Matrix
		
	glTranslatef(this->x, this->y, this->z);
	
	glRotatef(this->rx, 1.0, 0.0, 0.0);
	glRotatef(this->ry, 0.0, 1.0, 0.0);
	glRotatef(this->rz, 0.0, 0.0, 1.0);

	glBegin(GL_TRIANGLES);
	//draw the triangles
	for( int t_loop=0; t_loop<this->number_of_triangles; t_loop++)
	{
		glColorMaterial(GL_FRONT,GL_DIFFUSE);
		glMaterialfv(GL_FRONT,GL_DIFFUSE, this->triangle[t_loop].diffuse);
		glMaterialfv(GL_FRONT,GL_AMBIENT, this->triangle[t_loop].ambient);
		glMaterialfv(GL_FRONT,GL_SPECULAR, this->triangle[t_loop].specular);

		glNormal3fv(this->triangle[t_loop].norm);
		//one vertex at a time
		for( int v_loop=0; v_loop<3; v_loop++)
		{
			glVertex3f(this->triangle[t_loop].vertex[v_loop].x,
				this->triangle[t_loop].vertex[v_loop].y,
				this->triangle[t_loop].vertex[v_loop].z);
		}//end of vertex loop
		
	}//end of triangle llop
	glEnd();
	
}
well i don't what you want, but maybe this these links will help you.

http://nehe.gamedev.net/data/projects/project.asp?project=lights
http://www.morrowland.com/apron/tut_gl.php

or you could explane what you want or want the program should do ?
Live the life you lovelove the life you lead
Never be afraid of doing tasks you are not familiar with. Noah's Ark was built by an amateur. Professionals have built the Titanic.
You should never let your fears become the boundaries of your dreams.
Advertisement
code works fine for me :)
The full program loads and displays models from ms3d and flat shades them.

It works fine except when the object is rotating it looks like the light is following the object.

Did you try it with a rotating object genjix?

I'll check out those links gallit.

Thanks
If you have your light's positions etc in world space then you could try

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glLoadMatrixf( &yourViewMatrix );

before you do

vector4 pos;
glLight( light, GL_POSITION, &pos );

the light position is transformed by the current modelview matrix, perhaps the rotated model matrix is being left on the matrix stack from the previous frame's rendering.
Here is the program.

www.cls-productions.net\files\aarons pong.zip

You'll see that the light seems to rotate with the object.

I think you are probably right gooberius

This topic is closed to new replies.

Advertisement