Coordinate System



A coordinate system is needed for measuring objects' positions

It allows us to describe any location by a set of numbers - 2 numbers when working in 2 dimensions, 3 numbers for 3 dimensions.











A coordinate system has an origin (a reference point) and coordinate axes

In 2D we have an X axis and a Y axis. In 3D, we add a Z axis.

The axes are perpendicular - they are independent







OpenGL's default 2D coordinate system has the window cover the area from -1 to +1 in X and -1 to +1 in Y.
(0,0) is at the center of the window.




This can be changed with the function gluOrtho2D
e.g.:

	glMatrixMode(GL_PROJECTION)
	glLoadIdentity()
	gluOrtho2D(0.0, 10.0, 0.0, 5.0)






GLUT's reshape callback is a common place to use gluOrtho2D.
It's called whenever the window changes size.

e.g., to make the window always span -10 to +10 in X, and keep the aspect ratio 1:1,

def reshape(w, h):
	glViewport(0, 0, w, h)
	glMatrixMode(GL_PROJECTION)
	glLoadIdentity()
	gluOrtho2D(-10, 10, -10*h/w, 10*h/w)
	glMatrixMode(GL_MODELVIEW)



next