Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.

Slides:



Advertisements
Similar presentations
Lecture 3: Transformations and Viewing. General Idea Object in model coordinates Transform into world coordinates Represent points on object as vectors.
Advertisements

Graphics Pipeline.
Translation and Rotation in 2D and 3D David Meredith Aalborg University.
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
HCI 530 : Seminar (HCI) Damian Schofield. HCI 530: Seminar (HCI) Transforms –Two Dimensional –Three Dimensional The Graphics Pipeline.
Part I: Basics of Computer Graphics Viewing Transformation and Coordinate Systems Chapter
CSCE 590E Spring 2007 Basic Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
Introduction to 3D in XNA Game Design Experience Professor Jim Whitehead February 27, 2009 Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0.
Course Website: Computer Graphics 3: 2D Transformations.
Game Engine Design ITCS 4010/5010 Spring 2006 Kalpathi Subramanian Department of Computer Science UNC Charlotte.
Viewing Doug James’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals of Computer Graphics, Chap 7 Wen-Chieh (Steve) Lin Institute of Multimedia.
Computer Graphics (Fall 2004) COMS 4160, Lecture 3: Transformations 1
CHAPTER 7 Viewing and Transformations © 2008 Cengage Learning EMEA.
CAP4730: Computational Structures in Computer Graphics
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
CS 450: Computer Graphics 2D TRANSFORMATIONS
1 Computer Graphics Week7 -2D Rotation. 3-Rotation A shape can be rotated about any of the three axes. A rotation about the z-axis will actually rotate.
Introduction to 3D Graphics Lecture 3: General Camera Model Anthony Steed University College London.
Mathematical Fundamentals
COMP 175: Computer Graphics March 24, 2015
CSE 381 – Advanced Game Programming Basic 3D Graphics
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
02/26/02 (c) 2002 University of Wisconsin, CS 559 Last Time Canonical view pipeline Orthographic projection –There was an error in the matrix for taking.
Computer Graphics Texture Mapping
Week 2 - Wednesday CS361.
Lecture Notes: Computer Graphics.
Computational Biology, Part E Basic Principles of Computer Graphics Robert F. Murphy Copyright  1996, 1999, 2000, All rights reserved.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
Week 5 - Wednesday.  What did we talk about last time?  Project 2  Normal transforms  Euler angles  Quaternions.
Maths and Technologies for Games Quaternions CO3303 Week 1.
Foundations of Computer Graphics (Fall 2012) CS 184, Lectures 13,14: Reviews Transforms, OpenGL
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
1 Computer Graphics Week9 -3D Geometric Transformation.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
Games Development 1 Camera Projection / Picking CO3301 Week 8.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
CS 376 Introduction to Computer Graphics 02 / 23 / 2007 Instructor: Michael Eckmann.
SE 313 – Computer Graphics Lecture 8: Transformations and Projections Lecturer: Gazihan Alankuş 1.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
Computer Graphics Rendering 2D Geometry CO2409 Computer Graphics Week 2.
Emerging Technologies for Games Deferred Rendering CO3303 Week 22.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
Computer Graphics Camera Projection / Picking CO2409 Week 8 - Optional Advanced Material Not on Exam.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Lecture 3 Transformations. 2D Object Transformations The functions used for modifying the size, location, and orientation of objects or of the camera.
Computer Graphics Matrix Hierarchies / Animation
Viewpoints and Transformations CSIS 5838: Graphics and Animation for Gaming.
Maths & Technologies for Games Graphics Optimisation - Batching CO3303 Week 5.
Computer Graphics Matrices
Graphics Lecture 2: Slide 1 Lecture 2 Transformations for animation.
Coordinate Systems Lecture 1 Fri, Sep 2, The Coordinate Systems The points we create are transformed through a series of coordinate systems before.
CS559: Computer Graphics Lecture 9: 3D Transformation and Projection Li Zhang Spring 2010 Most slides borrowed from Yungyu ChuangYungyu Chuang.
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
Some Notes on 3-D Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 24, 2003.
Viewing. Classical Viewing Viewing requires three basic elements - One or more objects - A viewer with a projection surface - Projectors that go from.
3D Ojbects: Transformations and Modeling. Matrix Operations Matrices have dimensions: Vectors can be thought of as matrices: v=[2,3,4,1] is a 1x4 matrix.
- Introduction - Graphics Pipeline
Computer Graphics 3: 2D Transformations
Computer Graphics 3: 2D Transformations
CS451Real-time Rendering Pipeline
COMP 175: Computer Graphics February 9, 2016
Computer Graphics Lecture 20
GAM 325/425: Applied 3D Geometry
Chapter V Vertex Processing
(c) University of Wisconsin, CS559
Presentation transcript:

Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8

Lecture Contents 1.Viewing a 3D Scene 2.Camera Positioning 3.The View Matrix 4.Camera Internals 5.Projecting 3D Vertices to 2D 6.Projection Matrices

Model Space Scene models are defined in their own local coordinate system called Model Space E.g. this square is defined as four vertices in model space: –A(5,5,0), B(-5,5,0), C(-5,-5,0), D(5,-5,0) The origin in model space is set to the model “centre” –We want rotation and scaling to work with a sensible centre –Recall the standard rotation & scaling matrices operate around the origin

