1 / 31

Viewing and Projections

CS 535 CSUSM. Objective. Viewing Transformations in 3D GraphicsOpenGL functions to set up camera viewOrthographic and Perspective projectionProjective matricesOpenGL function for setting up projection. CS 535 CSUSM. Viewing Transformation . Another change of coordinate systemsMaps points from w

sydnee
Download Presentation

Viewing and Projections

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    1. CS 535 CSUSM Viewing and Projections

    2. CS 535 CSUSM Objective Viewing Transformations in 3D Graphics OpenGL functions to set up camera view Orthographic and Perspective projection Projective matrices OpenGL function for setting up projection

    3. CS 535 CSUSM Viewing Transformation Another change of coordinate systems Maps points from world space into eye space Viewing position is transformed to the origin Viewing direction is oriented along some axis A viewing volume is defined Combined with modeling transformation to form the modelview matrix in OpenGL

    4. CS 535 CSUSM Motivation In the scene shown, the world space is convenient for orienting the objects, for example floor, walls, and the chair. However, it is not convenient for describing the camera view. The goal of a viewing transformation is to specify a coordinate system that is the most convenient for the camera given the position and orientation of our camera in the scene.

    5. CS 535 CSUSM Camera View Camera coordinate system the camera is located at the origin. The camera’s optical axis is along one of the coordinate axes (-z in OpenGL convention) The up axis (y axis) is aligned with the camera's up direction we can greatly simplify the clipping and projection steps in this frame. The viewing transformation can be expressed using the rigid body transformations discussed before.

    6. CS 535 CSUSM Viewing Transformation Steps

    7. CS 535 CSUSM 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.

    8. CS 535 CSUSM Example void display() { glClear(GL_COLOR_BUFFER); glColor3f(0.0f, 1.0f, 0.0f); glLoadIdentity(); glLookAt(ex, ey, ez, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 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(); }

    9. CS 535 CSUSM The Matrix for glLookAt (u, v, w, eye) forms the viewing coordinate system. w = eye – look u = up × w v = w × u The matrix that transforms coordinates from world frame to viewing frame. dx = - eye · u dy = - eye · v dz = - eye · w

    10. CS 535 CSUSM Setup Camera Since viewing transformation is a rotation and translation transformation. We can use glRotatef() and glTranslatef() instead of glLookAt(). In the previous example (view a scene at origin from (10, 0, 0) ), we can equivalently use glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0, 0, -10); glRotatef(-90, 0, 1, 0); Since the viewing transformation is applied after modeling transformations, it should be set before modeling transformations.

    11. CS 535 CSUSM Set Viewing Transformation Furthermore, glTranslatef() and glRotatef() can be used to define custom viewing control. Example: Plane View -- display the world from the point of view of a plane pilot. Void PlaneView(GLfloat planex, GLfloat planey, GLfloat planez, GLfloat roll, GLfloat pitch, GLfloat yaw) { glRotatef(roll, 0, 0, 1); glRotatef(yaw, 0, 1, 0); glRotatef(pitch, 1, 0, 0); glTranslatef(-planex, -planey, -planez); … }

    12. CS 535 CSUSM Projection Transformations The projection transformation maps all of our 3-D coordinates onto our desired viewing plane. Greatly simplified by using the camera (viewing) frame. projection matrices do not transform points from our affine space back into the same space. Projection transformations are not affine and we should expect projection matrices to be less than full rank

    13. CS 535 CSUSM Orthographic Projection The simplest form of projection simply project all points along lines parallel to the z-axis (x, y, z)->(x, y, 0) Here is an example of an parallel projection of our scene. Notice that the parallel lines of the tiled floor remain parallel after orthographic projection

    14. CS 535 CSUSM Orthographic Projection The projection matrix for orthographic projection is simple: Notice the units of the transformed points are still the same as the model units. We need to further transform them to the screen space. OpenGL functions for orthographic projection gluOrtho2D(left, right, bottom, top), glOrtho(left, right, bottom, top, near, far)

    15. CS 535 CSUSM Mapping to Pixel Coordinates This process is often called the viewport transformation. OpenGL function glViewport(x, y, width, height) The variables, left, right, top, bottom, near and far in glOrtho(left, right, bottom, top, near, far) refer to the extents of the viewing frustum in modeling units. The values width and height are in unit of pixels. This transformation is little more than a scale and a translation.

    16. CS 535 CSUSM Perspective Projection Perspective projection is important for making images appear realistic. causes objects nearer to the viewer to appear larger than the same object would appear farther away Note how parallel lines in 3D space may appear to converge to a single point when viewed in perspective.

    17. CS 535 CSUSM Perspective projection Also called central projection All points on projection lines passing through the center (eye point) are projected to the same point on the image plane Not an affine transformation Projection transformation properties Angles are not preserved (not preserved under Affine Transformation). Distances are not preserved (not preserved under Affine Transformation). Ratios of distances are not preserved. Affine combinations are not preserved. Straight lines are mapped to straight lines.

    18. CS 535 CSUSM Perspective mapping in eye coordinate system Given a point S, we want to find its projection P. Similar triangles: P=(xn/z, n) In 3D, Have identified all points on a line through the origin with a point in the projection plane. If we have solids or colored lines, then we need to know ``which one is in front''. This map loses all z information, so it is inadequate.

    19. CS 535 CSUSM Why Map Z? 3D->2D projections map all z to same value. Need z to determine occlusion, so a 3D to 2D projective transformation doesn't work. Further, we want 3D lines to map to 3D lines (this is useful in hidden surface removal) The mapping maps lines to lines, but loses all depth information. We could use Thus, if we map the endpoints of a line segment, these end points will have the same relative depths after this mapping. BUT: It fails to map lines to lines

    20. CS 535 CSUSM Bad mapping In this figure, P,Q,R map to P',Q',R' under a pure projective projection. With the mapping                              P,Q,R actually map to             , which fail to lie on a straight line.

    21. CS 535 CSUSM Viewing Frustum and Clipping The right picture shows the view volume that is visible for a perspective projection window, called viewing frustum. It is determined by a near and far cutting planes and four other planes Anything outside of the frustum is not shown on the projected image, and doesn’t need to be rendered The process of remove invisible objects from rendering is called clipping

    22. CS 535 CSUSM OpenGL Perspective Projection Set viewing frustum and perspective projection matrix glFrustum(left,right,bottom,top,near,far) left and right are coordinates of left and right window boundaries in the near plane bottom and top are coordinates of bottom and top window boundaries in the near plane near and far are positive distances from the eye along the viewing ray to the near and far planes Projection actually maps the viewing frustum to a canonical cube the preserves depth information for visibility purpose.

    23. CS 535 CSUSM The OpenGL Perspective Matrix

    24. CS 535 CSUSM Projective space

    25. CS 535 CSUSM Verifications

    26. CS 535 CSUSM Mapping z The perspective transformation maps a line to a line P(f) = 1 and P(n) = -1. What maps to 0?

    27. CS 535 CSUSM Z mapping formula What happens as f and n move away from each other. Look at size of the regions [n,2fn/(f+n)] and [2fn/(f+n),f]. When f is much larger compared to n, we have                                                                              So                                                                             and                                                                             But both intervals are mapped to a region of size 1. Thus, as we move the clipping planes away from one another, the far interval is compressed more than the near one. With floating point arithmetic, this means we'll lose precision. In the extreme case, think about what happens as we move f to infinity: we compress an infinite region to a finite one.

    28. CS 535 CSUSM Near/Far and Depth Resolution It may seem sensible to specify a very near clipping plane and a very far clipping plane Sure to contain entire scene But, a bad idea: OpenGL only has a finite number of bits to store screen depth Too large a range reduces resolution in depth - wrong thing may be considered “in front” Always place the near plane as far from the viewer as possible, and the far plane as close as possible

    29. CS 535 CSUSM Perspective Projection (2) If the viewing frustum is symmetrical along the x and y axes. It can be set using gluPerspective(). gluPerspective(?,aspect,n,f) ?: the field of view angle aspect: the aspect ratio of the display window (width/height).

    30. CS 535 CSUSM Perspective Projection Suppose we have transformed from the viewing frustum from Eye coordinate space to Canonical viewing volume How do we project onto “image plane”? Simply ignore z coordinate. Then why do we map z coordinate? Hidden-surface removal!

    31. CS 535 CSUSM 3D Clipping We could clip to all 6 sides of the truncated viewing pyramid. But the plane equations are simpler if we clip after projection, because all sides of volume are parallel to coordinate plane. Clipping to a plane in 3D is identical to clipping to a line in 2D. We can also clip in homogenous coordinates.

    32. CS 535 CSUSM Summary Modeling transformations: transform objects into the world coordinate system Viewing transformations: change from world coordinate system to eye coordinate system Projection transformations: map eye centered viewing frustum to a canonical viewing volume (NDC)

More Related