1 / 61

Viewing and Projection

Viewing and Projection. Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com). Viewing. To render a scene, need to know “Where am I” and “What am I looking at” The view transform does this Maps a standard “view space” into world space

renate
Télécharger la présentation

Viewing and Projection

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. Viewing and Projection Jim Van Verth (jim@essentialmath.com) Lars M. Bishop (lars@essentialmath.com)

  2. Viewing • To render a scene, need to know “Where am I” and “What am I looking at” • The view transform does this • Maps a standard “view space” into world space • Defined by a point (location), and two vectors (direction and up) Essential Math for Games

  3. y View Space z x • “Locked” to the camera • Origin is view position (focal point) • The position and orientation of this space in world space tells us • Where the camera is located • What it is looking at Essential Math for Games

  4. View Space • x- and y-axes intuitive for screen coordinates • Z-axis is the view direction (depth) • Can be right- or left-handed: • Left-handed can be intuitive; z = depth • OpenGL uses right-handed; −z = depth • We’ll explain the right-handed case Essential Math for Games

  5. View Space Transform • A transform that can map World Space → View Space • Often written as V • Easier to discuss V-1 first • V-1 maps view → world • “Pick up a camera and aim” Essential Math for Games

  6. Components of V-1 • V-1 is built from simple transforms • View Translation • Where is the camera? • View Orientation • What direction is the camera facing? Essential Math for Games

  7. Components of V • V is built from the inverse transforms • View Translation • Move the world to the camera • View Orientation • Turn world to face the camera Essential Math for Games

  8. Creating View Transform • Have viewer position e, world up direction u, point we want to look at o • Want to compute view transform u e o Essential Math for Games

  9. View Translation • Translate the view center e to the origin E = Essential Math for Games

  10. y View Orientation z x • View orientation consists of three view vectors (we defined these earlier): World space view space • View-direction vector −z-axis • View-right vector x-axis • View-up vector y-axis view z x Essential Math for Games y

  11. Computing View Orientation • First compute view direction vector • Take cross product with up vector to get right vector • Cross with direction to get view up Essential Math for Games

  12. Computing View Orientation • Normalize these three vectors • We have three unit-length, orthogonal vectors – basis vectors! • Copy to columns of matrix RVW – transforms from view orientation to world orientation Essential Math for Games

  13. Verifying RVW World Space = Transform x View Space Essential Math for Games

  14. Finishing View Orientation • RVW maps view-to-world – we need world-to-view • Just invert RVW. Since RVW is a rotation (orthogonal), we know: Essential Math for Games DEMO

  15. Other View Orientation Methods • View Orientation is just a rotation • Either use look-at orientation (prev seq) • OR other rotation matrix • OR convert orientation from other format (e.g. Quaternions) Essential Math for Games

  16. y Final V z x • Viewing transformation V: • View translation matrix E • View orientation matrix RWV • V = RWVE • Maps world space to view space • No right-to-left handed swap needed, as depth maps to −Z Essential Math for Games

  17. Mbv= V Mbw • Mbvcan be used to transform the vertices of the body of object from model space to view space Essential Math for Games

  18. Mav= V Mbw Mab • Just like the body, but with one additional concatenation • The final matrix, Mav,can be used to transform the vertices of the arm of object from model space to view space Essential Math for Games

  19. Prefabricated Look At • gluLookAt() is equivalent to concatenating V = RWV E • Most of the time, can pretty much just use that • But it is important to know how it works! • Complex camera interactions require an understanding of the view transform Essential Math for Games

  20. Projection • How we represent our camera’s “lens” • Maps a subset of the scene onto screen • Generally, destination is a rectangular window • Sometimes truly a GUI window • Sometimes the full screen • Sometimes a texture Essential Math for Games

  21. y NDC Space x • Normalized Device Coordinates • The space of our “window” • Lies in a plane • Resolution independent • Unit square (-1,-1) -> (1, 1) • Origin at (0,0) • “Visible” objects transformed into NDC space Essential Math for Games

  22. Projection • Must project (flatten) 3D view of camera to a plane — called projective transformation • NDC space defines visible area of projection plane • Two kinds • Parallel - linear • Perspective - non-linear (there’s a divide) Essential Math for Games

  23. Parallel Projection • “Flatten” in a constant direction • Infinitely distant center of projection 3d object projection plane / NDC space view position Essential Math for Games

  24. Parallel Projection • Parallel lines remain parallel • Orthographic most commonly used – projection perpendicular to plane • Not how we see the world • Mainly useful for art tools and special effects Essential Math for Games

  25. Perspective Projection • Lines converge to single center of projection 3d object projection plane / NDC space view position Essential Math for Games

  26. Perspective Projection • Gives view we’re used to • Parallel lines in view direction merge • Distances appear to shrink • Non-linear Essential Math for Games

  27. The View Frustum • We need to know what part of view space to render. A “window” into the world! y window view position x z Essential Math for Games

  28. The View Frustum • Size of window and closeness to eye determine field of view fov angle y window x z Essential Math for Games

  29. The View Frustum • Also defines how far objects are visible and how near objects are visible The View Frustum y Far plane Near plane window view position x z Essential Math for Games DEMO

  30. Field of View • Related to location of projection plane y-axis (VUP) 1 -z-axis (VDIR) /2 View position View space origin d Projection plane Essential Math for Games

  31. The Perspective Projection • Want to project a view-space point yv , zv y-axis (VUP) View position -z-axis (VDIR) View space origin Essential Math for Games

  32. The Perspective Projection Projection plane y-axis yv -z-axis View position View space origin -zv Essential Math for Games

  33. The Perspective Projection • Similar triangles gives us Projection plane y-axis yv Yndc -z-axis View position View space origin d -zv Essential Math for Games

  34. The Perspective Projection Solving for yndc Essential Math for Games

  35. Aspect Ratio • One thing we haven’t considered • Screen may not be square • Need to adjust area covered by projection plane by aspect ratio • Assume y height remains 1, adjust x Essential Math for Games

  36. The Perspective Projection • Our projection equations • It’s a non-linear transformation Essential Math for Games

  37. Homogeneous Perspective • Transformation has linear and non-linear parts • Linear part are the scales • Non-linear part is the division • Put linear part in homogeneous transformation matrix • Dividing out the w can get us the perspective division Essential Math for Games

  38. Perspective matrix • The homogeneous perspective matrix • Note that w is no longer 1 • Perspective matrix non-invertible • (right column all zeroes) Essential Math for Games

  39. Perspective In Action • Multiply linear part • Divide out the w Essential Math for Games

  40. What happens to Z? • Conceptually, it’s lost in the projection • In practice, we keep it for sorting chores • Map near plane to -1 and far plane to 1; the tighter they are, the better z-precision Pv y-axis View position View space origin Near plane: -zs= -1 Far plane : -zs= 1 -z-axis Essential Math for Games

  41. Projecting The Z • Projection equation for z where n = near plane, f = far plane (distance from eye) • Maps near to -1, far to 1 Essential Math for Games

  42. Final Projection Matrix • This projection matrix has all this built in Essential Math for Games

  43. The Perspective Projection • Current equations map from view space (xv, yv,zv) to the projection plane • If (xndcyndc) falls within unit square, we’re in NDC space and visible • Need to keep going into screen space Essential Math for Games

  44. Screen Space • Aspect ratio is not usually 1:1 (e.g.4:3) • Screen space y axis is flipped • Origin at upper left corner x ws hs y Essential Math for Games

  45. Screen Space • Need to map NDC to screen • Scale to same size as screen, flip y, translate corner to origin NDC-space Screen space (-1 1) (1 1) (0 0) (ws 0) (0 0) (-1 -1) (1 -1) (0 hs) (ws hs) Essential Math for Games

  46. Screen Space Transform • Scale to same size as screen, flip y, translate corner to origin • Step is affine – so, we can even concatenate this into projection matrix! Essential Math for Games

  47. Notes On Projection • Have described a basic viewing and projection system • Others are more powerful, allowing oblique projections in which the projection plane is not parallel to the view vector • All the major concepts in this one apply in the other ones Essential Math for Games

  48. Cameras are only the Start • Projection matrices have many more uses today • Shadows, dynamic lights, and some mirror techniques all use projection matrices • These effects often require the more complex projections (oblique, etc) Essential Math for Games

  49. Picking • Have point on screen (clicked by user) • Need to go backwards from screen to world space • Tricky part is “inverting” projection • Can use gluUnProject(), or manually Screen NDC View World Model Essential Math for Games

  50. Pick A Vector, Any Vector • Given some pixel on the screen, find the 3D object containing that pixel • Construct 3D pick vector originating at view position, ending at pixel • Inverse mapping from screen space to NDC space, then inverse projection into view space Essential Math for Games

More Related