I am making a program in which a pacman sphere and a bunch of smaller spheres move about on the x-y plane, and you look down the z-axis at them. I want to be able to move a light source by dragging the mouse. I can find the mouse position on the x-y plane just fine, and I can move the light along with it, but I’m having issues with the light’s z-coordinate. I’m also having problems with each of my objects being lit from the same direction, even though they are scattered about. I would like to keep the light at 0.0, and have it light all the objects that are moved down the z axis to a farther plane.
Here is psuedo-code to show how I’m currently trying it:
In init():
zoomOut = -20;
light_position = {0.0, 0.0, 0.0, 0.0};
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
In draw():
loadIdentity();
light_position[0] = glMouseX;
light_position[1] = glMouseY;
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glTranslatef(0.0, 0.0, zoomOut);
drawPacman();
drawSpheres();
for pacman and for each sphere, i do glPushMatrix(), transform on x and y, and draw the proper model, then glPopMatrix.
What currently happens is that everything is lit directly from side, as if the light is at the same depth that they are. Also, no matter where they are on the screen, when i draw the mouse around the center of the screen, everything is lit as if they were at the center of the screen.
Here is a link to the full source (not including the header)
Here is a link to the executable.
Controls:
Use the arrow keys to move Pacman around. Use the spacebar to turn on and off Pacman’s gravity.
Thanks in advance for help!