Top Banner
Geometric Transforms Changing coordinate systems
39

Geometric Transforms

Jan 01, 2016

Download

Documents

garth-wall

Geometric Transforms. Changing coordinate systems. The plan. Describe coordinate systems and transforms Introduce homogeneous coordinates Introduce numerical integration for animation Later: camera transforms physics more on vectors and matrices. World Coordinates. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Geometric Transforms

Geometric Transforms

Changing coordinate systems

Page 2: Geometric Transforms

The plan

• Describe coordinate systems and transforms• Introduce homogeneous coordinates• Introduce numerical integration for animation

• Later:– camera transforms– physics– more on vectors and matrices

Page 3: Geometric Transforms

World Coordinates

• Objects exist in the world without need for coordinate systems

• But, describing their positions is easier with a frame of reference

• “World” or “object-space” or “global” coordinates

Page 4: Geometric Transforms

Screen vs World Coordinates

• Some objects only exist on the screen– mouse pointer, “radar” display, score, UI elements

• Screen coordinates typically 2D Cartesian– x, y

• Objects in the world also appear on the screen – need to project world coordinates to screen coordinates– camera transform

Page 5: Geometric Transforms

Coordinate Transforms

• A Cartesian coordinate system has three things:

• an origin – reference point measurements are taken from

• axes – canonical directions• scale – meaning of units of distance

Page 6: Geometric Transforms

Types of transforms

• Translation– moving in a fixed position

• Rotation– changing orientation

• Scale– changing size

• All can be viewed either as affecting the model or as affecting the coordinate system

Page 7: Geometric Transforms

Changing coordinate systems

• Translation: changing the origin of the coordinate system

(0,0)

(0,0)

(5,13)

(2,12)

Page 8: Geometric Transforms

Changing coordinate systems

• Rotation: changing the axes of the coordinate system

(0,0)

(0,0)

(5,5)

(7,1)

Page 9: Geometric Transforms

Changing coordinate systems

• Scaling: changing the units of the coordinate system

(0,0)

(0,0)

(4,4)(8,8)

Page 10: Geometric Transforms

Matrix Transforms

• For "simplicity"s sake, we want to represent our transforms as matrix operations

• Why is this simple?– single type of operation for all transforms– IMPORTANT: collection of transforms can be

expressed as a single matrix• efficiency

Page 11: Geometric Transforms

Scaling

• If we express our 2D coordinates as (x,y), scaling by a factor a multiplies each coordinate: so (ax, ay)

• Can write as a matrix multiplication:

a 0

0 b

x

y

ax

by=

Page 12: Geometric Transforms

Scaling Syntax

Matrix.CreateScale( s );– scalar argument s describes amount of scaling

• alternatively,

Matrix.CreateScale( v );– vector argument v describes scale amount in x y z

Page 13: Geometric Transforms

Rotation

• Similarly, rotating a point by an angle θ:– (x,y) (x cos θ - y sin θ, x sin θ + y cos θ)

cos θ -sin θ

sin θ cos θ

x

y

x cos θ – y sin θ

x sin θ + y cos θ =

Page 14: Geometric Transforms

Rotation Syntax

Matrix.CreateRotationZ(angle)

• Note, specify the axis about which the rotation occurs– also have CreateRotationX, CreateRotationY

• argument is angle of rotation, in radians

Page 15: Geometric Transforms

Translation

• Translating a point by a vector involves a vector addition:

– (x,y) + (s,t) = (x+s, y+t)

Page 16: Geometric Transforms

Translation

• Translating a point by a vector involves a vector addition:

– (x,y) + (s,t) = (x+s, y+t)

• Problem: cannot compose multiplications and additions into one operation

Page 17: Geometric Transforms

Coordinate Transforms

• Scaling: p’ = Sp• Rotation: p’ = Rp

• Translation: p’ = t + p• Problem: Translation is treated differently.

Page 18: Geometric Transforms

Homogeneous Coordinates

• Add an extra coordinate w• 2D point written (x,y,w)• Cartesian coordinates of this point are (x/w,

y/w)– w=0 represents points at infinity and should be

avoided if representing location• [Aside: w=0 also used to represent vector, e.g., normal]

– in practice, usually have w=1

Page 19: Geometric Transforms

Translation now

• (x,y,1) + (s,t,0) = (x+s,y+t, 1)

1 0 s

0 1 t

0 0 1

x

y

1

x+s

y+t

1

=

Page 20: Geometric Transforms

Composing Translations

1 0 s1

0 1 t1

0 0 1

