180 likes | 435 Views
OpenGL Viewing Pipeline. Object coordinates. Modelview matrix. Eye coordinates. Projection matrix. Clip coordinates. Perspective division. Normalized device coordinates. Viewport transformation. Window coordinates. Object coordinates. Modeling matrix. Modelview Matrix.
E N D
OpenGL Viewing Pipeline Object coordinates Modelview matrix Eye coordinates Projection matrix Clip coordinates Perspective division Normalized device coordinates Viewport transformation Window coordinates
Object coordinates Modeling matrix Modelview Matrix World coordinates Viewing matrix Eye coordinates
Viewing Transformation void gluLookAt( GLdouble x0, GLdouble y0, GLdouble z0, GLdouble x, GLdouble y, GLdouble z, GLdouble vx, GLdouble vy, GLdouble vz ) (x0, y0, z0): View Reference Point P0=(x0, y0, z0) (x, y, z): Look-at Point P=(x, y, z) (vx, vy, vz): View-up Vector V=(vx, vy, vz) y yv xv V zv P0 P x z
Projection Transformations Orthographic Projection For orthographic projection, OpenGL assumes the view plane is placed at the near clipping plane. (xmax, ymax) View Volume yv Far Plane z = zf xv Near Plane z = zn (xmin, ymin) zv
void glOrtho( GLdouble xmin, GLdouble xmax, GLdouble ymin,GLdouble ymax, GLdouble zn, GLdouble zf ) Transformation matrix for orthographic projection:
Perspective Projection For perspective projection, OpenGL assumes the view plane is placed at the near clipping plane, and the projection reference point is at the eye coordinates origin. View Frustum (xmax, ymax) yv Far Plane z = zf xv Near Plane z = zn (xmin, ymin) zv
void glFrustum( GLdouble xmin, GLdouble xmax, GLdouble ymin,GLdouble ymax, GLdouble zn, GLdouble zf ) Transformation matrix for perspective projection:
Symmetric Perspective Projection View Frustum yv w h Far Plane z = zf xv Near Plane z = zn zv Field of View (FOV) angle Aspect ratio r = w / h
void gluPerspective(GLdouble , GLdouble r, GLdouble zn, GLdouble zf ) Transformation matrix for symmetric perspective projection:
Viewport Transformation Program Window and Window Coordinates (Device Coordinates) yd Program Window Title Bar Menu Bar Tool Bar Client Area Border xd Status Bar
Mapping View Volume to Viewport Orthographic Projection View Volume yv xv zv Viewport
Perspective Projection View Frustum yv xv zv Viewport
void glViewport(GLint x, GLint y, GLint width, GLint height) (x, y): Lower left corner of the Viewport in Window coordinates. width: Width of the Viewport, in pixels. height: Height of the Viewport, in pixels. yd Viewport height y xd x width
Setting up 2D Viewing in OpenGL yv yd ymax Viewport Clipping Window ymin xmin xmax xv xd Viewing (Eye) Coordinates Device (Window) Coordinates void gluOrtho2D( GLdouble xmin, GLdouble xmax, GLdouble ymin, GLdouble ymax) Sets up projection matrix for 2D viewing. This is equivalent to glOrtho(xmin, xmax, ymin, ymax, -1.0, 1.0)
Walking in a 3D Scene First Person Camera System U0 P: Camera Position F0: Initial Forward Direction U0: Initial Up Direction R0: Initial Right Direction F: Forward Direction U: Up Direction R: Right Direction U F R0 F0 R P
U0 F0 T F T R0 F0 R0 R P R 0 360 90 90 Move forward: PP+aT Move backward: PPaT Move up: PP+aU0 Move down: PPaU0 Move left: PPaR Move right: PP+aR Turn left: Turn right: + Look up: + Look down: