1 of 44

Geometry: �Coordinates & Cameras

Instructor: Christopher Rasmussen (cer@cis.udel.edu)

February 15, 2022 ❖ Lecture 3

2 of 44

Outline

  • Coordinate systems
  • More 3-D transformations
    • Setting up the camera
  • Projections
    • Orthographic
    • Perspective
  • Marschner readings: 6.5-7.2

3 of 44

Coordinate Systems

  • What does it mean to say a point x = (x, y, z) is in a certain coordinate system or frame?
  • One way to think of x is as a weighted sum (aka linear combination) of basis vectors representing the frame’s axes
  • So x = x(1, 0, 0) + y(0, 1, 0) + z(0, 0, 1) in the local frame

x

Z

X

Y

4 of 44

Coordinate Systems

  • If the frame of interest is embedded in another frame F, then its origin and axes can be represented in F as a point o and unit vectors i, j, and k, respectively

x

k

i

j

F

o

Z

X

Y

5 of 44

Coordinate Systems

  • If the frame of interest is embedded in another frame F, then its origin and axes can be represented in F as a point o and unit vectors i, j, and k, respectively
    • These vectors can have any orientation in F, but are all orthogonal to each other
    • Later we will also refer to these with u, v, n or

u, v, w (sorry!)

x

w

(or n)

u

v

F

o

Z

X

Y

6 of 44

Coordinate Systems

  • Now x, which in the local coordinate frame is just (x, y, z), can be thought of in F as:

x = o + xi + yj + zk

x

k

i

j

F

o

Z

X

Y

7 of 44

Coordinate Systems

  • Now x, which in the local coordinate frame is just (x, y, z), can be thought of in F as:

x = o + xi + yj + zk

x

k

i

j

F

o

Z

X

Y

In Marschner: p + uu + vv + ww

8 of 44

3-D Transformations:� Arbitrary Change of Coordinates

  • A rigid transformation is used to represent a change in the coordinate system that “expresses” a point’s location

YA

XA

ZA

A

x

ZB

XB

YB

B

9 of 44

3-D Transformations:� Arbitrary Change of Coordinates

  • A rigid transformation is used to represent a change in the coordinate system that “expresses” a point’s location

YA

ZA

A

ZB

XB

YB

B

XA

Ax

10 of 44

3-D Transformations:� Arbitrary Change of Coordinates

  • A rigid transformation is used to represent a change in the coordinate system that “expresses” a point’s location

YA

ZA

A

ZB

XB

YB

B

XA

Bx

See Fig. 6.20 in Marschner for 2-D equivalent

11 of 44

3-D Transformations:� Arbitrary Change of Coordinates

  • A rigid transformation is used to represent a change in the coordinate system that “expresses” a point’s location

A

B

12 of 44

3-D Transformations:� Arbitrary Change of Coordinates

  • A rigid transformation is used to represent a change in the coordinate system that “expresses” a point’s location

A

B

M transforms x from A's to B's coordinate system

13 of 44

3-D Transformations:� Translation-only Change of Coordinates

  • A rigid transformation is used to represent a change in the coordinate system that “expresses” a point’s location

Location of A’s origin in

B’s coordinate system

A

B

14 of 44

3-D Transformations:� Arbitrary Change of Coordinates

  • A rigid transformation is used to represent a change in the coordinate system that “expresses” a point’s location

Rotation that makes

A’s axes parallel to B’s,

creating translation-

only case

A

B

15 of 44

3-D Transformations:� Arbitrary Change of Coordinates

  • A rigid transformation is used to represent a change in the coordinate system that “expresses” a point’s location

A

B

16 of 44

3-D Rigid Transformations

  • Combination of rotation followed by translation, without scaling, etc.
  • “Moves” an object from one 3-D pose to another

T

R

M

17 of 44

Rigid Transformations: Homogeneous Coordinates

  • Points in one coordinate system are transformed to the other as follows:

18 of 44

Rigid Transformations: Homogeneous Coordinates

  • Points in one coordinate system are transformed to the other as follows:

same as frame-to-canonical

matrix in Marschner 6.5

19 of 44

Rigid Transformations: Homogeneous Coordinates

  • Points in one coordinate system are transformed to the other as follows:

  • Rows of rotation matrix are B ’s axes “in” A ’s coordinate system

same as frame-to-canonical

