graphics & visualization: principles &...

44
Graphics & Visualization Chapter 4 Projections and Viewing Transformations Graphics & Visualization: Principles & Algorithms Chapter 4

Upload: others

Post on 13-May-2020

59 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization

Chapter 4

Projections and Viewing

Transformations

Graphics & Visualization: Principles & Algorithms Chapter 4

Page 2: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 2

• In computer graphics there are:

3D models

2D output devices (displays and printers)

• Projective mapping (projection):

Must take place at some point in the graphics pipeline

Usually after the culling stages and before the rendering stage

• Viewing transformation:

Defines the transition from the world coordinate

system (WCS) to canonical screen system (CSS)

via the eye coordinate system (ECS)

Specifies the clipping bounds (for frustum culling)

in ECS

Introduction

Page 3: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 3

• All objects are initially defined in their own local coordinate system

• These objects are unified in WCS

• The WCS is essentially used to define the model of a 3D synthetic

world

• The transition from WCS to ECS:

Simplifies a number of operations including culling (e.g. the specification of

the clipping bounds by the user) and projection

• The transition from ECS to CSS:

Ensures that all objects that survived culling will be defined in a canonical

space (usually [-1,1])

• Objects defined in a canonical space:

Can easily be scaled to the actual coordinates of any display device or monitor

Maintain high floating-point accuracy

Coordinate Systems

Page 4: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 4

• Projection: techniques for the creation of the image of an object

onto another simpler object (e.g. line, plane, surface)

• Projection lines are defined by:

Center of projection

Points on the image being projected

• The intersection of a projector with the simpler object (e.g. the plane

of projection) forms the image of a point of the original object.

• Projections can be defined in spaces of arbitrary dimension.

• In Computer Graphics & Visualization:

Projections are from 3D space onto 2D space

The 2D space is referred to as the plane of projection & models the output

device

Projections

Page 5: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 5

• Two projections are of interest:

Perspective: the distance of the center of projection from the plane of

projection is finite

Parallel: the distance of the center of projection from the plane of

projection is infinite

• Projective mappings are not affine transformations, so they cannot

be described by affine transformation matrices.

Differences between affine transformations and projective mappings:

Projections(2)

Page 6: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 6

• Parallel lines: are not projected onto parallel lines

their projections seem to meet at a vanishing point

• Parallel lines are projected onto parallel lines only when their plane

is parallel to the plane of projection

• A straight line will map to a straight line

Example:

• Ratios of distances are not preserved:

• Cross ratios are preserved:

• To fully describe the projective image of a line we need the image of

3 points on the line (affine transformations need only 2)

Projections(3)

ab a b

bd b d

ac a c

cd c dab a b

bd b d

Page 7: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 7

• Models the viewing system of our eyes

• Can be abstracted by a pinhole camera:

Center of projection: the pinhole

Plane of projection: the image plane (where the image is formed)

Creates an inverted image

Derive an upright image by placing the image ‘in front’ of the pinhole

Perspective Projection

Page 8: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 8

• Suppose that:

Center of projection is the origin

Plane of projection is perpendicular to the

negative z-axis at distance d from the center

• A point P = [x, y, z]T is projected onto P΄ = [x΄, y΄, d]T

• P1 and P1΄ are the projections of P and P΄ onto the yz-plane

• are similar so:

• Similarly :

• The above are not linear equations (division by z)

Perspective Projection (2)

and 1 2 1 2OP P OP P ·y y d y

yd z z

1 2 1 2

22

P P P P

OPOP·d xx

z

Page 9: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 9

• Trick to express the perspective-projection equations in matrix form:

Use matrix

which alters the homogeneous coordinate and

maps the coordinates of a point [x, y, z]T as follows:

• Divide by the homogeneous coordinate:

Perspective Projection (3)

0 0 0

0 0 0

0 0 0

0 0 1 0

d

d

d

PERP

·

··

·

1

x x d

y y d

z z d

z

PERP

·

·

· ·/

·

1

x d

x d z

y d y dz

zz d

dz

Page 10: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 10

• Perspective shortening:

The size of the projection of an object is inversely proportional to its distance

