CS 432 Interactive Computer Graphics

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

Introduction to Computer Graphics with WebGL

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

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

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

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

Basic Elements. Geometry is the study of the relationships among objects in an n-dimensional space

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

Computer Viewing Computer Graphics I, Fall 2008

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

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

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

3D Viewing Episode 2

3D Viewing Episode 2

CS354 Computer Graphics Viewing and Modeling

Three Main Themes of Computer Graphics

Viewing with Computers (OpenGL)

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

Lecture 9: Transformations. CITS3003 Graphics & Animation

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

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

CS452/552; EE465/505. Geometry Transformations

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

CS251 Spring 2014 Lecture 7

CS 432 Interactive Computer Graphics

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

Drawing in 3D (viewing, projection, and the rest of the pipeline)

Virtual Cameras and The Transformation Pipeline

Drawing in 3D (viewing, projection, and the rest of the pipeline)

CS451Real-time Rendering Pipeline

C O M P U T E R G R A P H I C S. Computer Graphics. Three-Dimensional Graphics I. Guoying Zhao 1 / 52

Graphics pipeline and transformations. Composition of transformations

Today s Agenda. Geometry

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

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

Transformations. Rotation and Scaling

CS452/552; EE465/505. Models & Viewing

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

Drawing in 3D (viewing, projection, and the rest of the pipeline)

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

Overview. By end of the week:

Computer graphics 2: Graduate seminar in computational aesthetics

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

CS 432 Interactive Computer Graphics

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

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

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

Fachhochschule Regensburg, Germany, February 15, 2017

CS 432 Interactive Computer Graphics

COMS 4160: Problems on Transformations and OpenGL

GEOMETRIC TRANSFORMATIONS AND VIEWING

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

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

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

CS452/552; EE465/505. Review & Examples

CS559 Computer Graphics Fall 2015

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

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

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

CS452/552; EE465/505. Transformations

3D Viewing. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 9

CSE328 Fundamentals of Computer Graphics

Rasterization Overview

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

Objectives. Geometry. Basic Elements. Coordinate-Free Geometry. Transformations to Change Coordinate Systems. Scalars

3D Viewing Transformations

3D Viewing. CS 4620 Lecture 8

Viewing and Modeling

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

COMP 175 COMPUTER GRAPHICS. Lecture 07: Scene Graph. COMP 175: Computer Graphics March 10, Remco Chang 07 Scene Graph

Autonomous Navigation for Flying Robots

Figure 1. Lecture 1: Three Dimensional graphics: Projections and Transformations

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

The Graphics Pipeline and OpenGL I: Transformations!

Introduction to Computer Graphics with WebGL

Lecture 4. Viewing, Projection and Viewport Transformations

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

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

CS 130 Final. Fall 2015

3D Modelling: Animation Fundamentals & Unit Quaternions

The Projection Matrix

CSE528 Computer Graphics: Theory, Algorithms, and Applications

GEOMETRIC OBJECTS AND TRANSFORMATIONS I

CS 4204 Computer Graphics

CS 4620 Program 3: Pipeline

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Computer Graphics - Treasure Hunter

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

Vector Calculus: Understanding the Cross Product

Visualisation Pipeline : The Virtual Camera

Texture Mapping. Michael Kazhdan ( /467) HB Ch. 14.8,14.9 FvDFH Ch. 16.3, , 16.6

BASIC ELEMENTS. Geometry is the study of the relationships among objects in an n-dimensional space

2D transformations: An introduction to the maths behind computer graphics

Pipeline Operations. CS 4620 Lecture 14

Perspective transformations

CGT520 Transformations

Ray Tracer I: Ray Casting Due date: 12:00pm December 3, 2001

CS 381 Computer Graphics, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Tuesday, October 16, 2012.

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

Computer Graphics 7: Viewing in 3-D

Transcription:

CS 432 Interactive Computer Graphics Lecture 4 3D Viewing Matt Burlick - Drexel University - CS 432 1

Reading Angel Chapters 3-4 Red Book Chapter 5, Appendix E Matt Burlick - Drexel University - CS 432 2

From Objects to the Screen We started off be specifying objects via vertices that define primitives in 2D space. These vertices were all in the range 1 xx, yy 1 We added the ability to specify in OpenGL a viewport within the window to map this range to. In 3D space we can also specify a z-coordinate so that it s in view if 1 zz 1 Matt Burlick - Drexel University - CS 432 3

From Objects to the Screen In 2D space we call the area 1 xx, yy < 1 the clipping window Everything outside of this is clipped In 3D space, we call the volume 1 xx, yy, zz < 1 the clipping volume. Everything outside of this volume is clipped Matt Burlick - Drexel University - CS 432 4

From Objects to the Screen Conceptually, the job of a virtual camera is to project points in the clipping volume onto the clipping area such that zz = 0. These resulting points xx, yy, 0 are now considered in camera coordinates z=0 Matt Burlick - Drexel University - CS 432 5

From Objects to the Screen Once the objects are in camera coordinates they must be mapped to screen coordinates (i.e. pixels) We can even restrict what area of the screen to show This is called the viewport Matt Burlick - Drexel University - CS 432 6