1 0 s2

0 1 t2

0 0 1

1 0 s1+s2

0 1 t1+t2

0 0 1

=

Page 21: Geometric Transforms

Translation Syntax

Matrix.CreateTranslation( v );

– vector v is the translation vector

• Also,

Matrix.CreateTranslation( x, y, z);– x, y, z are scalars (floats)

Page 22: Geometric Transforms

Composing Transformations

• Rotation, scale, and translate are all matrix multiplications

• We can compose an arbitrary sequence of transformations into one matrix

• C = T0T1…Tn-1Tn

• Remember – order matters• In XNA, later transforms are added on the

right

Page 23: Geometric Transforms

Kinds of Transformations

• Rigid transformations– composed of only rotations and translations– preserve distances between points

• Affine transformations– include scales– preserve parallelism of lines– distances and angles might change

Page 24: Geometric Transforms

More on Rotations

• R matrix we wrote allows rotation about origin

• Usually, origin and point of rotation do not coincide

Page 25: Geometric Transforms

More on Rotations

• Want to rotate about arbitrary point• How to achieve this?

Page 26: Geometric Transforms

More on Rotations

• Want to rotate about arbitrary point• How to achieve this?• Composite transform

– first translate to origin– next, rotate desired amount– finally, translate back– C = T-1RT

Page 27: Geometric Transforms

More on Order of Operations

• AB != BA in general• But, AB = BA if:

– A is translation, B is translation– A is scale, B is scale– A is rotation, B is rotation– A is rotation, B is scale (that preserves aspect

ratio)

• All in two dimensions, note

Like transforms commute

Page 28: Geometric Transforms

ISROT

• ISROT: a mnemonic for the order of transformations– Identity: gets you started– Scale: change the size of your model– Rotation: rotate in place– Orbit: rotate about an external point

• first translate• then rotate (about origin)

– Translation: move to final position

Page 29: Geometric Transforms

3D transforms

• Translation same as in 2D– use 4D homogeneous coordinates x,y,z,w

• Scaling same as 2D• For rotation, need to specify axis

– unique in 2D, but different possibilities available in 3D

– can represent any 3D rotation by a composition of rotations about axes

Page 30: Geometric Transforms

Transforming objects

• So far, talked about transforming points• How about objects?

• Lines get transformed sensibly with transforms on endpoints

• Polygons same, mutatis mutandis

Page 31: Geometric Transforms

Hierarchical Models

• Many times, structures (and models) will be built as a hierarchy:

Body

Arm Other limbs...

Hand

Thumb other fingers...

Page 32: Geometric Transforms

Transforms on Hierarchies

• Transforms applied to nodes higher in the hierarchy are also applied to lower nodes– parent transforms propagate to children

• How to achieve this?• Simple: multiply your transform with your

parent's transform• May want a stack for hierarchy management

– push transform on descending– pop when current node finished

Page 33: Geometric Transforms

Transforms on Hierarchies

• pseudocode for computing final transform: applyWorld = myWorld * parentWorld;

• applyWorld is the final transform• myWorld is the local transform• parentWorld is the parent node's transform• The power of matrix transforms! Complex

hierarchical models can be expressed simply.

Page 34: Geometric Transforms

Moving objects

• Want to get things to move• Can adjust transform parameters

– translation amount– rotation, orbit angles

• Just incorporate changes into Update()• Need to do this in a disciplined way

Page 35: Geometric Transforms

Speed position

• If we know – where an object started– how fast it is moving (and the direction)– and how much time has passed

• we can figure out where it is now

• x(t + dt) = x(t) + v(t)dt• Numerical integration!

Page 36: Geometric Transforms

Euler integration

• Assumes constant speed within a timestep– still gives an answer if speed changes, but answer

might be wrong

• x(t + dt) = x(t) + v(t)dt• "Explicit integration"• Most commonly used in graphics/game

applications

Page 37: Geometric Transforms

Implementation

• Time available in Update as gameTimeobject.position += object.velocity *

gameTime.ElapsedGameTime.TotalSeconds;– if speed expressed in distance units per second– assumes that position and velocity are vectors– may have some way of updating velocity

• physics, player control, AI, ...

• Similar approach for angle updates (need angular velocity)

Page 38: Geometric Transforms

Recap

• How to use world transformations– scale, rotate, translate

• Use of homogeneous coordinates for translation

• Order of operations– ISROT

• Animation and Euler integration

Page 39: Geometric Transforms

Future lectures

• matrix and vector math• camera transformations• illumination and texture• particle systems

– linear physics