from the center of projection

• Known in ancient times, then forgotten

• Leonardo da Vinci studied the laws of perspective

• Older paintings had no perspective (symbolic criteria prevailed)

Perspective Projection (4)

Page 11: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 11

• Center of projection is at infinite distance from the projection plane

• Projection lines are parallel to each other

• To describe parallel projection one must specify:

The direction of projection (a vector)

The plane of projection

• Two types of parallel projections:

Orthographic: the direction of projection is normal to the plane

of projection

Oblique: the direction of projection is not necessarily normal to

the plane of projection

Parallel Projection

Page 12: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 12

• Usually employs one of the main planes as the plane of projection

• Suppose the xy-plane is used

• A point P = [x, y, z]T will be projected onto P΄ = [x΄,y΄,z΄]T =[x,y,0] T

as follows:

where

Orthographic Projection

· ORTHO

P P P

1 0 0 0

0 1 0 0

0 0 0 0

0 0 0 1

ORTHOP

Page 13: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 13

• Let the direction of projection be:

and the plane of projection be the xy-plane

• The projection P΄ = [x΄,y΄,z΄]T of a point P = [x, y, z]T will be

(1) for some scalar λ

• The z-coordinate of P΄ is 0, so (1) becomes:

• The other 2 coordinates of P΄ are:

Oblique Projection [ , , ]T

x y zDOP DOP DOPDOP

· P P DOP

0 · or z

z

zz DOP

DOP

· · and ·yx

x

z z

DOPDOPx x DOP x z y y z

DOP DOP

Page 14: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 14

• Matrix form:

Oblique Projection (2)

1 0 0

0 1 0( )

0 0 0 0

0 0 0 1

x

z

y

z

DOP

DOP

DOP

DOP

OBLIQUEP DOP

( )· OBLIQUE

P P DOP P

Page 15: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 3 15

EXAMPLE 1: Perspective Projection of a Cube

Determine the perspective projections of a cube

of side 1 when

(a)the plane of projection is z=-1 and

(b)the plane of projection is z=-10.

The cube is placed on the plane of projection.

SOLUTION (a)

• Represent the vertices of the cube as a 4×8 matrix:

Projection Example 1

0 1 1 0 0 1 1 0

0 0 1 1 0 0 1 1

1 1 1 1 2 2 2 2

1 1 1 1 1 1 1 1

C

Page 16: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 3 16

• Multiply the perspective projection matrix (d=-1) by C:

• Normalize by the homogeneous coordinates:

Projection Example 1 (2)

1 0 0 0 0 1 1 0 0 1 1 0

0 1 0 0 0 0 1 1 0 0 1 1· ·

0 0 1 0 1 1 1 1 2 2 2 2

0 0 1 0 1 1 1 1 2 2 2 2

PERP C C

1 10 1 1 0 0 0

2 2

1 10 0 1 1 0 0

2 2

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

Page 17: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 3 17

(b) The original cube is:

• Multiply the perspective projection matrix (d=-10) by C’:

• Normalize by the homogeneous coordinates:

Projection Example 1 (3)

0 1 1 0 0 1 1 0

0 0 1 1 0 0 1 1

10 10 10 10 11 11 11 11

1 1 1 1 1 1 1 1

C

10 0 0 0 0 10 10 0 0 10 10 0

0 10 0 0 0 0 10 10 0 0 10 10·

0 0 10 0 100 100 100 100 110 110 110 110

0 0 1 0 10 10 10 10 11 11 11 11

C

10 100 1 1 0 0 0

11 11

10 100 0 1 1 0 0

11 11

10 10 10 10 10 10 10 10

1 1 1 1 1 1 1 1

Page 18: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 3 18

EXAMPLE 2: Perspective Projection onto an Arbitrary Plane

Compute the perspective projection of a point P=[x, y, z]T onto the

arbitrary plane Π which is specified by the point R0=[x0,y0,z0]T and a

normal vector . The center of projection is O.

SOLUTION

• P΄=[x ΄, y ΄, z ΄]T is the projection of P=[x, y, z]T

• are collinear so

for some scalar a

