Computer Graphics: Local Space, World Space and Cameras

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

Escuela Profesional de

Ciencia de la Computación

ICC Fase 1

Computer graphics
Local space, world space and
cameras

MSc. Vicente Machaca Arceda

Universidad Nacional de San Agustín de Arequipa

May 12, 2021

MSc. Vicente Machaca Arceda (UNSA) 1704146 1 / 24


Overview

1 Local space, world space and cameras


Local and world space
Eye space and camera

2 Projection matrices
The perspective projection matrix
The orthographic projection matrix
Look-at matrix
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 2 / 24


Local space, world space and cameras Local and world space

Table of Contents

1 Local space, world space and cameras


Local and world space
Eye space and camera

2 Projection matrices
The perspective projection matrix
The orthographic projection matrix
Look-at matrix
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 3 / 24


Local space, world space and cameras Local and world space

Local and world space

The space in which a model is defined is called its local space,


or model space. OpenGL documentation uses the term object
space.

The matrix that positions and orients an object into world space
is called a model matrix, or M.
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 4 / 24


Local space, world space and cameras Eye space and camera

Table of Contents

1 Local space, world space and cameras


Local and world space
Eye space and camera

2 Projection matrices
The perspective projection matrix
The orthographic projection matrix
Look-at matrix
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 5 / 24


Local space, world space and cameras Eye space and camera

Camera

We will want to display our 3D space—or a portion of it—on a


2D monitor.
vmachacaa@unsa.edu.pe

Figure: Positioning a camera in the 3D world. Source: [1]

MSc. Vicente Machaca Arceda (UNSA) 1704146 6 / 24


Local space, world space and cameras Eye space and camera

Camera
OpenGL includes a camera that is permanently fixed at the
origin (0, 0, 0).
vmachacaa@unsa.edu.pe

Figure: OpenGL fixed camera. Source: [1]

MSc. Vicente Machaca Arceda (UNSA) 1704146 7 / 24


Local space, world space and cameras Eye space and camera

Camera in OpenGL

We need to simulate moving


the camera to a desire
location. How?

Figure: Camera orientation.


Source: [1]
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 8 / 24


Local space, world space and cameras Eye space and camera

Camera in OpenGL

We need to simulate moving


the camera to a desire
location. How?

Given a point at world space


location PW , we need a
transform to convert it to the
equivalent point in camera
space, making it appear as
Figure: Camera orientation. though we are viewing it from
Source: [1] the desired camera location
vmachacaa@unsa.edu.pe

Cw .

MSc. Vicente Machaca Arceda (UNSA) 1704146 8 / 24


Local space, world space and cameras Eye space and camera

Camera in OpenGL

The transformations are:


Translate PW by the
negative of the desired
camera location.
Rotate PW by the
negative of the desired
Figure: Camera orientation. camera orientation.
Source: [1]
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 9 / 24


Local space, world space and cameras Eye space and camera

Camera in OpenGL

We can build a single transform that does both the rotation (R)
and the translation (T) in one matrix, called the viewing
transform matrix (V).

We compute transformations using these equations:

PC = R ∗ (T ∗ PW ) (1)

PC = (R ∗ T ) ∗ PW (2)
PC = V ∗ PW (3)
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 10 / 24


Local space, world space and cameras Eye space and camera

Camera in OpenGL
Deriving a view matrix

Figure: Deriving a view matrix. Source: [1]


vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 11 / 24


Local space, world space and cameras Eye space and camera

Camera in OpenGL
Model and View Matrices

More commonly, the V matrix is concatenated with the model


matrix M to form a single model-view (MV) matrix:

MV = V ∗ M (4)
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 12 / 24


Local space, world space and cameras Eye space and camera

Camera in OpenGL
Model and View Matrices

More commonly, the V matrix is concatenated with the model


matrix M to form a single model-view (MV) matrix:

MV = V ∗ M (4)

Then, a point PM in its own model space is transformed directly