Model Space to World Space –To position it in world space This is called the World Matrix –Transforms the vertices of the model from model space into world space Build the matrix by combining (multiplying) basic transforms: –Model 1 uses just a translation matrix It is moved away from the origin –Model 2 uses a combination of a Z- rotation (first), then a translation It is rotated first, then moved Every scene model has a positioning matrix

Model Positioning Recall the position and rotation of a model can be specified by defining its local space: –Position P and axes X,Y & Z (right, up and forward directions) –Defined in world space Can be written in a matrix… –…this time add a fourth column from the identity (explained last lecture): It turns out that this is another way to get the world matrix of the model –Same result as multiplying together basic transformations to create it So two ways to think about a world matrix…

Building World Matrices Two ways to build a world matrix for a model: (a) Make a matrix from the desired position and axes i.e. fill in the values of the matrix on the last slide (b) Combine some basic transformations to move/rotate/scale the model from its original location E.g. WorldMatrix = Rot(X) * Rot(Y) * Trans(P) Every time we render our scene we either: –Rebuild the world matrices from scratch From simpler variables, which we update to move the model E.g. Store x,y,z position and x,y,z rotation as floats, then build world matrix from basic transformation matrices made using these values –Or store the matrix persistently, only changing it as necessary Update a world matrix by multiplying by another transform E.g. to rotate a model, multiply its world matrix by a rotation matrix

Viewing a 3D Scene We have only considered the models in a scene –We haven’t considered the viewer We treat the viewer as an actual object in the 3D environment, looking around –This is different from 2D where the viewer is considered to be outside of the scene, looking in The viewer has position and orientation just like a model The viewer (or viewpoint) is usually considered to be a person (shown as an eye) or a camera –Will use the camera analogy in this module –But you will see the eye used in some text books / web pages

Camera Positioning The camera is positioned like any other object in world space –Its local coordinate system is called Camera Space –It views down its own z-axis We can create a matrix to position the camera just like a model –But it is not called the world matrix –We’ll call it the camera matrix This matrix can be manipulated like the world matrix of model –To position and orient the camera –Note: scaling the camera is unusual, it would effectively scale the entire world

World to Camera Space To render pixels on the screen, need to know how the models are positioned relative to the camera –What is in front of the camera, what is behind it etc… Need to transform model vertices from world space (top diagram) to camera space (bottom diagram) Maybe the camera matrix described on last slide can do this transformation? No, it goes the opposite way… –It would transform a vertex from camera space into world space – not very useful

Inverting the Camera Matrix We need another matrix that performs the inverse of the camera matrix described above Finding the inverse of a matrix is a well-known mathematical technique –We won’t cover the maths here, easily found in text book / web –Process is slow and best done rarely Finding the inverse is easy if the camera matrix is built from basic transforms: If Cam = Rot(Z) * Rot(Y) * Rot(X) * Translate(P) then Cam Inverse = Translate(-P) * Rot(-X) * Rot(-Y) * Rot(-Z) –Build the inverse by combining same basic transformations –But reverse the amounts & reverse the order of the multiplication

The View Matrix This inverted camera matrix is called the View Matrix We can calculate its general form: –Same result as multiplication on the last slide –Although we rarely utilise this form So three ways to make the view matrix –Use a camera matrix – just like a world matrix for the camera, then calculate the view matrix using the mathematical inverse –Create it from basic transformations (in reverse) –Fill in the matrix above (Dot products on the bottom line)

Using World & View Matrices Start with a model made of vertices provided by artist Give each model a world matrix and a create a view matrix for the camera Transform (multiply) each model vertex by the world matrix –To convert the models from model space into world space Then transform these world space models by view matrix –Into camera space Now have the 3D world viewed from the perspective of the camera

Camera Internals 1 Camera space is 3D, we actually display a 2D projection of it We project the 3D camera space models onto the 2D viewport The viewport is assumed to be an actual rectangle in the world Fixed in front of the camera Rays are projected from the 3D camera space vertices to the position of the camera –Passing through the viewport –Where they strike are the 2D vertices

Camera Internals 2 The viewport sits at a fixed distance in front of the camera –Sometimes called the near clip distance because objects cannot be seen nearer than this distance It covers an angle from the camera called the field of view (FOV) –FOV can be different in X & Y Rays from the 3D models that hit the viewport define 2D vertices –And meshes become 2D polygons –We can render this with 2D methods

Projection Matrices The details of the camera calculations are in an optional extra set of notes for this week (not examinable) The process is performed in two steps: –Projection –Perspective divide and scaling to viewport pixel coordinates The first step uses the projection matrix –We transform the camera space vertices into projection space using this matrix –The matrix is unlike previous matrices you have seen It includes the FOV and viewport distance We will look how they can be created in the lab –But it is applied to the vertices just like the world and view matrix The second step is performed by the graphics API

Process Overview For each vertex in our original model: –Multiply by the world, view, then projection matrix We can combine these matrices together for efficiency Very common to combine view and project matrix to make a single view-projection matrix as both are related to the camera –The vertices pass through world space, camera space and end up in projection space –A final perspective divide and scale is performed in hardware to create a final viewport space pixel position for the vertex In DirectX: –We only need to create the three matrices Create one view / projection matrix each frame for camera Create a different world matrix for each model –Vertex transformations done by shaders –Final perspective divide is done in hardware