• In the projection equations:

(1)

scalar a must be determined.

Projection Example 2

[ , , ]T

x y zn n nN

and OP OP ·a OP OP

' , ' , 'x ax y ay z az

Page 19: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 3 19

• Vector is on the plane of projection, so :

• Substitute the values of x, y, z from (1), set c = nx x0 + ny y0 + nz z0 and

solve for a:

• The projection equations include a division by a combination of x,y,z

• Put in matrix form by altering the homogeneous coordinate:

Projection Example 2 (2)

0R P

0 0 0

0 0 0

· 0

( ) ( ) ( ) 0

x y z

x y z x y z

N

or n x x n y y n z z

or n x n y n z n x n y n z

0R P

x y z

ca

n x n y n z

,

0 0 0

0 0 0

0 0 0

0x y z

c

c

c

n n n

PERP

Page 20: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 3 20

EXAMPLE 3: Oblique projection with Azimuth & Elevation Angles

Sometimes (particularly in architectural design), oblique projections are

specified in terms of the azimuth and elevation angles φ and θ that define

the relation of the direction to the plane of projection. Determine the

projection matrix in this case.

SOLUTION

• Let xy be the plane of projection

• The direction of the projection vector is:

• So:

Projection Example 3

[cos cos ,cos sin ,sin ]T DOP

cos1 0 0

tan

sin0 1 0( , )

tan

0 0 0 0

0 0 0 1

OBLIQUEP

Page 21: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 3 21

EXAMPLE 4: Oblique projection onto an Arbitrary Plane

Determine the oblique projection mapping onto an arbitrary plane Π that

is specified by a point R0=[x0,y0,z0]T and a normal vector .

The direction of projection is given by the vector

SOLUTION

Transform plane Π to coincide with the xy-plane, use the oblique

projection matrix, undo the first transform:

• Step 1: Translate R0 to the origin,

• Step 2: Align with the positive z-axis (by using from[Ex 3.12])

• Step 3: Use the oblique projection matrix with the direction of

projection transformed according to previous steps:

Projection Example 4

[ , , ]T

x y zDOP DOP DOPDOP

[ , , ]T

x y zn n nN

( )0

T R

N ( )A N

( )· ( )·

0DOP A N T R DOP

Page 22: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 3 22

• Step 4: Undo the alignment

• Step 5: undo the translation

• Finally:

Projection Example 4 (2) ( )1A N

( )0

T R

, ( ) ( )· ( ) · ( )· ( )· ( )

1

OBLIQUE 0 OBLIQUE 0P DOP T R A N P DOP A N T R

Page 23: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 23

• Defines:

the process of coordinate conversion:

The clipping boundaries (for frustum culling) in ECS

(Right-handed coordinate systems)

• Viewing Transformation: a. WCS-to-ECS conversion

b. ECS-to-CSS conversion

orthographic projections

perspective projections

• z-coordinate is maintained by the ECS-to-CSS conversion

Stages following VT (e.g. hidden surface elimination) require 3D

information

Viewing Transformation (VT)

Page 24: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 24

• ECS can be defined within the WCS by:

The ECS origin E

The direction of view

The up direction

• The origin E represents the point of view (location of an observer)

• The vector

defines the up direction

need not be perpendicular to

• WCS to ECS conversion steps:

1. Define the ECS axes xe, ye and ze

2. Perform the WCS-to-ECS conversion for all objects

WCS to ECS

g

up

up

g

Page 25: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 25

1. Define the ECS axes

• Sufficient information (E, , ) since the coordinate system is

right-handed

• Align xe- and ye-axes with the WCS axes with the convention:

xe is the horizontal axis & increases to the right

ye is the vertical axis & increases upwards

ze-axis points towards the observer (right-handed ECS)

Compute xe- and ye-axes as cross products:

WCS to ECS (2)

gup

e e

e e e

x up z

y z x

ez g

Page 26: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 26

2. WCS-to-ECS conversion

i. Establish matrix

ii. Pre-multiply all object vertices by it

• From [Ex. 3.16] this conversion requires 2 transformations:

Translation by

Change of basis (rotational transformation)

