Computer Graphics World, View and Projection Matrices - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Computer Graphics World, View and Projection Matrices

Description:

Allows us to apply rotation and scaling with a sensible centre ... Recall the position and rotation of a model can be specified by defining its local space: ... – PowerPoint PPT presentation

Number of Views:354
Avg rating:3.0/5.0
Slides: 17
Provided by: lauren80
Category:

less

Transcript and Presenter's Notes

Title: Computer Graphics World, View and Projection Matrices


1
Computer GraphicsWorld, View and Projection
Matrices
  • CO2409 Computer Graphics
  • Week 8

2
Lecture Contents
  • Viewing a 3D Scene
  • Camera Positioning
  • The View Matrix
  • Camera Internals
  • Projecting 3D Vertices to 2D
  • Projection Matrices

3
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
  • Allows us to apply rotation and scaling with a
    sensible centre

4
Model Space to World Space
  • Each model has a positioning matrix
  • To transform it from model space into world space
  • Built from basic transforms
  • Model 1 is simply translated away from the origin
  • Model 2 is rotated (Z) around the origin (first),
    then translated
  • This matrix is called the World Matrix (or
    Transform)
  • Transforms the vertices of the model into world
    space

5
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
  • Defined in world space
  • Can write this in a matrix
  • but this time add a fourth column from the
    identity (like last week)
  • It turns out that this is the world matrix of the
    model
  • Same as combining the basic transformations to
    position it
  • So two ways to think about a world matrix

6
Building World Matrices
  • Two ways to build a world matrix for a model
  • Make a matrix from the desired position and axes
  • Combine basic transformations (considering order)
  • E.g. WorldMatrix Rot(X) Rot(Y) Trans(P)
  • Can rebuild the matrix each time we render
  • From stored variables
  • Or can store it persistently
  • To move or reorient a model we
  • Apply another transform to its world matrix
  • Or entirely rebuild the world matrix (either
    method)

7
Viewing a 3D Scene
  • Have only considered the objects in a scene
  • Not considered the viewer
  • Treat the viewer as an object in the 3D
    environment, looking around
  • Different from 2D where the viewer is outside of
    the scene, looking in
  • So the viewer has a position and an orientation
  • The viewer (or viewpoint) is usually considered
    to be a person (shown as an eye) or a camera
  • We will use the camera analogy

8
Camera Positioning
  • The camera is positioned like any other object in
    world space
  • So it has a local coordinate system called Camera
    Space
  • Define a matrix for the cameras position in the
    usual way
  • This matrix can be translated and rotated like
    any other matrix
  • To position and orient the camera
  • Scaling the camera is unusual
  • Effectively shrinks the world

9
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
    etc
  • Need to convert the models from world space into
    camera space
  • We might think that the camera matrix can be used
    to do this
  • but it converts wrong way
  • From camera space to world space

10
Inverting the Camera Matrix
  • Need another matrix that performs the inverse of
    the camera matrix
  • Finding the inverse of a matrix is a well-known
    mathematical technique
  • But it is expensive and best avoided where
    possible
  • Can find the inverse easily if the camera matrix
    is built from basic transforms
  • If Cam Rot(Z) Rot(Y) Rot(X) Translate(P)
  • then Cam-1 Translate(-P) Rot(-X) Rot(-Y)
    Rot(-Z)
  • Negate the translations and rotations and reverse
    the order of the multiplication

11
The View Matrix
  • This inverted camera matrix is called the View
    Matrix (Transform)
  • In fact we can calculate its general form
  • This is the same result as the multiplication
    method given on the last slide
  • Again two ways to think about this matrix
  • And two possibilities when creating it

(Dot products on the bottom line)
12
Using World View Matrices
  • Transform 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 a the entire 3D world as viewed from the
    perspective of the camera
  • NB We view down the Z axis

13
Camera Internals 1
  • Finally we project the 3D camera space models
    into 2D geometry
  • The viewport is assumed to be a fixed distance in
    front of the camera
  • Rays are projected from the 3D camera space
    vertices to the position of the camera
  • Passing through the viewport

14
Camera Internals 2
  • The viewport has a fixed size, and 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 visible 2D vertices
  • The key camera settings to perform this
    projection are
  • The viewport distance
  • The field of view

15
Projection Matrices
  • The details of the camera calculations are in an
    additional set of notes for this week
  • The process is performed in two steps
  • Projection
  • Perspective divide and scaling to pixel
    coordinates
  • The first step uses the projection matrix
  • Complex and unlike previous matrices you have
    seen
  • It includes the FOV and viewport distance
  • We will look how they can be created in the lab
  • The second step is typically performed by the
    graphics API (based on the viewport size)

16
Process Overview
  • For each vertex in our original model
  • Multiply by the world, view, then projection
    matrix
  • These matrices can themselves be combined
  • Resulting vertices are in viewport space
  • A final perspective divide and scale is needed to
    create a pixel position for the vertex
  • In DirectX
  • We only need to create the three matrices
  • Create view / projection matrix once per render
    for camera
  • Create a different world matrix for each model
  • Vertex transformations done by our shader
    (programmable pipeline) or by DirectX (fixed
    pipeline)
  • Final perspective divide is done by API in both
    cases
Write a Comment
User Comments (0)
About PowerShow.com