iPhone OpenGL-ES : Stopping the light source from moving
I been following a lighting guide and set up a lighting source for my spinning cube (spins by user interaction on 3 axis)
However, whatever I do, I can't keep the light source stay in the right position, it seems to rotate with the cube. So if I rotate the cube one part of is lit and one one part is not.
I am doing quite a bit of matrix manipulation. I tried resetting up the matrix and then applying the light source, I tried glLoadIdentity()
to reset the view.
I just can't seem to keep it still.
static const Vertex3D light0Position[] = {{0.0, 10.0, 10.0}};
glLightfv(GL_LIGHT0, GL_POSITION, (const GLfloat *)light0Position);
// Calculate light vector so it points at the object
static const Vertex3D objectPoint[开发者_开发知识库] = {{8.0, 8.0, -4.0}};
const Vertex3D lightVector = Vector3DMakeWithStartAndEndPoints(light0Position[0], objectPoint[0]);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, (GLfloat *)&lightVector);
The position and spotlight direction that you specify to OpenGL ES are transformed by the current modelview matrix at the time of the call to glLightfv, and are applied to a vertex after it has been transformed by the modelview matrix at the time of the call to glDrawArrays/glDrawElements. Neither takes into account the state of the projection matrix.
In order for us to understand how your transformations might be going wrong, you’ll need to show exactly when you apply your object/world/camera transformations to the modelview matrix, and where light property specification and drawing takes place relative to this.
精彩评论