• Let the WCS coordinates of the ECS unit axis vectors be:

• Then:

WCS to ECS (3)

WCS ECSM

[ , , ]T

x y zE E E E

[ , , ] , [ , , ] and [ , , ]T T T

x y z x y z x y za a a b b b c c c e e ex y z

0 1 0 0

0 0 1 0 ·

0 0 0 1

0 0 0 1 0 0 0 1

x y z x

x y z y

x y z z

a a a E

b b b E

c c c E

WCS ECSM

Page 27: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 27

• Orthographic projection onto the xy-plane:

Select a region of space (view volume) that will be mapped to CSS

rectangular parallelepiped

can be defined by 2 opposite vertices

xe = l, the left clip plane

xe = r, the right clip plane, (r > l)

ye = b, the bottom clip plane

ye = t, the top clip plane, (t > b)

ze = n, the near clip plane

ze = f , the far clip plane, ( f < n, since

the ze axis points toward the observer)

ECS to CSS: Orthographic projection

Page 28: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 28

• To maintain the z-coordinate use the ortho. proj. MORTHO = ID

• Converting the view volume into CSS:

Translation & Scaling

Map the (l, b, n) values to -1 and (r, t, f) values to 1

• Thus a WCS point Xw = [xw, yw, zw]T is mapped into CSS by:

ECS to CSS: Orthographic projection(2)

2 2 2( , , )· ( , , )·

2 2 2

2 20 0 0 0 01 0 0

2

2 20 0 0 0 00 1 0

· 2

2 20 0 0 0 00 0 1

2

0 0 0 10 0 0 1 0 0 0 1

r l t b n f

r l t b f n

r lr l

r l r l r l

t bt b

t b t b t b

n fn f

f n f n f n

ORTHO

ECS CSSM S T ID

· · ORTHO

s ECS CSS WCS ECS wX M M X

Page 29: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 29

• View volume is a truncated pyramid, symmetrical about the

-ze axis

• This view volume is specified by:

θ , the angle of the field of view in the y-direction

aspect, the width to height ratio of a cross section of the pyramid

ze = n, the near clipping plane

ze = f , the far clipping plane ( f < n)

ECS to CSS: Perspective projection

Page 30: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 30

• Projection takes place onto the near clipping plane ze = n

• Compute the other clipping boundaries:

• Use a modified version of the

perspective projection matrix:

• z-coordinate :

Preserve it for hidden surface & other computations in screen space

Simply keeping ze will deform objects

Use a mapping that preserves lines & planes

zs = A + B / ze , where A,B are constants

ECS to CSS: Perspective projection (2)

top: | |·tan( )2

bottom: -

right: ·

left: -

t n

b t

r t aspect

l r

0 0 0

0 0 0

0 0 0

0 0 1 0

d

d

d

PERP

Page 31: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 31

• Require that (ze = n) (zs = n) and (ze = f ) (zs = f ) so

A = ( n + f ) and B = -nf

• This mapping will not alter the boundaries ze = n , ze = f

but this will not be true for ze values between them

• Thus the perspective projection matrix is:

Makes the w-coordinate equal to ze

Must be followed by a division by ze

(perspective division)

Clipping boundaries are not affected

Transforms the truncated pyramid into

a rectangular parallelepiped :

ECS to CSS: Perspective projection (3)

0 0 0

0 0 0

0 0

0 0 1 0

n

n

n f nf

VTP

Page 32: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 32

• Situation similar to the setting before the orthographic projection

• This view volume is already symmetrical about the –ze axis

• ECS-to-CSS conversion steps: 1. PVT

2. translation along ze

3. scaling

ECS to CSS: Perspective projection (4)

2 2 2( , , )· (0,0, )·

2

20 0 0

1 0 0 00 0 0

2 0 1 0 00 0 0 0 0 0

· · 0 00 0 12 20 0 0 0 0 1 0

0 0 0 1

0 0 0 1

n f

r l t b f n

r ln

nt b n f

n f nf

f n

PERSP

ECS CSS VTM S T P

20 0 0

20 0 0

20 0

0 0 1 0

n

r l

n

t b

