Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a...

58
Assignment #3 As a graphics engineer, can you implement a “skeletal” rendering pipeline? Computer Graphics graphics primitives modeling transform viewing transform clipping shading & texture projection images in Internal buffer transform matrix Eye, lookat, headup material, lights, surface color Parallel or Persepctive volume images on screen viewport transform viewport location

Transcript of Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a...

Page 1: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Assignment #3

As a graphics engineer, can you implement

a “skeletal” rendering pipeline?

Computer Graphics

graphics

primitives

modeling

transform

viewing

transformclipping

shading &

texture

projectionimages in

Internal buffer

transform

matrix

Eye, lookat,

headup

material,

lights,

surface color

Parallel or

Persepctive

volume

images on

screenviewport

transform

viewport

location

Page 2: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

glMatrixMode(GL_MODELVIEW);

glLoadIdentity(T1);

glMultiMatrixf(T2);

glMultiMatrixf(Tn);

draw_the_object(v);

v’ = IT1T2Tnv

Modeling Transform

As a global system

objects move but coordinates stay the same

apply in the reverse order

Page 3: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Tasks

Need a stack (CS16, 24)

Push & pop

Need to create matrices (4x4)

Need to multiply matrices (4x4)

Computer Graphics

Page 4: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Why 4x4 not 3x3?

Use of homogeneous coordinates

[x,y] -> [wx,wy,w]

[wx,wy,w] -> [wx/w, wy/w, w] -> [x,y]

[x,y,z] -> [wx, wy, wz, w]

[wx, wy, wz, w] -> [wx/w, wy/w, wz/w] -

>[x,y,z]

One dimension up (w!=0)

Computer Graphics

Page 5: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Reason #1

All operations (including translation) are

now matrix operations

Hierarchical transforms (multiple T, R, S)

are computed once (top matrix in the stack)

and applied

Computer Graphics

Page 6: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Euler Angle Rotation

X Y

Z

XY

Z

X

Y

Z

x

y

z

x

y

z

'

'

'

cos sin

sin cos

1

0 0

0 0

0 0 1 0

0 0 0 1 1

x

y

z

x

y

z

'

'

'

cos sin

sin cos

1

1 0 0 0

0 0

0 0

0 0 0 1 1

11000

0cos0sin

0010

0sin0cos

1

'

'

'

z

y

x

z

y

x

Page 7: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Transformations

Translation Scaling

X

Y

Zz

x

y

X

Y

Z 2x

11000

100

010

001

1

'

'

'

z

y

x

T

T

T

z

y

x

z

y

x

11000

000

000

000

1

'

'

'

z

y

x

S

S

S

z

y

x

z

y

x

Page 8: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Modeling Transform Your Way

Implement a stack with push and pop

Replace OpenGL codes with your own

codes

Computer Graphics

Page 9: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Viewing Transform

So the user specifies a lot of information

Eye

Center

Up

Near, far,

Left, right top, bottom, etc.

X

Y

Z

UP

EYE

rightleft

bottom

top

bf

CENTER

Page 10: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

What does a system programmer do with those numbers?

Generate screen coordinates correctly and efficiently

Inside/outside test

Projection

Here comes the part which contains math which you may not like

But all you need to know is matrix operation

What does OpenGL do?

Page 11: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Arbitrary View Volume

X

Y

Z

UP

EYE

rightleft

bottom

top

bf

CENTER

Page 12: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Inside-Outside Test (Clipping)

Intersection of

A plane and

A Line