3D Viewing Matt Burlick - Drexel University - CS 432 7

OpenGL Coordinate Systems We now have four coordinate systems! 1. Model Coordinate System Where we build our objects 2. World Coordinate System Where we place our objects via a model matrix transformation 3. Camera Coordinate System Where the objects appear on the camera film 4. Window Coordinate System Where the objects on the film appear on the screen (pixels) Matt Burlick - Drexel University - CS 432 8

OpenGL Coordinate Systems Remember, when we were talking about forwards and backwards facing polygons we talked about the right hand rule. This also defines the orientation of these coordinate systems This result is that the positive z-axis points towards the viewer centerof-projection (COP) Matt Burlick - Drexel University - CS 432 9

Computer Viewing We can simulate viewing the world by transforming objects using the following pipeline: 1. Position the objects Via their respective model matrices 2. Positioning the camera Setting the view matrix 3. Selecting the projection type/parameters Setting the projection matrix Then we clip the transformed objects against some default camera view window or volume. Matt Burlick - Drexel University - CS 432 10

Default Coordinate Systems By default the object, world, and camera coordinate systems are the same resulting in the camera located at the shared origin and pointing in the negative z-direction The default camera view volume is a cube with sides of length 2 centered at the origin Matt Burlick - Drexel University - CS 432 11

Moving the Camera Frame If we want to visualize object with both positive and negative zz values we can either Move the camera in positive zz direction Translate the camera frame Move the objects in the negative zz direction Translate the world frame Both of these view are equivalent and are determined by the model-view matrix Want a translation: TTTTTTTTTTTTTTTTTT(0.0, 0.0, dd) Where dd > 0 Matt Burlick - Drexel University - CS 432 12

Moving Camera back from Origin default frames frames after translation by dd, where dd > 0 Note: You re really transforming the world relative to the camera Matt Burlick - Drexel University - CS 432 13

Moving the Camera We can move the camera to any desired position and orientation by a sequence of rotations and translations Example: side view Rotate the camera Move it away from the origin Transformation matrix MM vvvvvvvv = TTTT Matt Burlick - Drexel University - CS 432 14

OpenGL Code Remember that the last transformation specified is the first applied mat4 t = Translate(0.0, 0.0, -d); mat4 ry = RotateY(90.0); mat4 mview = t*ry; So now we have both a model matrix for an object and a view matrix. We have options: Send both independently to the shader and in the shader compute: gl_position = view_matrix*model_matrix*vposition; Compute view_matrix*model_matrix in the OpenGL program and send that single matrix to the shader program: modelview_matrix = view_matrix*model_matrix; //OpenGL gl_position = modelview_matrix*vposition; //GLSL And of course you might just update the vertices right in OpenGL and send them to the shader. Matt Burlick - Drexel University - CS 432 15

Moving the Camera on the GPU Your choice may depend on how often things change Never? Model often, camera rarely? Camera rarely, model often? Both often? Transpose Remember, we most likely need to transpose our matrices when we send them to the shaders: GLuint model_view_loc = glgetuniformlocation(program, modelview_matrix ); gluniformmatrix4fv(modelview_loc,1,gl_true,modelview_matrix); Matt Burlick - Drexel University - CS 432 16

Viewing APIs Specifying/computing the translation and rotation(s) may not be easy or natural. To simplify things, there are several APIs that will provide the modelview matrix for different parameters. One of the more popular (and supported in OpenGL) is the Look-At API But first we need to review some geometry! Matt Burlick - Drexel University - CS 432 17

Points We already know that to defined objects we need to provide vertex locations. Geometrically we can call these locations in space points. In graphics there are at least three other important geometric objects: 1. Vectors 2. Lines 3. Planes Matt Burlick - Drexel University - CS 432 18

Vectors A vector is a quantity with two attributes Direction Magnitude Note: They have not actual position in space Examples include Force Velocity Directed line segments Important for graphics! v Matt Burlick - Drexel University - CS 432 19

Vectors A vector can be defined given two points via subtraction: vv = PP QQ Here we say the vector goes in the direction from point QQ to point PP. Matt Burlick - Drexel University - CS 432 20

Vectors Also given a point and a vector we can arrive at a new point via addition: PP = vv + QQ Matt Burlick - Drexel University - CS 432 21

Vector Operations There are additional properties of vectors: Every vector has an inverse Same magnitude but points in the opposite direction Every vector can be multiplied by a scalar Same direction (assuming non-negative magnitude), different magnitude The sum of any two vectors is a vector Use the head to tail axiom v -v αv v u w Matt Burlick - Drexel University - CS 432 22

Vectors in Homogenous Coordinates We know in 3D we specify vertices (points) via a 4D vector (confusing?) with the 4 th coordinate equal to one: PP = PP xx, PP yy, PP zz, 1 Via vector arithmetic, we then define a vector in 3D homogenous coordinates as a 4D vector with the 4 th coordinate equal to zero: vv = vv xx, vv yy, vv zz, 0 Matt Burlick - Drexel University - CS 432 23

