CSC 470 Computer Graphics. Three Dimensional Viewing

Similar documents
CSC 470 Computer Graphics

Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter Three-dimensional Viewing

CS 4204 Computer Graphics

Overview. Viewing and perspectives. Planar Geometric Projections. Classical Viewing. Classical views Computer viewing Perspective normalization

3D Viewing. With acknowledge to: Ed Angel. Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

CS 543: Computer Graphics Lecture 6 (Part I): 3D Viewing and Camera Control. Emmanuel Agu

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

The Viewing Pipeline adaptation of Paul Bunn & Kerryn Hugo s notes

Computer Viewing Computer Graphics I, Fall 2008

7. 3D Viewing. Projection: why is projection necessary? CS Dept, Univ of Kentucky

CITSTUDENTS.IN VIEWING. Computer Graphics and Visualization. Classical and computer viewing. Viewing with a computer. Positioning of the camera

Geometry: Outline. Projections. Orthographic Perspective

The View Frustum. Lecture 9 Sections 2.6, 5.1, 5.2. Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2011

Fundamental Types of Viewing

One or more objects A viewer with a projection surface Projectors that go from the object(s) to the projection surface

Introduction to Computer Graphics 4. Viewing in 3D

Lecture 9 Sections 2.6, 5.1, 5.2. Wed, Sep 16, 2009

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Computer Graphics (CS 543) Lecture 6a: Viewing & Camera Control. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Classical and Computer Viewing. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

CS354 Computer Graphics Viewing and Modeling

CS380: Computer Graphics Viewing Transformation. Sung-Eui Yoon ( 윤성의 ) Course URL:

Viewing Transformation

1 Transformations. Chapter 1. Transformations. Department of Computer Science and Engineering 1-1

3D Viewing. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

COMP Computer Graphics and Image Processing. 5: Viewing 1: The camera. In part 1 of our study of Viewing, we ll look at ˆʹ U ˆ ʹ F ˆʹ S

COMP3421. Introduction to 3D Graphics

COMP3421. Introduction to 3D Graphics

Viewing and Projection

COMP3421. Introduction to 3D Graphics

3D Viewing. Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

3.1 Viewing and Projection

Overview of Projections: From a 3D world to a 2D screen.

Three-Dimensional Viewing Hearn & Baker Chapter 7

Prof. Feng Liu. Fall /19/2016

2D and 3D Viewing Basics

Announcements. Submitting Programs Upload source and executable(s) (Windows or Mac) to digital dropbox on Blackboard

Advanced Computer Graphics (CS & SE )

Computer Graphics. P05 Viewing in 3D. Part 1. Aleksandra Pizurica Ghent University

Getting Started. Overview (1): Getting Started (1): Getting Started (2): Getting Started (3): COSC 4431/5331 Computer Graphics.

Chapter 5. Projections and Rendering

Visualisation Pipeline : The Virtual Camera

Describe the Orthographic and Perspective projections. How do we combine together transform matrices?

Fachhochschule Regensburg, Germany, February 15, 2017

Computer Viewing. CITS3003 Graphics & Animation. E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley

Viewing with Computers (OpenGL)

COMP Computer Graphics and Image Processing. a6: Projections. In part 2 of our study of Viewing, we ll look at. COMP27112 Toby Howard

Transformation Pipeline

Computer Viewing. Prof. George Wolberg Dept. of Computer Science City College of New York

OpenGL Transformations

Computer Graphics 7: Viewing in 3-D

Chapter 8 Three-Dimensional Viewing Operations

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

Graphics and Visualization

Viewing and Projection

COMS 4160: Problems on Transformations and OpenGL

3D Graphics for Game Programming (J. Han) Chapter II Vertex Processing

Viewing COMPSCI 464. Image Credits: Encarta and

Viewing and Projection

Reminder: Affine Transformations. Viewing and Projection. Shear Transformations. Transformation Matrices in OpenGL. Specification via Ratios

Computer Viewing. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

1 (Practice 1) Introduction to OpenGL

Announcement. Project 1 has been posted online and in dropbox. Due: 11:59:59 pm, Friday, October 14

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

CSE 690: GPGPU. Lecture 2: Understanding the Fabric - Intro to Graphics. Klaus Mueller Stony Brook University Computer Science Department

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Lecture 4. Viewing, Projection and Viewport Transformations

CSE328 Fundamentals of Computer Graphics

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