n f nf

f n f n

Page 33: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 33

• Thus a WCS point Xw = [xw, yw, zw]T is converted into CSS by:

followed by the perspective division by w (= ze)

• Frustum culling is performed before the perspective division

ensuring that the coordinates of every point on every object are

within the clipping bounds:

-w ≤ x, y, z ≤ w

• The coordinates of every point are now in the range [-1,1]

ECS to CSS: Perspective projection (5)

· ·

x

y

z

w

PERSP

ECS CSS WCS ECS wM M X

/

x

yw

z

w

sX

Page 34: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 34

Example:

• Take the boundary points with ECS coordinates

[l, b, n, 1]T and [0, 0, f, 1]T

• Apply the PVT matrix:

• The homogeneous coordinate is no longer 1

• Apply the scaling & translation matrices:

ECS to CSS: Perspective projection (6)

2 2

0 0

0 0· ·

1 1

l ln

b bn

n n f f

n f

VT VTP P

2 2

0 0

0 0· · · ·

ln n

bn n

n n f f

n n f f

S T S T

Page 35: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 35

Example(continued):

• Due to the symmetry of the truncated pyramid about –ze :

r = -l, t = -b so r - l = -2l, t - b = -2b

• Perspective division:

which are the CSS values of the points

ECS to CSS: Perspective projection (7)

1 0

0

1 0 0/ /

1 1

1 1

n

nn f

n f

n f

Page 36: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 36

A. Truncated Pyramid Not Symmetrical about ze-Axis

e.g. stereo viewing where two viewpoints are slightly offset on the

xe –axis

Extended Viewing Transformation

Page 37: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 37

A. Truncated Pyramid Not Symmetrical about ze-Axis

• Parameters of the clipping planes:

ze = n0, the near clipping plane (as before)

ze = f0, the far clipping plane, f0 < n0 (as before)

ye = b0, the ye-coordinate of the bottom clipping plane at its

intersection with the near clipping plane

ye = t0, the ye-coordinate of the top clipping plane at its intersection

with the near clipping plane

xe = l0, the xe-coordinate of the left clipping plane at its intersection

with the near clipping plane

xe = r0, the xe-coordinate of the right clipping plane at its intersection

with the near clipping plane

Extended Viewing Transformation(2)

Page 38: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 38

A. Truncated Pyramid Not Symmetrical about ze-Axis (steps)

• Convert the non-symmetrical pyramid to symmetrical about ze with a shear

transformation on the xy-plane

(1)

• Determine the A, B parameters

Take the shear on the y-coordinate: map the midpoint of t0b0 to 0

Similarly for the xe shear factor:

• So (1) becomes:

Extended Viewing Transformation(3)

1 0 0

0 1 0

0 0 1 0

0 0 0 1

A

B

xySH

0 0 0 00

0

· 0 2 2

b t b tB n B

n

0 0

02

l rA

n

0 0

0

0 0

0

1 0 02

0 1 02

0 0 1 0

0 0 0 1

l r

n

b t

n

NON SYMSH

Page 39: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 39

A. Truncated Pyramid Not Symmetrical about ze-Axis (steps)

• Change the clipping boundaries, to reflect the symmetrical shape of

the new pyramid:

• Substitute the above into

which is equivalent to the original with the clipping bounds

replaced by the initial clipping bounds.

Extended Viewing Transformation(4)

0 0

0 0 0 00 0

0 0 0 00 0

2 2

2 2

n n f f

l r l rl l r r

b t b tb b t t

PERSP

ECS CSSM

0

0 0

0

0 0

0 0 0 0

0 0 0 0

20 0 0

20 0 0

20 0

0 0 1 0

n

r l

n

t b

n f n f

f n f n

PERSP

ECS CSSM

PERSP

ECS CSSM

Page 40: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 40

A. Truncated Pyramid Not Symmetrical about ze-Axis

• Thus it is not necessary to have initial clipping bounds; can name

them n, f, l, r, b, t from the start.

• The ECSCSS mapping in the case of non-symmetrical

perspective projection is thus:

Extended Viewing Transformation(5)

20 0 0