Vectors in Homogenous Coordinates vv = vv xx, vv yy, vv zz, 0 The magnitude of this vector is: vv = vv xx 2 + vv yy 2 + vv zz 2 Usually we specify the direction by making the vector have a length of one (unit length, or a normalized): vv vv Matt Burlick - Drexel University - CS 432 24

Planes A plane can be define either by A point and two vectors Three points P v R u R Q Matt Burlick - Drexel University - CS 432 25

Normals Every plane has a vector nn normal (perpendicular, orthogonal) to it Given two non-collinear vectors on a plane, uu and vv, we can use the cross product to find a plane s normal: nn = uu vv Matt Burlick - Drexel University - CS 432 26

Cross Product The cross product is defined as aa bb = aa bb sin θθ nn Where nn is the normal. So by solving for the cross product we get the normal multiplied by a scalar. Given two vectors uu, vv we can compute the cross product as uu vv = uu yy vv zz uu zz vv yy, uu zz vv xx uu zz vv zz, uu xx vv yy uu yy vv xx, 0 Fortunately both OpenGL and GLSL also give us a cross function But be careful Always make sure your 4 th component is 0 so that it s treated as a vector! Matt Burlick - Drexel University - CS 432 27

Viewing APIs Ok back to a viewing API.. We can define a camera s location and orientation by specifying: The position of the camera, often called the eye or the view reference point (VRP) A vector that specifies the normal of the camera s view plane. This is often called the view plane normal (VPN, nn in the figure below) It is in the viewing direction In OpenGL the VPN is in the direction opposite the one in which the camera is looking The direction opposite the VPN is often called the at vector. Another vector, called the view-up vector, is in a direction specifying which is the approximate up direction for the camera Matt Burlick - Drexel University - CS 432 28

The LookAt Function The GLU library contained a function glulookat to form the required model-view matrix through a simple interface Replaced by LookAt() in mat.h These too will have to be transposed when sent to the shader programs. mat4 view_matrix = LookAt(vec4 eye, vec4 at, vec4 up); Matt Burlick - Drexel University - CS 432 29

Angle.h Lookat mat4 LookAt(const vec4& eye, const vec4& at, 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); } Matt Burlick - Drexel University - CS 432 30

The LookAt Function If we want to update our camera (move it, rotate it, etc..) we ll want to keep track of some things The location of the camera: eye Three vectors that define the view plane: 1. The view plane normal (opposite the at direction), n 2. The right direction, u 3. For convenience, we ll keep track of the third vector orthogonal to the other two (approximately the up direction), v Matt Burlick - Drexel University - CS 432 31

The LookAt Function From these vectors you should easily be able to compute the at and up vectors needed for the LookAt API at = eye-n; up = v; Matt Burlick - Drexel University - CS 432 32

Other Viewing APIs The LookAt (and glulookat) function is one of many possible APIs for positioning the camera Others include View reference point, view plane normal, view up Yaw, pitch, roll Elevation, azimuth, twist Direction angles Matt Burlick - Drexel University - CS 432 33

Interface: Flying Cameras Often we like to use the keyboard to navigate around the world This is akin to moving the camera (and re-orienting it) If we use the Look-At API on each relevant keystroke we must Compute the new eye point Compute the new at point Compute the new up vector Matt Burlick - Drexel University - CS 432 34

Interface: Flying Cameras It may be conceptually easier to move the camera according to another common API: pitch/yaw/roll Pitch: rotate around current u axis Roll: rotate around current n axis Yaw: rotate around current v axis And update our coordinate system Matt Burlick - Drexel University - CS 432 35

Interface: Flying Cameras From our Look-At API we already have v (up) and n=e-a. So a=e-n And we can get u=normalize(cross(v,n)); Pitch (rotate around u axis) by αα radians uu = uu vv = cos(αα)vv sin(αα)nn nn = sin(αα)vv + cos(αα)nn We can do this similarly for roll and yaw Notes: Use the normalize function when necessary to get unit length vectors Again, be careful that your 4 th component is zero before doing this. Make sure to call the glutpostredisplay() after changing view matrix so that it is redrawn immediately Matt Burlick - Drexel University - CS 432 36

Interface: Flying Cameras The last thing we may want to do is move allow (or away from) the direction of n We can do this by change the eye and at points by the same amount along the n vector ee = ee + ββnn aa = aa + ββnn Interface: X Pitch down x Pitch up C Yaw clockwise in un plane c Yaw counter-clockwise in un plane Z Roll clockwise in the uv plane z Roll counter-clockwise in the uv plane GLUT_KEY_UP Move towards at point GLUT_KEY_Down Move away from at point NOTE: GLUT_KEY_UP/DOWN are special keys and are called via the glutspecialfunc callback Matt Burlick - Drexel University - CS 432 37

A Camera Class For convenience you ll likely want to create a Camera class. This can store: Current view_matrix eye u,v,n And can do things like Get the view_matrix Update eye, u, v, n based on interactions. And we ll add more (the projection matrix) in a minute And when it comes time to draw an object, just pass it the current view_matrix so it can either use it or pass it to the shader. Matt Burlick - Drexel University - CS 432 38