matrix in Marschner 6.5

20 of 44

Rigid Transformations: Homogeneous Coordinates

  • Points in one coordinate system are transformed to the other as follows:

  • Rows of rotation matrix are B ’s axes “in” A ’s coordinate system
  • CWM transforms points expressed in world coordinates Wx into points expressed in camera coordinates Cx. Equivalently, it transforms a camera object to the world origin
    • Info needed for CWM: (1) Camera axes in world coordinates, (2) world origin in camera coordinates

same as frame-to-canonical

matrix in Marschner 6.5

21 of 44

Rigid Transformations: Homogeneous Coordinates

  • Points in one coordinate system are transformed to the other as follows:

  • Rows of rotation matrix are B ’s axes “in” A ’s coordinate system
  • CWM transforms points expressed in world coordinates Wx into points expressed in camera coordinates Cx. Equivalently, it transforms a camera object to the world origin
    • Info needed for CWM: (1) Camera axes in world coordinates, (2) world origin in camera coordinates

same as frame-to-canonical

matrix in Marschner 6.5

22 of 44

Rigid Transformations: Homogeneous Coordinates

  • Points in one coordinate system are transformed to the other as follows:

  • Rows of rotation matrix are B ’s axes “in” A ’s coordinate system
  • CWM transforms points expressed in world coordinates Wx into points expressed in camera coordinates Cx. Equivalently, it transforms a camera object to the world origin
    • Info needed for CWM: (1) Camera axes in world coordinates, (2) world origin in camera coordinates

same as frame-to-canonical

matrix in Marschner 6.5

23 of 44

Controlling the camera position

Blender: camera pose + object, right-handed coordinates. Origin of camera coordinate system C at tip of pyramid, note "up" arrow. World coordinates W coincide with cube object centroid (aka "model" coordinates M)

Similar view in Unity, left-handed coordinates. Here camera axes are explicit and world coordinates are not same as model coordinates.

RGB axis colors correspond to XYZ ordering

24 of 44

Transformations in Blender

  • Change view by clicking/dragging axes in scene
  • Zoom in/out, move view, toggle user/camera

  • Select object in scene or Scene Collection pane
    • Click and drag with Move, Rotate, and Scale options in scene
    • Click Transform drop-down, directly edit Location/Rotation/Scale

25 of 44

Transformations in OpenGL

  • A variety of transformations were built into OpenGL before 3.0 --- you defined a vertex v = (x, y, z) and called a function like glTranslate() to transform it
    • All this did was create a transformation matrix to be multiplied
  • Now the programmer is "responsible" for building transformation matrices
  • Luckily, other libraries exist to make this easy; we will use GLM (OpenGL Mathematics)

26 of 44

Controlling the camera position in OpenGL

  • Standard OpenGL frame: At (0, 0, 0)T in world coordinates looking in -Z direction (0, 0, -1) with up vector (0, 1, 0)T
    • Up vector controls camera roll (rotation around Z axis)
  • Changing position: "glm::lookAt" function
    • eye = (eyeX, eyeY, eyeZ)T: Desired camera position
    • center = (centerX, centerY, centerZ)T: Point at which camera is aimed (defining “gaze direction”, aka camera pitch and yaw)
    • up = (upX, upY, upZ)T: Camera’s “up” vector

from Woo et al.

27 of 44

glm::lookAt: What It Does

  • Creates rigid transformation CWM making a change from world to camera coordinates
  • Commonly called the view matrix V
  • Effect is to move scene points Wx to Cx so that camera is at origin, “look at” point is on -Z axis, and camera +Y axis is aligned with up vector
  • Up to programmer to apply it in the right place

More details in Marschner, Chapter 7.1.3

28 of 44

glm::lookAt: How It Works

  1. Compute vectors u, v, n defining new camera axes in world coordinates (Marschner textbook uses w instead of n)
    1. “Old” axes are u’ = (1, 0, 0)T, v’ = (0, 1, 0)T, n’ = (0, 0, 1)T
  2. Compute location CoW of old camera position (i.e., world origin) in terms of new location’s coordinate system
  3. Fill in rigid transform matrix

from Hill

center

C

W

29 of 44

glm::lookAt: Camera axes in world coords.

  • Form basis vectors
    • New camera Z axis: ñ = eye - center
    • New camera X axis: ũ = up x n
    • New camera Y axis: v = n x u (not necessarily same as up)
  • Normalize to make unit vectors: n = ñ/‖ñ‖, etc.