line of points end:),,(),,,(

10

)()()(

0)]([)]([)]([

)(

)(

)(

:

0:

222111

121212

111

121121121

121

121

121

zyxzyx

t

zzcyybxxa

dczbyaxt

dzztzcyytybxxtxa

zztz

yyty

xxtx

line

dczbyaxplane

EYE

Page 13: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Clipping in Canonical Volumes

Z

Y

Y=-Z

Y=Z

Z=-1

Z=Zmin

45^o

Z

Y Y=1

Y=-1

Z=-1

(A,B,C)(A,B,C)

far plane=film

near plane

Page 14: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Clipping with 6-bit outcode

Perspective

Above y>-z

Below y<z

Right x>-z

Left x<z

Behind z<-1

In front z >zmin

Parallel

Above y>1

Below y<-1

Right x>1

Left x<-1

Behind z<-1

In front z >0

Page 15: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Projection

Again, an intersection of

A plane and

A Line

EYE

Page 16: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Sidebar: Reason #2

A pin-hole model without inversion (f=1 in

OpenGL)

f (v)

Z

X

x fX

Z

y fY

Z

f (v) x

x

Page 17: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Canonical Volumes

Z

Y

Y=-Z

Y=Z

Z=-1

Z=Zmin

45^o

Z

Y Y=1

Y=-1

Z=-1

(A,B,C) (A,B) (A,B,C)(A/C,B/C)

far plane=film

near plane

Page 18: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Sidebar: Reason #2

Traditional Way Matrix Way

Computer Graphics

x fX

Z

y fY

Z

10100

1000

0010

0001

1

'

'

'

z

y

x

z

y

x

Page 19: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Problem

Both clipping and projection can be done

efficiently in a canonical volume

But we do not have a canonical volume in

general

Solution: Normalization transform

A single matrix operation to bring objects in

any arbitrary volume into a canonical volume

Cannot change what the user sees

Page 20: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Normalization Transform A transformation to facilitate clipping and

projection

X

Y

Z

An arbitrary view volume:

Expensive for clipping and projection

Page 21: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

X

Y

Z

The canonical view volume:

Simple clipping (six-bit outcode)

Simple projection (x/z, y/z)

Y

Z

y z

y z

z 1

z z min

45o

Page 22: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

OpenGL Terminology

X

Y

Z

UP

EYE

rightleft

bottom

top

bf

CENTER

Page 23: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Normalization TransformPerspective - OpenGL

External parameters

Translate EYE into origin

Rotate the EYE coordinate system such thatw (e-c) becomes z

u becomes x

v becomes y

Internal parameters

Shear to have centerline of the view volume

aligning with z

Scale into canonical truncated pyramid

Page 24: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Existing Rendering Pipeline

graphics

primitives

modeling

transform

viewing

transformclipping

shading &

texture

projectionimages in

Internal buffer

transform

matrix

Eye, lookat,

headup

material,

lights,

surface color

Parallel or

Perspective

volume

images on

screenviewport

transform

viewport

location

Page 25: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Rendering Pipeline with

Normalization Transform

graphics

primitives

modeling

transform

viewing

transformclipping

shading &

texture

projectionimages in

Internal buffer

transform

matrix

Eye, lookat,

headup

material,

lights,

surface color

Parallel or

Perspective

volume

images on

screenviewport

transform

viewport

location

normalization

transform

Page 26: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Changes

Modeling + Viewing + Normalization get

concatenated into ONE transform before

applying to any primitives

Confusion: normalization does not just push

the eye frame back to origin and line up

with world frame, it pushes objects away

too

Purpose: to make clipping and projection

much more efficient

Page 27: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Clipping?

Polygon clipping algorithm discussed

earlier

For inside/outside determination

Page 28: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

What Else?

Start from polygon with vertices

End with polygon with vertices

Visible surface determination

Painter’s algorithm (sort by depth)

2D painting

Interior: Scan conversion

Exterior: Line drawing (Bresemheim)

That is!

Computer Graphics

Page 29: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Viewing Normalization

Line up (X-Y-Z) and (U-V-W)

Initially, (U-V-W) are specified in (X-Y-Z)

system (In fact, everything is specified in

X-Y-Z system)

Some point in time, want to specify things

in (U-V-W) system, or U becomes (1,0,0),

V becomes (0,1,0), W becomes (0,0,1)

Translation (easy) + Rotation (hard)

Page 30: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Hand-eye Coordination A common problem in graphics, robotics

and vision

The camera and effector are not co-located

Computer Graphics

Page 31: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

From camera to robot

R and O are in camera’s frame

Rows are robot’s frame in

camera’s system

Computer Graphics

x

yz

o

P=(xc,yc,zc)

P’=(xr,yr,zr)?

)(

'

'

''

OP

z

y

x

P

Page 32: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

X YZ

o

P=(xc,yc,zc)

P’=(xr,yr,zr)?

TPOPOPOP

z

y

x

P

|||

|||

|||

|||

|||

|||

)(

|||

|||

)(

'

'

'' ZYXZYXZYXZYX

T

From robot to camera

R and T are in robot’s frame

Cols are camera’s frame in robot’s system

Page 33: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Translate EYE into the origin

X

Y

Z

u

v

w

X

Y

Z

u

v

w

1000

100

010

001

1

z

y

x

EYE

EYE

EYE

T

Page 34: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Viewing Normalization

Three rotations

Rotate about Y

Rotate about X

Rotate about Z

Page 35: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

X

Y

Z

X

Y

Z

X

Y

Z

X

Y

Z

Y rotation

X rotation

Z rotation

UP

E-C

Page 36: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Viewing Normalization

we c

e c

uup w

up w

v w u

| |

| |

u

v

w

u u u

v v v

w w w

x

y

z

x y z

x y z

x y z

1

0

0

0

0 0 0 1 1

Figuring out [u, v, w] in [x, y, z] system

Applying a rotation to transform [x, y, z]

coordinates into [u, v, w] coordinates

Page 37: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Rotate EYE coordinate to align w. world system

X

YZ

u

v

wX

Y

Z

u

v

w

Page 38: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Shear

X

Y

Z

u

v

wX

Y

Z

u

v

),2

,2

( nearbottomtoprightleft

),0,0( near

near

bottomtop

bnear

rightleft

a

b

a

SH

2,2

,

1000

0100

010

001

w

Page 39: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Scale into canonical volume

-z

Y2

bottomtop

near far

-z

Y -1

45o

)1,

2

,

2

(1 bottomtop

near

leftright

nearS

)1

,1

,1

(2farfarfar

S

• scale in x and y

• scale in z

2

bottomtop

Page 40: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Example

101

)0,20(),()0,20(),(

)0,1,0()0,0,0(

)10,10,10(

BF

bottomtopleftright

UPCENTEREYE

X

Y

Z

Page 41: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

• Translate EYE into the origin

T1

1 0 0 10

0 1 0 10

0 0 1 10

0 0 0 1

Rotate EYE to align with the world system

R

1

20

1

20

1

6

2

6

1

60

1

3

1

3

1

30

0 0 0 1

)1,2,1(6

1)1,0,1()1,1,1(

6

12

)1,0,1(

|)1,1,1()0,1,0(|

)1,1,1()0,1,0(

||

3

)1,1,1(

||

uwv

wUP

wUPu

ce

cew

Page 42: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

• Shear

102,102

,

1000

0100

01010

01001

near

bottomtop

bnear

rightleft

a

SH

Page 43: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

• Scale into canonical volume

• scale in x and y

• scale in z

1000

0100

0010

10

00010

1

1S

1000

010

100

0010

10

00010

1

1S

Page 44: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Comparing Canonical Volumes

One additional division is needed in perspective

Z

Y

Y=-Z

Y=Z

Z=-1

Z=Zmin

45^o

Z

Y Y=1

Y=-1

Z=-1

(A,B,C) (A,B) (A,B,C)(A/C,B/C)

far plane=film

near plane

(1,-1)

(-1,-1)

(1,-1)

(-1,-1)

Page 45: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Matrix Magic

Try this:

Map perspective volume into parallel volume to

save the division (note Zmin is NEGATIVE)

Computer Graphics

1

0

1

0

0

0

1

0

0100

11

100

0010

0001

1

0

1

0

0

0

1

0

0100

11

100

0010

0001

0100

11

100

0010

0001

min

min

min

min

min

min

min

min

min

min

min

min

min

min

'

min

min

min

z

z

z

z

z

z

z

z

z

z

z

z

z

z

MNN

z

z

z

M

perper

Page 46: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Normalization TransformParallel (othographic) - OpenGL

External parameters

Translate EYE into origin

Even though eye is not really where the viewer is

Rotate the EYE coordinate system such that w (e-c) becomes z

u becomes x

v becomes y

Internal parameters

Translate to have centerline of the view volume

aligning with z, and near plane at z=0

Scale into canonical rectangular piped

Page 47: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Viewing Normalization

Line up (X-Y-Z) and (U-V-W)

Initially, (U-V-W) are specified in (X-Y-Z)

system (In fact, everything is specified in

X-Y-Z system)

Some point in time, want to specify things

in (U-V-W) system, or U becomes (1,0,0),

V becomes (0,1,0), W becomes (0,0,1)

Translation (easy) + Rotation (hard)

Page 48: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Translate EYE into the origin

X

Y

Z

u

v

w

X

Y

Z

u

v

w

1000

100

010

001

1

z

y

x

EYE

EYE

EYE

T

Page 49: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Viewing Normalization

Three rotations

Rotate about Y

Rotate about X

Rotate about Z

Page 50: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

X

Y

Z

X

Y

Z

X

Y

Z

X

Y

Z

Y rotation

X rotation

Z rotation

UP

E-C

Page 51: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Viewing Normalization

we c

e c

uup w

up w

v w u

| |

| |

u

v

w

u u u

v v v

w w w

x

y

z

x y z

x y z

x y z

1

0

0

0

0 0 0 1 1

Figuring out [u, v, w] in [x, y, z] system

Applying a rotation to transform [x, y, z]

coordinates into [u, v, w] coordinates

Page 52: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Rotate EYE coordinate to align w. world system

X

YZ

u

v

wX

Y

Z

u

v

w

Page 53: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Translation

X

Y

Z

u

v

wX

Y

Z

u

v

),2

,2

( nearbottomtoprightleft

)0,0,0(

nearcbottomtop

brightleft

a

c

b

a

T

,2

,2

,

1000

100

010

001

w

Page 54: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Scale into canonical volume

-z

Y 2

bottomtop

near Far-near

)1

,

2

1,

2

1(

nearfarbottomtopleftrightS

• scale in x, y, and z

2

bottomtop

-z

Y 1

near -1

1

Page 55: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

Example

101

)0,20(),()0,20(),(

)0,1,0()0,0,0(

)10,10,10(

BF

bottomtopleftright

UPCENTEREYE

X

Y

Z

Page 56: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

• Translate EYE into the origin

T1

1 0 0 10

0 1 0 10

0 0 1 10

0 0 0 1

Rotate EYE to align with the world system

R

1

20

1

20

1

6

2

6

1

60

1

3

1

3

1

30

0 0 0 1

)1,2,1(6

1)1,0,1()1,1,1(

6

12

)1,0,1(

|)1,1,1()0,1,0(|

)1,1,1()0,1,0(

||

3

)1,1,1(

||

uwv

wUP

wUPu

ce

cew

Page 57: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

• Translation

102,102

,

1000

1000

10010

10001

near

bottomtop

bnear

rightleft

a

SH

Page 58: Assignment #3 - sites.cs.ucsb.eduyfwang/courses/cs180/notes/opengltheory.pdf · Assignment #3 As a graphics ... normalization transform. Computer Graphics Changes Modeling + Viewing

Computer Graphics

• Scale into canonical volume

• scale in x, y, and z

1000

09

100

0010

10

00010

1

1S