Computer Graphics Viewing

Computer Graphics. Lecture 04 3D Projection and Visualization. Edirlei Soares de Lima.

3D Polygon Rendering. Many applications use rendering of 3D polygons with direct illumination

Wire-Frame 3D Graphics Accelerator IP Core. C Library Specification

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

Order of Transformations

Models and The Viewing Pipeline. Jian Huang CS456

MAE : Lecture #12 - Projection and Perspective. Lecture Overview:

1 OpenGL - column vectors (column-major ordering)

3D Viewing Episode 2

3D Viewing. CS 4620 Lecture 8

MORE OPENGL. Pramook Khungurn CS 4621, Fall 2011

INTRODUCTION TO COMPUTER GRAPHICS. It looks like a matrix Sort of. Viewing III. Projection in Practice. Bin Sheng 10/11/ / 52

3D Viewing Episode 2

CMSC427 Transformations II: Viewing. Credit: some slides from Dr. Zwicker

COMP30019 Graphics and Interaction Perspective & Polygonal Geometry

So we have been talking about 3D viewing, the transformations pertaining to 3D viewing. Today we will continue on it. (Refer Slide Time: 1:15)

Viewing. Reading: Angel Ch.5

Projection and viewing. Computer Graphics CSE 167 Lecture 4

Computer Graphics. Bing-Yu Chen National Taiwan University

Overview. By end of the week:

The Virtual Camera. The Virtual Camera. Setting the View Volume. Perspective Camera

CS 428: Fall Introduction to. Viewing and projective transformations. Andrew Nealen, Rutgers, /23/2009 1

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Computer Graphics: Viewing in 3-D. Course Website:

CIS 636 Interactive Computer Graphics CIS 736 Computer Graphics Spring 2011

INTRODUCTION TO COMPUTER GRAPHICS. cs123. It looks like a matrix Sort of. Viewing III. Projection in Practice 1 / 52

Viewing. Announcements. A Note About Transformations. Orthographic and Perspective Projection Implementation Vanishing Points

CSE 167: Introduction to Computer Graphics Lecture #5: Projection. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

Viewing. Part II (The Synthetic Camera) CS123 INTRODUCTION TO COMPUTER GRAPHICS. Andries van Dam 10/10/2017 1/31

COMP30019 Graphics and Interaction Perspective Geometry

Transcription:

CSC 470 Computer Graphics Three Dimensional Viewing 1

Today s Lecture Three Dimensional Viewing Developing a Camera Fly through a scene Mathematics of Projections Producing Stereo Views 2

Introduction We have already learnt how to: Create 2D and 3D solid objects Construct a 3D scene Add colors Create complex mesh surfaces So what do we do now? Moving/Flying through a scene Adding perspective 3

The Camera We previously looked at setting up a camera. glortho() and glulookat() these created parallel projections We now want to modify a scene to give us perspective projections. lines converge as they get further away 4

Viewing process and graphics pipeline parallel projection 5

OpenGL tools for modeling and viewing Set modeling transformations. Setting camera in OpenGL. Positioning and aiming the camera. 6

Set the projection matrix glmatrixmode(gl_projection); // make the projection matrix current glloadidentity(); // set it to the identity matrix glortho(left,right,bottom,top,near,far); // multiply it by the new matrix 7

glulookat(eye.x, eye.y, eye.z, look.x, look.y, look.z, up.x, up.y, up.z) It takes as parameters the eye position, eye, of the camera and the look-at point, look. It also takes an approximate up direction, up. up is most often set to (0, 1, 0) to suggest an up direction parallel to the y-axis. 8

Example 1: Set up a typical camera Show the camera with its eye situated at eye = (4,4,4) looking at the origin with lookat = (0,1,0). The up direction is set to up = (0, 1, 0). Suppose we also want the view volume to have a width of 6.4, a height of 4.8 (so its aspect ratio is 640/480), and to set near to 1 and far to 50. This camera would be established using: glmatixmode(gl_projection); // set the view volume glloadidentity(); glortho(-3.2, 3.2, -2.4, 2.4, 1, 50); glmatrixmode(gl_modelview); // place and aim the camera glloadidentity(); glulookat(2, 4, 5, 0, 0, 0, 0, 1, 0); 9

10

Example 2 11

The Camera The Perspective Camera 12

