float g_CameraPos[3];float g_CameraDir[3];float g_LightDirection[3]; // this is from sun to earthfloat g_LightDistance; // distance from sun to the ground.float g_LightLookAtOffset; // How far in front of the camera should the light focus. void CTerrain::StoreLightMatrix(void){ memset(modelViewMatrix, 0, sizeof(float) * 16); memset(modelProjectionMatrix, 0, sizeof(float) * 16); float pointInFrontOfCamera[3] = { g_CameraPos[0] + g_CameraDir[0] * g_LightLookAtOffset, g_CameraPos[1] + g_CameraDir[1] * g_LightLookAtOffset, g_CameraPos[2] + g_CameraDir[2] * g_LightLookAtOffset}; float lightPosition[3] = { pointInFrontOfCamera[0] - g_LightDirection[0] * g_LightDistance, pointInFrontOfCamera[1] - g_LightDirection[1] * g_LightDistance, pointInFrontOfCamera[2] - g_LightDirection[2] * g_LightDistance}; glPushMatrix(); glPushMatrix(); glLoadIdentity(); gluLookAt(lightPosition[0], lightPosition[1], lightPosition[2], pointInFrontOfCamera[0], pointInFrontOfCamera[1], pointInFrontOfCamera[2], 0.0, 1.0, 0.0); glGetFloatv(GL_MODELVIEW_MATRIX, modelViewMatrix); glPopMatrix(); glLoadIdentity(); gluPerspective(20.0f, 1.0f, 200.0f, 300.0f); glGetFloatv(GL_MODELVIEW_MATRIX, modelProjectionMatrix); glPopMatrix();}
Btw, this is what i tried to say in my first post, and i think is the same thing zedzeek suggested.
HellRaiZer