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

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

Introduction to Computer Graphics with WebGL

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

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

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

Computer Viewing Computer Graphics I, Fall 2008

CS 432 Interactive Computer Graphics

CSC 470 Computer Graphics

CSC 470 Computer Graphics. Three Dimensional Viewing

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

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

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

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

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

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

Computer Graphics CS 543 Lecture 5 (Part 2) Implementing Transformations

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

CS354 Computer Graphics Viewing and Modeling

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

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

Fachhochschule Regensburg, Germany, February 15, 2017

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

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

3D Viewing Episode 2

Transformations. Rotation and Scaling

COMP3421. Introduction to 3D Graphics

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

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

COMP3421. Introduction to 3D Graphics

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

3D Viewing Transformations

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

CS 4204 Computer Graphics

Computer Viewing and Projection. Overview. Computer Viewing. David Carr Fundamentals of Computer Graphics Spring 2004 Based on Slides by E.

Visualisation Pipeline : The Virtual Camera

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

COMP3421. Introduction to 3D Graphics

3D Viewing Episode 2

Geometry: Outline. Projections. Orthographic Perspective

Graphics pipeline and transformations. Composition of transformations

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

Computer Graphics. Chapter 10 Three-Dimensional Viewing

3.1 Viewing and Projection

Viewing and Projection

Recall: Indexing into Cube Map

Transformation Pipeline

Introduction to Computer Graphics with WebGL

CS Computer Graphics: Transformations & The Synthetic Camera

CS 543: Computer Graphics. Projection

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

Viewing with Computers (OpenGL)

Computer Graphics (CS 543) Lecture 8a: Per-Vertex lighting, Shading and Per-Fragment lighting

CS452/552; EE465/505. Review & Examples

Building Models. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

EECS : Introduction to Computer Graphics Building the Virtual Camera ver. 1.4

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

EECS : Introduction to Computer Graphics Building the Virtual Camera ver. 1.5

Computer Graphics. Chapter 7 2D Geometric Transformations

CS452/552; EE465/505. Transformations

CS452/552; EE465/505. Models & Viewing

Camera Placement for Ray Tracing

Lecture 3 Sections 2.2, 4.4. Mon, Aug 31, 2009

3D Transformations. CS 4620 Lecture Kavita Bala w/ prior instructor Steve Marschner. Cornell CS4620 Fall 2015 Lecture 11

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

Order of Transformations

Virtual Cameras and The Transformation Pipeline

OpenGL Transformations

Computer Graphics (CS 543) Lecture 6a: Hierarchical 3D Models. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

COMS 4160: Problems on Transformations and OpenGL

Viewing transformations. 2004, Denis Zorin

CS251 Spring 2014 Lecture 7

CS 112 The Rendering Pipeline. Slide 1

To Do. Outline. Translation. Homogeneous Coordinates. Foundations of Computer Graphics. Representation of Points (4-Vectors) Start doing HW 1

3D Transformations. CS 4620 Lecture 10. Cornell CS4620 Fall 2014 Lecture Steve Marschner (with previous instructors James/Bala)

Computer Graphics (CS 543) Lecture 8c: Environment Mapping (Reflections and Refractions)

Overview. By end of the week:

Computing the 3D Viewing Transformation

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

Lecture 5: Transforms II. Computer Graphics and Imaging UC Berkeley CS184/284A

CGT520 Transformations

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

Viewing Transformation

Linear and Affine Transformations Coordinate Systems

Introduction to Computer Graphics 4. Viewing in 3D

GEOMETRIC TRANSFORMATIONS AND VIEWING

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

Objectives. transformation. General Transformations. Affine Transformations. Notation. Pipeline Implementation. Introduce standard transformations

2D and 3D Viewing Basics

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

The Importance of Matrices in the DirectX API. by adding support in the programming language for frequently used calculations.

Prof. Feng Liu. Fall /19/2016

Illumination & Shading I

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

Three-Dimensional Viewing Hearn & Baker Chapter 7

Computer Graphics (4731) Lecture 4: 2D Graphics Systems (Drawing Polylines, tiling, & Aspect Ratio)

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

Computer Graphics (CS 543) Lecture 9 (Part 2): Clipping. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

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

Lecture 4. Viewing, Projection and Viewport Transformations

CSC 305 The Graphics Pipeline-1

Transcription:

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

3D Viewing? Specify a view volume Objects inside view volume drawn to viewport (screen) Objects outside view volume clipped (not drawn)! 1. Set camera position 2. Set view volume (3D region of interest)

Different View Volume Shapes z y z y x Orthogonal view volume x Perspective view volume Different view volume shape => different look Foreshortening? Near objects bigger Perpective projection has foreshortening Orthogonal projection: no foreshortening