The Camera Revisited View volume: a portion of a rectangular pyramid. Viewangle (θ): the opening (vertically) of the pyramid. Viewplane: between the near plane and the far plane whose location dose not matter. Map the image (projections) on the viewplane into the viewport. Aspect ratio: to specify a view volume *With a perspective projection, the point P is determined by finding where a line from the eye to P intersects the viewplane. 13

Setting the View Volume The projection matrix (encoded with the view volume) is set up using gluperspective(). (Comparing with glortho() for parallel projection.) The height (H) of a viewplane (i.e. near plane)can be computed as: H=2*N*tg(θ/2), and its width (W) is decided by the aspect ratio (AR): W=H*AR. OpenGL commands: glmatrixmode(gl_projection); glloadidentity(); gluperspective(viewangle, aspectratio, N, F); 14

Positioning and Pointing the Camera The only difference between a parallel- and perspective-projection camera resides in the projection matrix, which determines the shape of the view volume. Code: glmatrixmode(gl_modelview); glloadidentity(); glulookat(eye, look, up); 15

The Camera Setting up the Camera instead of glortho() we now use: gluperspective() gluperspective viewangle aspectratio (W/H) near plane far plane 16

The Camera glmatrixmode(gl_projection); glloadidentity(); gluperspective(viewangle, aspectratio, N, F); 17

The Camera Positioning the Camera The camera is positioned using a combination of translations and rotations. Think if the camera being in the same location as the viewers eye. 18

The Camera up(x,y,z) eye(x,y,z) lookat(x,y,z) 19

The Camera glmatrixmode(gl_modelview); glloadidentity(); glulookat(eye.x, eye.y, eye.z, look.x, look.y, look.z, up.x, up.y, up.z); 20

The Camera The camera can have an arbitrary orientation and position. Therefore we can think of the camera having its own axes. 21

glulookat and the Camera Coordinate System The view matrix V created by glulookat is V u u u d v v v d x y z x x y z y = nx ny nz dz 0 0 0 0 where d x = -eye u, d y = -eye v, d z = -eye n V is postmultiplied by M to form the modelview matrix VM. 22

The Camera Camera Movement A camera has six degrees of freedom: 1. slid in 3 directions; and 2. rotated in 3 directions 23

The Camera Camera Movement The camera can move along its axes. 24

The Camera Camera Movement The camera can move along its axes. This is called sliding the camera. Sliding the camera: for example, move it a distance D along u-axis: eye + Du. 25

The Camera Camera Movement To move the camera along the u axis you would simply perform eye = eye + Du To move slide the camera in any direction: eye.x = du*u.x + dv*v.x + dn*n.x eye.y = du*u.y + dv*v.y + dn*n.y eye.z = du*u.z + dv*v.z + dn*n.z v n u 26

The Camera Camera Movement Besides physically moving the camera to another location the camera can be tilted in different directions to look at different parts of the scene. 27

The Camera Camera Movement We use a plane analogy to describe the cameras movement. a rotation from the horizontal along the length is called PITCH a rotation from the horizontal along the width is called ROLL a rotation around the vertical is called YAW 28

Positioning and Pointing the Camera Arbitrary orientation and position (using the aviation terms): (rotate) (change heading) pitch heading or azimuth or bearing 29

The Camera Pitch v = cos(θ)v sin(θ)n n = sin(θ)n + cos(θ)v v n 30

The Camera Roll u = cos(θ)u + sin(θ)v v = cos(θ)v - sin(θ)u v u 31

The Camera Yaw n = cos(θ)n - sin(θ)u u = sin(θ)n + cos(θ)u n u 32

The Camera A Teapot Fly By teapot_flyby.exe A Mesh Surface Fly By 33

