1/50 cs148: introduction to computer graphics and imaging transforms cs148: introduction to computer...

Post on 21-Jan-2016

233 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1/50

CS148: Introduction to Computer Graphics and Imaging

Transforms

CS148: Introduction to Computer Graphics and Imaging

Transforms

2/50

© Louie Psihoyos

http://www.youtube.com/watch?v=46mcpqOVN08

3/50

Rotate

glRotatef(angle,ax,ay,az)

4/50

Translate

glTranslatef(tx,ty,tz)

5/50

Scale

Uniform

Nonuniform

glScalef(sx,sy,sz)

6/50

Transformations

What? Just functions acting on points

(x’,y’,z’) = T(x,y,z)

P’ = T(P)

Why?

Viewing■ Window coordinates to framebuffer coordinates

■ Virtual camera: parallel/perspective projections

Modeling■ Create objects in convenient coordinates

■ Multiple instances of a prototype shape

■ Kinematics of linkages/skeletons - characters/robots

7/50

Scale

8/50

Scale

9/50

Reflection

10/50

Shear

11/50

Linear Transform = Matrices

12/50

Lines Map to Lines→ Linear Transform

13/50

Non-Linear Transform!

Lines Map to Curves

14/50

Parametric Form of a Line

15/50

Linear Transform→ Lines Map to Lines

Start with the parametric form of a line

Transform all the points on the line

Thus, a line transforms into a linear

combination of transformed points,

which is a line

16/50

Coordinate System

An origin o and two unit vectors x, y define a frame of reference

17/50

Points are Defined wrt to the Frame

18/50

Coordinate Frames

Can interpret the columns of the matrix

as the x and y axes that define the frame

19/50

Rotation Matrix?

20/50

Rotation Matrix

Setting the columns of the matrix

to the x and y axes

creates the transform from that frame

21/50

Rotation Matrix

22/50

23/50

Translate??

24/50

Solution: Homogenous Coordinates

25/50

Vectors

26/50

Composing Transformations

27/50

Rotate, Then Translate

R(45) T(1,1) R(45)

28/50

Translate, Then Rotate

T(1,1) R(45) T(1,1)

29/50

Order Matters

R(45) T(1,1)T(1,1) R(45) ≠

30/50

Rotate 45 about the Center (1,1)?

31/50

Rotate 45 @ (1,1)

T(-1,-1)

T(1,1) R(45) T(-1,-1)

R(45)

T(1,1)

32/50

Order of Transformations

The rightmost transform is applied first

P’ = T(1,1) (R(45)(P))

That is, the rotate is applied before the translate

OpenGL

glTranslatef( 1.0, 1.0, 0.0 );

glRotatef( 45.0, 0., 0., 1. );

The last gl call is applied first; we’ll see why later

33/50

Advantages of the Matrices

Combine a sequence of transforms into

a single transform

P’ = A ( B ( C ( D ( p ) ) ) )

= ( A B C D ) P

= M P

Why? Matrix multiplication is associative

Advantages■ Very inefficient to recompute the matrix entries

■ Very inefficient to multiply matrix times point multiple times

■ Compute the matrix M once and then apply that matrix to many points

34/50

Transforming Points

vs.

Transforming Coordinate Systems

35/50

Transforming the Coordinate System

T(1,1)

R(45) T(1,1)

Transforms are defined wrt the Global/World C.S.

R(45)

T(1,1) R(45)

36/50

Transforming the Coordinate System

T(1,1)

T(1,1) R(45)

R(45)

R(45) T(1,1)

Transforms are defined wrt the Local/Object C.S.

37/50

Two Interpretations are Equivalent

T(1,1)

R(45) T(1,1)

R(45)

R(45) T(1,1)

World: Read right to left Object: Read left to right

38/50

Two Interpretations are Equivalent

R(45)

T(1,1) R(45)

T(1,1)

T(1,1) R(45)

World: Read right to left Object: Read left to right

39/50

Two Interpretations are Equivalent

R(45)

T(1,1) R(45)

T(1,1)

T(1,1) R(45)

World: Read right to left Object: Read left to right

Object way will be veryuseful when creatinghierarchies

40/50

Hierarchical Transformations

41/50

Skeleton

body torso head shoulder larm upperarm lowerarm hand rarm upperarm lowerarm hand hips lleg upperleg lowerleg foot rleg upperleg lowerleg foot

42/50

Skeletons and Linkages

1. Skeleton represents the hierarchy of an assembly of parts

- The arm is made of an upper arm and a lower arm

- Different parts may have the same shape, i.e. are “geometric instances”

2. Parts connected by joints

- “The ankle joint is connected to the knee joint”

- Different types of joints move differently

e.g. a ball and socket joint, a linear actuator

43/50

How Linkages Work

Lower levels of the hierarchy move when the upper levels moves

■ e.g. moving the left shoulder moves the left arm and the left hand

Motion in one sub-tree does not effect the position of a part in another sub-tree

■ e.g. moving the left hand does not effect the right hand

44/50Pat Hanrahan, Fall 2011

Skeleton

Text

translate(0,4,0);torso();pushmatrix(); translate(0,3,0); shoulder(); pushmatrix(); rotatey(necky); rotatex(neckx); head(); popmatrix(); pushmatrix(); translate(1.5,0,0); rotatex(lshoulderx); upperarm(); pushmatrix(); translate(0,-2,0); rotatex(lelbowx); lowerarm(); ... popmatrix(); popmatrix();...

translate(0,4,0);torso();pushmatrix(); translate(0,3,0); shoulder(); pushmatrix(); rotatey(necky); rotatex(neckx); head(); popmatrix(); pushmatrix(); translate(1.5,0,0); rotatex(lshoulderx); upperarm(); pushmatrix(); translate(0,-2,0); rotatex(lelbowx); lowerarm(); ... popmatrix(); popmatrix();...

45/50

OpenGL

46/50

Current Transformation Matrix

OpenGL maintains a current transformation matrix (CTM).

All geometry is transformed by the CTM.

Transformation commands are concatenated onto the CTM on the right.

CTM *= T

This causes T to be applied before the old CTM

47/50

OpenGL Matrix Functions

glLoadIdentity( )

■ Set the transform matrix to the identity matrix

glLoadMatrix( matrix M )

■ Replace the transform matrix with M

glMultMatrix( matrix M )

■ Multiplies transform matrix by CTM * M

■ glRotate, glTranslate, glScale etc. are just wrappers for glMultMatrix

48/50

Graphics Coordinate Frames

Object

■ Raw values as provided by glVertex (ex. teacup centered at origin)

World

■ Object at final location in environment (ex. teacup recentered to be on top of a table)

Screen

■ Object at final screen position

49/50

OpenGL Matrix Functions

glMatrixMode( mode )

■ Sets which transformation matrix to modify

■ GL_MODELVIEW: object to world transform

■ GL_PROJECTION: world to screen transform

■ CTM = GL_PROJECTION * GL_MODELVIEW

Why? May need to transform by one of these matrices for certain calculations like lighting. More on this latter.

50/50

OpenGL Matrix Stack

Save and restore transformations

glPushMatrix ( )

■ Pushes the current matrix onto the top of the matrix stack

glPopMatrix ( )

■ Pops the matrix off the top of the matrix stack and loads it as the current matrix

top related