The World Frame Object positions initially defined in world frame World Frame origin at (0,0,0) Objects positioned, oriented (translate, scale, rotate transformations) applied to objects in world frame World frame (Origin at 0,0,0)

Camera Frame More natural to describe object positions relative to camera (eye) Why? Our view of the world First person shooter games

Camera Frame Viewing: After user chooses camera (eye) position, represent objects in camera frame (origin at eye position) Viewing transformation: Converts object (x,y,z) positions in world frame to positions in camera frame More natural to view Objects in camera frame Objects initially Specified in world frame World frame (Origin at 0,0,0) Camera frame (Origin at camera)

Default OpenGL Camera Initially Camera at origin: object and camera frames same Points in negative z direction Default view volume is cube with sides of length 2 Default view volume (objects in volume are seen) 2 clipped out z=0

Moving Camera Frame Same relative distance after Same result/look default frames Translate objects -5 away from camera Translate camera +5 away from objects

Moving the Camera We can move camera using sequence of rotations and translations Example: side view Rotate the camera Move it away from origin Model-view matrix C = TR // Using mat.h mat4 t = Translate (0.0, 0.0, -d); mat4 ry = RotateY(90.0); mat4 m = t*ry;

Moving the Camera Frame Object distances relative to camera determined by the modelview matrix Transforms (scale, translate, rotate) go into modelview matrix Camera transforms also go in modelview matrix (CTM) Camera Transforms Object transforms (Rotate, Scale Translate) CTM

The LookAt Function Previously, command glulookat to position camera glulookat deprecated!! Homegrown mat4 method LookAt() in mat.h Sets camera position, transforms object distances to camera frame void display( ){ } mat4 mv = LookAt(vec4 eye, vec4 at, vec4 up);.. Builds 4x4 matrix for positioning, orienting Camera and puts it into variable mv

The LookAt Function LookAt(eye, at, up) But Why do we set Up direction? Programmer defines: eye position LookAt point (at) and Up vector (Up direction usually (0,1,0))

Nate Robbins LookAt Demo

What does LookAt do? Programmer defines eye, lookat and Up LookAt method: Forms new axes (u, v, n) at camera Transform objects from world to eye camera frame World coordinate Frame Eye coordinate Frame

Camera with Arbitrary Orientation and Position Define new axes (u, v, n) at eye v points vertically upward, n away from the view volume, u at right angles to both n and v. The camera looks toward -n. All vectors are normalized. World coordinate Frame (old) Eye coordinate Frame (new)

LookAt: Effect of Changing Eye Position or LookAt Point Programmer sets LookAt(eye, at, up) If eye, lookat point changes => u,v,n changes

Viewing Transformation Steps 1. Form camera (u,v,n) frame 2. Transform objects from world frame (Composes matrix to transform coordinates) Next, let s form camera (u,v,n) frame world y (0,1,0) v lookat x (1,0,0) u n (0,0,0) (0,0,1) z

Constructing U,V,N Camera Frame Lookat arguments: LookAt(eye, at, up) Known: eye position, LookAt Point, up vector Derive: new origin and three basis (u,v,n) vectors Lookat Point 90 o eye

Eye Coordinate Frame New Origin: eye position (that was easy) 3 basis vectors: one is the normal vector (n) of the viewing plane, other two (u and v) span the viewing plane v u n is pointing away from the world because we use left hand coordinate system Lookat Point eye n N = eye Lookat Point n = N / N world origin (u,v,n should all be orthogonal) Remember u,v,n should be all unit vectors So Normalize vectors!!!!!

Eye Coordinate Frame How about u and v? Lookat v V_up Derive u first - u u is a vector that is perp to the plane spanned by eye n N and view up vector (V_up) U = V_up x n u = U / U

Eye Coordinate Frame How about v? v V_up u To derive v from n and u Lookat eye n v = n x u v is already normalized

Eye Coordinate Frame Eye space origin: (Eye.x, Eye.y,Eye.z) Put it all together v V_up u Basis vectors: n = (eye Lookat) / eye Lookat u = (V_up x n) / V_up x n v = n x u Lookat eye n

Step 2: World to Eye Transformation Next, use u, v, n to compose LookAt matrix Transformation matrix (M w2e )? Matrix that transforms a point P in world frame to P in eye frame P = Mw2e x P world y P v x u Eye frame n 1. Come up with transformation sequence that lines up eye frame with world frame 2. Apply this transform sequence to point P in reverse order z

World to Eye Transformation 1. Rotate eye frame to align it with world frame 2. Translate (-ex, -ey, -ez) to align origin with eye y v u n Rotation: ux uy uz 0 vx vy vz 0 nx ny nz 0 0 0 0 1 world (ex,ey,ez) z x Translation: 1 0 0 -ex 0 1 0 -ey 0 0 1 -ez 0 0 0 1

