Introduction to OpenGL Transformations
70 likes | 273 Views
Introduction to OpenGL Transformations. How does OpenGL View the Scene?. Since viewing transformation is applied after modeling transformation, you should define viewing transformation first in the modelview matrix
Introduction to OpenGL Transformations
E N D
Presentation Transcript
How does OpenGL View the Scene? • Since viewing transformation is applied after modeling transformation, you should define viewing transformation first in the modelview matrix • Viewing transformation sets up the camera position and orientation and maps coordinates from the world coordinate system to the viewing coordinate system. • The camera is located at the origin of the viewing coordinate system and faces the –z direction.
Intuitive Camera Specification • How to specify a camera gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz). • (eyex, eyey, eyez): Coordinates of the camera (eye) location in the world coordinate system • (centerx, centery, centerz ): the look-at point, which should appear in the center of the camera image, specifies the viewing direction • (upx, upy, upz): an up-vector specifies the camera orientation by defining a world space vector that should be oriented upwards in the final image. • This intuitive specification allows us to specify an arbitrary camera path by changing only the eye point and leaving the look-at and up vectors untouched. • Or we could pan the camera from object to object by leaving the eye-point and up-vector fixed and changing only the look-at point.
Example • void display() { glClear(GL_COLOR_BUFFER); glColor3f(0.0f, 1.0f, 0.0f); glLoadIdentity(); gluLookAt(0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); … others transform … glBegin(GL_TRIANGLES); glVertex3f(2.0f, 0.0f, 0.0f); glVertex3f(0.0f, 2.0f, 0.0f); glVertex3f(0.0f, 0.0f, 2.0f); glEnd(); glFlush(); } Xiaoyu Zhang, CSUSM
Parallel (Orthographic) Projection • Set the viewing volume and matrix • glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(left, right, bottom, top, near, far); Xiaoyu Zhang, CSUSM