Lect8 viewing in3d&transformation

Post on 19-May-2015

996 views 0 download

Tags:

description

created by Sudipta mandal

Transcript of Lect8 viewing in3d&transformation

Sudipta Mondal

Computer Graphics 7:Transformation &

Viewing in 3-D

2of23

Imag

es ta

ken

from

Hea

rn &

Bak

er, “

Com

pute

r Gra

phic

s w

ith O

penG

L” (2

004)

3-D Coordinate Spaces

Remember what we mean by a 3-Dcoordinate space

x axis

y axis

z axis

P

y

zx

Right-HandReference System

3of23

Translations In 3-D

To translate a point in three dimensions bydx, dy and dz simply calculate the newpoints as follows:

x’ = x + dx y’ = y + dy z’ = z + dz

(x’, y’, z’)(x, y, z)

Translated Position

Imag

es ta

ken

from

Hea

rn &

Bak

er, “

Com

pute

r Gra

phic

s w

ith O

penG

L” (2

004)

4of23

Scaling In 3-D

To sale a point in three dimensions by sx, syand sz simply calculate the new points asfollows:

x’ = sx*x y’ = sy*y z’ = sz*z

(x, y, z)

Scaled Position

(x’, y’, z’)

Imag

es ta

ken

from

Hea

rn &

Bak

er, “

Com

pute

r Gra

phic

s w

ith O

penG

L” (2

004)

5of23

Rotations In 3-D

When we performed rotations in twodimensions we only had the choice ofrotating about the z axisIn the case of three dimensions we havemore options

– Rotate about x – pitch– Rotate about y – yaw– Rotate about z - roll

6of23

Imag

es ta

ken

from

Hea

rn &

Bak

er, “

Com

pute

r Gra

phic

s w

ith O

penG

L” (2

004)

Rotations In 3-D (cont…)

x’ = x·cosθ - y·sinθy’ = x·sinθ + y·cosθ

z’ = z

x’ = xy’ = y·cosθ - z·sinθz’ = y·sinθ + z·cosθ

x’ = z·sinθ + x·cosθy’ = y

z’ = z·cosθ - x·sinθ

The equations for the three kinds ofrotations in 3-D are as follows:

7of23

Homogeneous Coordinates In 3-D

Similar to the 2-D situation we can usehomogeneous coordinates for 3-Dtransformations - 4 coordinatecolumn vectorAll transformations canthen be representedas matrices

úúúú

û

ù

êêêê

ë

é

1zyx

x axis

y axis

z axis

P

y

zxP(x, y, z) =

8of23

3D Transformation Matrices

úúúú

û

ù

êêêê

ë

é

1000100010001

dzdydx

úúúú

û

ù

êêêê

ë

é

1000000000000

z

y

x

ss

s

úúúú

û

ù

êêêê

ë

é

-10000cos0sin00100sin0cos

qq

qq

Translation bydx, dy, dz

Scaling bysx, sy, sz

úúúú

û

ù

êêêê

ë

é-

10000cossin00sincos00001

qqqq

Rotate About X-Axis

úúúú

û

ù

êêêê

ë

é -

1000010000cossin00sincos

qqqq

Rotate About Y-Axis Rotate About Z-Axis

9of23

Remember The Big IdeaIm

ages

take

n fro

m H

earn

& B

aker

, “C

ompu

ter G

raph

ics

with

Ope

nGL”

(200

4)

10of23

What Are Projections?

Our 3-D scenes are all specified in 3-Dworld coordinatesTo display these we need to generate a 2-Dimage - project objects onto a picture plane

So how do we figure out these projections?

Picture Plane

Objects inWorld Space

11of23

Converting From 3-D To 2-D

Projection is just one part of the process ofconverting from 3-D world coordinates to a2-D image

Clip againstview volume

Project ontoprojection

plane

Transform to2-D devicecoordinates

3-D worldcoordinate

outputprimitives

2-D devicecoordinates

12of23

Types Of Projections

There are two broad classes of projection:– Parallel: Typically used for architectural and

engineering drawings– Perspective: Realistic looking and used in

computer graphics

Perspective ProjectionParallel Projection

13of23

Types Of Projections (cont…)

For anyone who did engineering or technicaldrawing

14of23

Parallel Projections

Some examples of parallel projections

Orthographic Projection

Isometric Projection

15of23

Isometric Projections

Isometric projections have been used incomputer games from the very early days ofthe industry up to today

Q*Bert Sim City Virtual Magic Kingdom

16of23

Perspective Projections

Perspective projections are much morerealistic than parallel projections

17of23

Perspective Projections

There are a number of different kinds ofperspective viewsThe most common are one-point and twopoint perspectives

Imag

es ta

ken

from

Hea

rn &

Bak

er, “

Com

pute

r Gra

phic

s w

ith O

penG

L” (2

004)

One Point PerspectiveProjection

Two-PointPerspectiveProjection

18of23

Elements Of A Perspective Projection

VirtualCamera

19of23

The Up And Look Vectors

The look vectorindicates the direction inwhich the camera ispointingThe up vectordetermines how the

camera is rotatedFor example, is the camera held vertically orhorizontally

Up vectorLook vector

Position

Projection ofup vector