World to Eye Transformation Transformation order: apply the transformation to the object in reverse order - translation first, and then rotate world Mw2e = y v u n (ex,ey,ez) x ux uy ux 0 1 0 0 -ex vx vy vz 0 0 1 0 -ey nx ny nz 0 0 0 1 -ez 0 0 0 1 0 0 0 1 = Rotation ux uy uz -e. u vx vy vz -e. v nx ny nz -e. n 0 0 0 1 Order Translation Multiplied together = lookat transform z Note: e.u = ex.ux + ey.uy + ez.uz e.v = ex.vx + ey.vy + ez.vz e.n = ex.nx + ey.ny + ez.nz

lookat Implementation (from mat.h) Eye space origin: (Eye.x, Eye.y,Eye.z) Basis vectors: n = (eye Lookat) / eye Lookat u = (V_up x n) / V_up x n v = n x u ux uy uz -e. u vx vy vz -e. v nx ny nz -e. n 0 0 0 1 mat4 LookAt( const vec4& eye, const vec4& at, const vec4& up ) { vec4 n = normalize(eye - at); vec4 u = normalize(cross(up,n)); vec4 v = normalize(cross(n,u)); vec4 t = vec4(0.0, 0.0, 0.0, 1.0); mat4 c = mat4(u, v, n, t); return c * Translate( -eye ); }

Other Camera Controls The LookAt function is only for positioning camera Other ways to specify camera position/movement Yaw, pitch, roll Elevation, azimuth, twist Direction angles

Flexible Camera Control Sometimes, we want camera to move Like controlling an airplane s orientation Adopt aviation terms: Pitch: nose up-down Roll: roll body of plane Yaw: move nose side to side

Yaw, Pitch and Roll Applied to Camera

Flexible Camera Control Create a camera class class Camera private: Point3 eye; Vector3 u, v, n;. etc Camera methods (functions) to specify pitch, roll, yaw. E.g cam.slide(1, 0, 2); // slide camera backward 2 and right 1 cam.roll(30); // roll camera 30 degrees cam.yaw(40); // yaw camera 40 degrees cam.pitch(20); // pitch camera 20 degrees

Recall: Final LookAt Matrix Slide along u, v or n Changes eye position Changes these components slide ux uy uz -e. u vx vy vz -e. v nx ny nz -e. n 0 0 0 1 Pitch, yaw, roll rotates u, v or n Changes u, v or n roll

Implementing Flexible Camera Control Camera class: maintains current (u,v,n) and eye position class Camera private: Point3 eye; Vector3 u, v, n;. etc User inputs desired roll, pitch, yaw angle or slide 1. Roll, pitch, yaw: calculate modified vector (u, v, n ) 2. Slide: Calculate new eye position 3. Update lookat matrix, Load it into CTM

Example: Camera Slide Recall: the axes are unit vectors User changes eye by delu, delv or deln eye = eye + changes (delu, delv, deln) Note: function below combines all slides into one E.g moving camera by D along its u axis = eye + Du void camera::slide(float delu, float delv, float deln) { eye.x += delu*u.x + delv*v.x + deln*n.x; eye.y += delu*u.y + delv*v.y + deln*n.y; eye.z += delu*u.z + delv*v.z + deln*n.z; setmodelviewmatrix( ); }

Load Matrix into CTM void Camera::setModelViewMatrix(void) { // load modelview matrix with camera values } mat4 m; Vector3 evec(eye.x, eye.y, eye.z);// eye as vector m[0] = u.x; m[4] = u.y; m[8] = u.z; m[12] = -dot(evec,u); m[1] = v.x; m[5] = v.y; m[9] = v.z; m[13] = -dot(evec,v); m[2] = n.x; m[6] = n.y; m[10] = n.z; m[14] = -dot(evec,n); m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1.0; CTM = m; // Finally, load matrix m into CTM Matrix Slide changes evec, roll, pitch, yaw, change u, v, n Call setmodelviewmatrix after slide, roll, pitch or yaw ux uy uz -e. u vx vy vz -e. v nx ny nz -e. n 0 0 0 1

Example: Camera Roll v v u u u' cos( ) u sin( ) v v' sin( ) u cos( ) v void Camera::roll(float angle) { // roll the camera through angle degrees float cs = cos(3.142/180 * angle); float sn = sin(3.142/180 * angle); Vector3 t = u; // remember old u u.set(cs*t.x sn*v.x, cs*t.y sn.v.y, cs*t.z sn.v.z); v.set(sn*t.x + cs*v.x, sn*t.y + cs.v.y, sn*t.z + cs.v.z) setmodelviewmatrix( ); }

References Interactive Computer Graphics, Angel and Shreiner, Chapter 4 Computer Graphics using OpenGL (3 rd edition), Hill and Kelley