Building a Camera in a Program The Camera class definition class Camera{ private: Point3 eye; Vector3 u,v,n; // view volume shape double viewangle, aspect, neardist, fardist; // tell OpenGL where the camera is void setmodelviewmatrix(); public: Camera(); // default constructor // like glulookat() void set(point3 eye, Point3 look, Vector3 up); void roll(float angle); // roll it void pitch(float angle); // increase pitch void yaw(float angle); // yaw it void slide(float delu, float delv, float deln); // slide it void setshape(float vang, float asp, float neard, float fard); }; 34

Building a Camera in a Program (2) The utility routine: setmodelviewmatrix(); void Camera :: setmodelviewmatrix(void) { // load modelview matrix with existing camera values float m[16]; //m is column-organized; m[0~3] = the 1st column! Vector3 evec(eye.x, eye.y, eye.z); // a vector version of eye m[0] = u.x; m[4] = u.y; m[8] = u.z; m[12] = -evec.dot(u); m[1] = v.x; m[5] = v.y; m[9] = v.z; m[13] = -evec.dot(v); m[2] = n.x; m[6] = n.y; m[10] = n.z; m[14] = -evec.dot(n); m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1.0; glmatrixmode(gl_modelview); glloadmatrixf(m); // load OpenGL s modelview matrix } void Camera:: set(point3 Eye, Point3 look, Vector3 up) { // create a modelview matrix and send it to OpenGL eye.set(eye); // store the given eye position n.set(eye.x - look.x, eye.y - look.y, eye.z - look.z); // make n u.set(up.cross(n)); // make u = up X n n.normalize(); u.normalize(); // make them unit length v.set(n.cross(u)); // make v = n X u setmodelviewmatrix(); // tell OpenGL } 35

Projections Parallel Perspective 36

Viewing process and graphics pipeline Modelview, projection, and viewport matrices 37

Projections Parallel Projection centre of projection at infinity A D A B D C B C projection plane 38

Parallel Projection Projections centre of projection at infinity A A B D D C Points on the object are projected to the viewing plane along parallel lines B C projection plane Preserves relative dimensions of the object but does not give a realistic presentation 39

40 40 Projections Projections Parallel Projection A D C B projection plane D C B A centre of projection at infinity = 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 z y x z y x p p p

Projections Parallel Projection y So all we are really doing is getting rid of the z coordinate to take the coordinates from 3d to 2d!!! z x 41

Perspective Projections 42

Perspective Transformation First discovered by Donatello, Brunelleschi, and DaVinci during Renaissance Objects closer to viewer look larger Parallel lines appear to converge to single point 43

Perspective Projection In the real world, objects exhibit perspective foreshortening: distant objects appear smaller The basic situation: 44

Perspective Projection When we do 3-D graphics, we think of the screen as a 2-D window onto the 3-D world: How tall should this bunny be? 45

Perspective Projection The geometry of the situation is that of similar triangles. View from above: X View plane P (x, y, z) (0,0,0) x =? Z d What is x? 46

Perspective Projections Projecting a 3D Point We use similar triangles to project the point onto the plane in the line of the eye. (x,y,z) N z near plane 47

Perspective Projections Projecting a 3D Point x /x = N/-z (z in the negative direction) y /y = N/-z Once projected onto a 2D plane the z coordinate is not needed. (x,y,z) (x,y ) N z near plane 48

Perspective Projections Properties 1. Parallel lines in 3D will meet at a vanishing point 49

Perspective Projections Properties 2. Lines that pass behind the eye of the camera cause a catastropic passage through infinity. 50

Perspective Projections Properties 3. Perspective projections usually produce geometrically realistic pictures. 51

Setting view volume and aiming camera 52

53

Stereo Projections Faking depth in a 2D image Based on natural stereoscopic eye-brain system. Objects are not viewed with just one eye, but two eyes. Each eye looks at the object from a slightly different location. 54

Stereo Projections 55

Stereo Projections In OpenGL we can produce stereo views by creating two side-by-side viewports with slightly different viewing angles. The lookat point stays the same but the location of the eye moves. Human eyes are about 3 inches apart, therefore a good value for D is 1.5 56

Stereo Projections eye=(0,-1,2.5) eye=(0.5,-1,2.5) -stereoview.exe 57

Taxonomy of Projections 58

Taxonomy of Projections Perspective One Point horizon vanishing point 59

Taxonomy of Projections Perspective Two Point horizon vanishing point 60

Taxonomy of Projections Perspective Three Point horizon vanishing point 61

Taxonomy of Projections Perspective Three Point M.C. Escher: Ascending and Descending 62

Taxonomy of Projections Orthographic Projections Multiview Orthographic 63

Taxonomy of Projections Orthographic Projections Axonometric View Isometric (all three axes are shortened equally) Dimetric (two axes are shortended equally) Trimetric (all axes are shortended unequally) 64

Taxonomy of Projections Oblique Projections Combine the properties of Orthographic and Axonometric Preserves the object face; and Gives a better sense of the 3D nature. 65

Taxonomy of Projections Oblique Projections 66