1 / 26

CS 4731: Computer Graphics Lecture 11: 3D Viewing

CS 4731: Computer Graphics Lecture 11: 3D Viewing. Emmanuel Agu. 3D Viewing. Similar to taking a photograph. Viewing Transformation. Control the “lens” of the camera Project the object from 3D world to 2D screen. (ex, ey, ez). world. view up vector (Up_x, Up_y, Up_z). (cx, cy, cz).

ekram
Download Presentation

CS 4731: Computer Graphics Lecture 11: 3D Viewing

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 4731: Computer GraphicsLecture 11: 3D Viewing Emmanuel Agu

  2. 3D Viewing • Similar to taking a photograph

  3. Viewing Transformation • Control the “lens” of the camera • Project the object from 3D world to 2D screen

  4. (ex, ey, ez) world view up vector (Up_x, Up_y, Up_z) (cx, cy, cz) Viewing Transformation • Control the “lens” of the camera • Important camera parameters to specify • Camera (eye) position (Ex,Ey,Ez) in world coordinate system • Center of interest (coi) (cx, cy, cz) or lookAt point • Orientation (which way is up?): Up vector (Up_x, Up_y, Up_z)

  5. u v n y Eye coordinate frame coi world x z Viewing Transformation • Transformation? • Form a camera (eye) coordinate frame • Transform objects from world to eye space

  6. world Viewing Transformation • Eye space? • Transform to eye space can simplify many downstream operations (such as projection) in the pipeline (1,0,0) (0,1,0) u v (0,0,1) n y (0,0,0) coi x z

  7. Viewing Transformation • OpenGL way: • gluLookAt (Ex, Ey, Ez, cx, cy, cz, Up_x, Up_y, Up_z) • The view up vector is usually (0,1,0) • Remember to set the OpenGL matrix mode to GL_MODELVIEW first • Recall: OpenGL uses 3 matrices: • Modelview matrix: • Projection matrix: • Viewport matrix: • Modelview matrix: • combination of modeling matrix M and Camera transforms V

  8. Viewing Transformation • OpenGL Code: void display() { glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,0,1,0,0,0,0,1,0); display_all(); // your display routine }

  9. Projection Transformation • Different types of projection: parallel, perspective, orthographic, etc • Important to control • Projection type: perspective or orthographic, etc. • Field of view and image aspect ratio • Near and far clipping planes

  10. Perspective Projection • Similar to real world • Characterized by object foreshortening • Objects appear larger if they are closer to camera • Need: • Projection center • Projection plane • Projection: Connecting the object to the projection center camera projection plane

  11. Projection?

  12. Orthographic Projection • No foreshortening effect – distance from camera does not matter • The projection center is at infinite • Projection calculation – just drop z coordinates

  13. y y z z x Field of View • Determine how much of the world is taken into the picture • Larger field of view = smaller object projection size center of projection field of view (view angle) q

  14. Near and Far Clipping Planes • Only objects between near and far planes are drawn • Near plane + far plane + field of view = Viewing Frustum Near plane Far plane y z x

  15. Viewing Frustrum • 3D counterpart of 2D world clip window • Objects outside the frustum are clipped Near plane Far plane y z x Viewing Frustum

  16. Projection Transformation • In OpenGL: • Set the matrix mode to GL_PROJECTION • Perspective projection: use • gluPerspective(fovy, aspect, near, far) or • glFrustum(left, right, bottom, top, near, far) • Orthographic: • glOrtho(left, right, bottom, top, near, far)

  17. y y z z x gluPerspective(fovy, aspect, near, far) • Aspect ratio is used to calculate the window width w fovy h eye Aspect = w / h near far

  18. y z x glFrustum(left, right, bottom, top, near, far) • Can use this function in place of gluPerspective() left top right bottom near far

  19. y z glOrtho(left, right, bottom, top, near, far) • For orthographic projection top left x right bottom near far

  20. Example: Projection Transformation void display() { glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJETION); glLoadIdentity(); gluPerspective(fove, aspect, near, far); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,0,1,0,0,0,0,1,0); display_all(); // your display routine }

  21. y f x pitch roll Flexible Camera Control • Sometimes, we want camera to move • Just like control a airplane’s orientation • Use aviation terms for this y d x q yaw

  22. Yaw, pitch, roll? • Think about being in an airplane • Pitch: nose up-down • Roll: roll body of plane • Yaw: move nose side to side

  23. y y f q x x pitch roll yaw Flexible Camera Control • Instead of provide COI, it is possible to just give camera orientation • Just like control a airplane’s orientation d

  24. Flexible Camera Control • How to compute the viewing vector (x,y,z) from pitch(f) and yaw(q) ? z = Rcos(f)cos(90-q) x = Rcos(f)cos(q) y y F = 0 q = 0 R f x x q R cos(f) z y = Rsin(f) z

  25. Flexible Camera Control • gluLookAt() does not let you to control pitch and yaw • you need to • User supplies ,  or roll angle • Compute/maintain the vector by yourself • Calculate COI = Eye + (x,y,z) • Then, call gluLookAt().

  26. References • Hill, chapter 7

More Related