Camera Movement

The OpenGL camera is always positioned at the origin, looking down the -Z axis.

The camera itself never moves.



Looking at the final image produced, moving a camera is equivalent to moving the world in the opposite direction.

e.g. moving everything to the right is will produce the same image as moving the camera to the left.





To give the effect of moving the perspective viewpoint in OpenGL, use a transformation at the beginning of the frame, which affects all objects.

For example, to move the camera 10 units from the origin in the +Z direction, translate the world by -10 in Z:

def draw():
	glMatrixMode(GL_PROJECTION)
	glLoadIdentity()
	gluPerspective(fovy, 1, 0.1, 100)

	glMatrixMode(GL_MODELVIEW)
	glLoadIdentity()
	glTranslatef(0, 0, -10)

	drawObjects()



next