I translate my object(soccer ball) -20z pixels away from the camera, keep the camera and rotating sphere(blue sphere=light, so you know where the light is) at origin, and rotate the light(represented by the sphere) around the origin to simulate moving light.
I think this short video(00:14) should clear things up:
*note: blue sphere=light, soccer ball=object, grey plane=flat ground
[media]
Why is my object acting as if it is at the origin, where the light is rotating around, but in reality it is -20z further away from the origin?
main function:
void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//lighting+sphere
rot+=1.0f;
glPushMatrix();
//glTranslatef(0.0f, 0.0f, -20.0f);
glRotatef(rot,0.0f,1.0f,0.0);
glTranslatef(0.0f, 0.0f, 10.0f);
initSceneLighting();//set position light[0] {0,0,0,1}
drawSceneSphereLight();//blue sphere
glPopMatrix();
//soccer ball(object)
glPushMatrix();
glTranslatef(0.0f, 0.0f, -20.0f);
glColor3f(1.0f,0.0f,0.0f);
glCallList(soccerBall);
glPopMatrix();
//floor
glPushMatrix();
glColor3f(0.5f,0.5f,0.4f);
drawSceneFloor();//grey ground
glPopMatrix();
?
glutSwapBuffers();
}