to camera space in one step as follows:

PC = MV ∗ PM (5)
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 12 / 24


Projection matrices The perspective projection matrix

Table of Contents

1 Local space, world space and cameras


Local and world space
Eye space and camera

2 Projection matrices
The perspective projection matrix
The orthographic projection matrix
Look-at matrix
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 13 / 24


Projection matrices The perspective projection matrix

The perspective projection matrix

Perspective projection
attempts to make a 2D picture
appear 3D.

Objects that are close appear


larger than objects that are far
away, and in some cases,
parallel lines in 3D space are
vmachacaa@unsa.edu.pe

no longer parallel.

Figure: The Annunciation, with


Saint Emidius (Crivelli – 1486).
MSc. Vicente Machaca Arceda (UNSA) 1704146 14 / 24
Projection matrices The perspective projection matrix

The perspective projection matrix


The shape formed by field of view, near and far clipping plane is
called frustum.
vmachacaa@unsa.edu.pe

Figure: Perspective view volume or frustum. Source: [1]

MSc. Vicente Machaca Arceda (UNSA) 1704146 15 / 24


Projection matrices The perspective projection matrix

The perspective projection matrix

The perspective matrix is used to transform points in 3D space


to their appropriate position on the near clipping plane, and it is
built by:

1
q= (6)
fieldOfView
tan( )
2
q
A= (7)
aspectRatio Figure: Perspective matrix.
Znear + Zfar
B= (8)
Znear − Zfar
The GLM library includes a
vmachacaa@unsa.edu.pe

glm::perspective() for
2 ∗ (Znear ∗ Zfar ) building a perspective matrix.
C= (9)
Znear − Zfar

MSc. Vicente Machaca Arceda (UNSA) 1704146 16 / 24


Projection matrices The orthographic projection matrix

Table of Contents

1 Local space, world space and cameras


Local and world space
Eye space and camera

2 Projection matrices
The perspective projection matrix
The orthographic projection matrix
Look-at matrix
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 17 / 24


Projection matrices The orthographic projection matrix

The orthographic projection matrix

In orthographic projection, parallel lines remain parallel.


vmachacaa@unsa.edu.pe

Figure: Orthographic projection. Source: [1]

MSc. Vicente Machaca Arceda (UNSA) 1704146 18 / 24


Projection matrices The orthographic projection matrix

The orthographic projection matrix

Parameters:
Znear
Zfar
L and R: X coordinates of
left and right boundaries
of the projection plane.
T and B: Y coordinates of
top and bottom
boundaries of the Figure: Orthographic projection
matrix.
projection plane.
vmachacaa@unsa.edu.pe

Parallel projection is useful in situations like casting shadows,


performing 3D clipping, and in CAD (computer aided design).

MSc. Vicente Machaca Arceda (UNSA) 1704146 19 / 24


Projection matrices Look-at matrix

Table of Contents

1 Local space, world space and cameras


Local and world space
Eye space and camera

2 Projection matrices
The perspective projection matrix
The orthographic projection matrix
Look-at matrix
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 20 / 24


Projection matrices Look-at matrix

Look-at matrix
This is handy when you wish to place the camera at one location
and look toward a particular other location.
vmachacaa@unsa.edu.pe

Figure: Elements of look-at. Source: [1]

MSc. Vicente Machaca Arceda (UNSA) 1704146 21 / 24


Projection matrices Look-at matrix

Look-at matrix

Figure: Look-at matrix. Source: [1]


vmachacaa@unsa.edu.pe

GLM includes a function glm::lookAt() for building a look-at


matrix.

MSc. Vicente Machaca Arceda (UNSA) 1704146 22 / 24


Projection matrices Look-at matrix

References I

V. S. Gordon and J. L. Clevenger, Computer Graphics


Programming in OpenGL with C++. Stylus Publishing,
LLC, 2020.
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 23 / 24


Projection matrices Look-at matrix

Questions?
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 24 / 24

You might also like