from Hill

center

C

W

30 of 44

glm::lookAt: Camera axes in world coords.

  • Form basis vectors
    • New camera Z axis: ñ = eye - center
    • New camera X axis: ũ = up x n
    • New camera Y axis: v = n x u (not necessarily same as up)
  • Normalize to make unit vectors: n = ñ/‖ñ‖, etc.

from Hill

center

C

W

ñ

31 of 44

glm::lookAt: Camera axes in world coords.

  • Form basis vectors
    • New camera Z axis: ñ = eye - center
    • New camera X axis: ũ = up x n
    • New camera Y axis: v = n x u (not necessarily same as up)
  • Normalize to make unit vectors: n = ñ/‖ñ‖, etc.

from Hill

center

up

C

W

up and n define a plane

which ũ is normal to—they

don’t have to be orthogonal

32 of 44

glm::lookAt: Camera axes in world coords.

  • Form basis vectors
    • New camera Z axis: ñ = eye - center
    • New camera X axis: ũ = up x n
    • New camera Y axis: v = n x u (not necessarily same as up)
  • Normalize to make unit vectors: n = ñ/‖ñ‖, etc.

from Hill

center

C

W

33 of 44

glm::lookAt: Camera axes in world coords.

  • Form basis vectors
    • New camera Z axis: ñ = eye - center
    • New camera X axis: ũ = up x n
    • New camera Y axis: v = n x u (not necessarily same as up)
  • Normalize to make unit vectors: n = ñ/‖ñ‖, etc.

from Hill

center

C

W

34 of 44

glm::lookAt: Camera axes in world coords.

  • Form basis vectors
    • New camera Z axis: ñ = eye - center
    • New camera X axis: ũ = up x n
    • New camera Y axis: v = n x u (not necessarily same as up)
  • Normalize to make unit vectors: n = ñ/‖ñ‖, etc.

from Hill

center

C

W

35 of 44

glm::lookAt: Camera axes in world coords.

  • Now make 3 x 3 rotation matrix as described on rigid transform slide:

36 of 44

glm::lookAt: Location

  • : World origin in camera coordinates

center

from Hill

origin

C

W

37 of 44

glm::lookAt: Location

  • : World origin in camera coordinates

center

from Hill

origin

C

W

eye

eye is camera origin in world coordinates -- aren't they just the reverse of each other?

38 of 44

glm::lookAt: Location

  • : World origin in camera coordinates

center

from Hill

origin

C

W

-eye

eye is camera origin in world coordinates -- aren't they just the reverse of each other?

39 of 44

glm::lookAt: Location

  • : World origin in camera coordinates
  • -eye is in world coordinates, so project onto camera axes (and don’t normalize):

from Hill

origin

-eye

C

W

40 of 44

glm::lookAt: Matrix

  • Letting and writing the vector components as u = (ux, uy, uz)T, etc., the final transformation matrix is given by:

V =

41 of 44

Transformations vs. Projections in CG

  • Transformation: Mapping within n-D space that “moves points around”
    • E.g., 2-D and 3-D rotation, translation, scaling, shear, but also nonlinear distortions

  • Projection: Mapping from n-D space down to lower-dimensional subspace

42 of 44

Transformations in CG

  • Mapping within n-D space that moves points around
    • Linear transformations (= matrix multiplication) preserve straight lines
    • Some nonlinear transformations in n-D can be expressed by linear ones in (n + 1)-D – the idea behind homogeneous coordinates

43 of 44

Projections in CG

  • Mapping from n-D space down to lower-dimensional subspace
    • E.g., point in 3-D space to point on plane (a 2-D entity) in that space
    • We will be interested in such 3-D to 2-D projections where the plane is the image plane
  • Things to know:
    • Where is the plane? Derived from view matrix V
    • What region of the plane does the image occupy?
    • What kind of projection?

44 of 44

The Viewing Volume

  • Definition: The region of 3-D space visible in the image
  • Depends on:
    • Camera position,
    • Camera orientation
    • Field of view
    • Image size
    • Projection type
      • Orthographic
      • Perspective

courtesy of N. Robins

Pyramid-shaped viewing volumes are characteristic of perspective projection -- more on Thursday