I have problem with my OpenGL game project. I have defined arrays with light properties:
GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 50.0 };
GLfloat light_position[] = { 3.0, 20.0, 3.0, 0.0 };
I use it with:
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
I have defined my Camera class and update method:
void update()
{
glLoadIdentity();
x = dist * sin(alpha) + 3;
z = dist * cos(alpha) + 3;
gluLookAt(x, y, z, 3, 5, 3, 0, 1, 0);
if (y <= 1) y = 1;
cout << "x " << x << "y: " << y << "z: " << z << "dist: " << dist << endl;
glutPostRedisplay();
}
Center point of my scene is (3,5,3). I want to rotate scene around this point and its working. But I have problem with lights - its also "rotating" - I dont know how to describe this.
I want simple lighting and camera rotating around point.
Fixed-Function GL stores the light position in eye space. To do this, the light position is multiplied by the current ModelView matrix at the time of the glLightfv(..., GL__POSITION, ...)
call. If you move your camera without re-specifying the light position, it has the effect of a light which remains stationary relative to the camera.
If you want a light which is stationary in the world, you have to load the view matrix (and just the view matrix) and specify the world space light position whenever the view matrix changes.