120 likes | 266 Vues
This guide explores the transformation functions in OpenGL, covering three main matrix stacks: ModelView, Projection, and Texture. Learn to manipulate matrices with commands like glLoadIdentity, glTranslate, glRotate, and glScale to create hierarchical structures. Discover how to set up your viewing transformation using gluLookAt for camera positioning and various projection methods such as perspective and orthographic projections. We'll also delve into viewport transformations, ensuring a comprehensive understanding of how to manage 3D scenes in OpenGL.
E N D
OpenGL Transformation Jian-Liang Lin 2002
Transformation -2 • There are three matrix stacks in OpenGL architecture • MODELVIEW, PROJECTION, TEXTURE • glMatrixMode( GLenum mode ); • mode: GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE • Current matrix mode is also a OpenGL state variable.
Transformation -3 • Matrix Manipulation • glLoadIdentity(); • glLoadMatrix{f,d}( const TYPE* m ); • glMultMatrix{f,d}( const TYPE* m ); • glPushMatrix(); • glPopMatrix(); • Stack operation of matrix is very useful for constructing a hierarchical structures. • Ex: Render a car with four wheels.
Transformation -4 • OpenGL built-in transformation: • glTranslate{f,d}( TYPE x, TYPE, y, TYPE z ); • Multiply a translation matrix into current matrix stack • glRotate{f,d}( TYPE angle, TYPE x, TYPE y, TYPE z ); • Multiply a rotation matrix about an arbitrary axis into current matrix stack • glScale{f,d}( TYPE x, TYPE y, TYPE z ); • Multiply a scaling matrix into current matrix stack
Transformation -5 • Viewing transformation • Choose your viewing system • Center-orientation-up system • Apply gluLookAt Utility routine. • gluLookAt( cx, cy, cz, cx+ox, cy+oy, cz+oz, upx, upy, upz ); • ( cx, cy, cz ) is the center of the camera • ( ox, oy, oz ) is the orientation vector of the camera • ( upx, upy, upz ) is the up vector of the camera • Polar coordinate system • Combine translation and two rotation. • …
Transformation -6 • Projection transformation: Perspective projection • glFrustum( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far );
Transformation -7 • gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far );
Transformation -8 • Projection transformation: Orthogonal projection • glOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far ); • gluOrtho2D( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top ); • A helper to create a 2D projection matrix
Transformation -9 • Viewport transformation • glViewport( GLint x, GLint y, GLsizei w, GLsizei h ); • Initial viewport is as the same size as the window
Transformation -10 • Note: • By default, the viewpoint as well as objects in the scene are originally situated at the origin, and is looking down the negative z-axis, and has the positive y-axis as straight up.