1 0 02

20 0 0

0 1 0· · 2

20 0 0 0 1 0

0 0 0 10 0 1 0

nl r

r ln

nb t

t bn

n f nf

f n f n

PERSP NON SYM PERSP

ECS CSS ECS CSS NON SYMM M SH

20 0

20 0

20 0

0 0 1 0

n l r

r l r l

n b t

t b t b

n f nf

f n f n

Page 41: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 41

B. Oblique Projection

• Useful, e.g., in the computation of oblique views for 3D displays:

is not sufficient

Direction of projection must be taken into account

• View volume: a six-sided parallelepiped specified by:

The 6 parameters used for the non-symmetrical pyramid (n0, f0, l0, r0, b0, t0)

The direction of projection vector

• Steps:

1. Translate the view volume so that (l0, b0, n0)-point moves to the ECS origin

2. Perform a shear in the xy-plane

Extended Viewing Transformation(6)

ORTHO

ECS CSSM

DOP

Page 42: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 42

B. Oblique Projection (steps)

• Take the point defined by the origin and

Shear the (DOPy) coordinate to 0:

Similarly for the x-shear factor:

• The required transformation is:

• Alter the clipping bounds to reflect the new rectangular parallelepiped

n = 0, f = f0 - n0, l = 0, r = r0 - l0, b = 0, t = t0 - b0

• ECSCSS mapping for a general parallel projection is thus:

Extended Viewing Transformation(7)

[ , , ]T

x y zDOP DOP DOPDOP

· 0y

y z

z

DOPDOP B DOP B

DOP

x

z

DOPA

DOP

0

0

0

1 0 01 0 0

0 1 00 1 0· ·

0 0 1

0 0 0 10 0 1 0

0 0 0 1

x

z

y

z

DOP

DOP l

DOP b

DOP n

PARALLEL PARALLELSH T

· · PARALLEL ORTHO

ECS CSS ECS CSS PARALLEL PARALLELM M SH T

Page 43: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 43

• Frustum culling:

Eliminates primitives (parts or whole) that lie outside the view volume(frustum)

Is implemented by 3D clipping algorithms

• The viewing transformation defines the 3D clipping boundaries.

• Clipping takes place in CSS, after the application of or

but before the division by w.

• Clipping boundaries for: perspective projection: -w ≤ x, y, z ≤ w

orthographic or parallel projection: -1 ≤ x, y, z ≤ 1

• Why clip in 3D and not in 2D, after throwing away z?

In perspective projection, objects behind the center of projection E would

appear upside-down (no sufficient information in clipping)

Avoids possible perspective division by 0

The near and far clipping planes limit the depth range & enable the optimal

allocation of the bits of the depth buffer

Frustum Culling & the Viewing Transformation

PERSP

ECS CSSM

ORTHO

ECS CSSM

Page 44: Graphics & Visualization: Principles & Algorithmsgraphics.cs.aueb.gr/cgvizbook/slides/CGVIZ_Chapter_4.pdf · Graphics & Visualization: Principles & Algorithms Chapter 4 5 • Two

Graphics & Visualization: Principles & Algorithms Chapter 4 44

• Viewport: rectangular part of the screen where the contents

of the view volume are displayed.

• Defined by its bottom-left and top-right corners

[xmin, ymin]T and [xmax, ymax]

T in pixel coordinates

[xmin, ymin, zmin]T and [xmax, ymax, zmax]

T to maintain the z-coordinate

• Viewport transformation converts objects from CSS into the

viewport coordinate system (VCS) with a scaling & a translation:

• This is a generalization of the 2D window-to-viewport transformation [Ex. 3.8].

• The size of the viewport defines the final size of the objects on screen

The Viewport Transformation

1 0 0 0 0 0 0 02 2 2 2

0 1 0 0 0 0 0 0·2 2 2 2

0 0 1 0 0 0 0 02 2

0 0 0 1 0 0 0 1

min max max min max min min max

min max max min max min min max

min max max min max min

x x x x x x x x

y y y y y y y y

z z z z z z

VIEWPORT

CSS VCSM

2 2

0 0 0 1

min maxz z