Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear...

17
Gopi -ICS280F02 - Slide 1 Model Transformations Model Transformations

Transcript of Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear...

Page 1: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 1

Model TransformationsModel Transformations

Page 2: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 2

Popular Linear TransformationsPopular Linear Transformations

• TranslationTranslation

• ScalingScaling

• Rotation Rotation

• ShearShear

Page 3: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 3

TranslationTranslation

• Translation is displacement of a point by a vector.Translation is displacement of a point by a vector.

• Translation of an object is achieved by displacing Translation of an object is achieved by displacing every point belonging to that object by the same every point belonging to that object by the same vector.vector.

• A vector cannot be “translated”.A vector cannot be “translated”.

• Point P: (x,y,z) Vector V:(tx,ty,tz) then Point P: (x,y,z) Vector V:(tx,ty,tz) then Translated Point TP:(x+tx, y+ty, z+tz)Translated Point TP:(x+tx, y+ty, z+tz)

Page 4: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 4

Using matrix for translationUsing matrix for translation

• Point P: (x,y,z,1) (Homogeneous representation)Point P: (x,y,z,1) (Homogeneous representation)

• Translation Vector V: (tx,ty,tz)Translation Vector V: (tx,ty,tz)

11 00 00 txtx

00 11 00 tyty

00 00 11 tztz

00 00 00 11

xx

yy

zz

11

=

x+txx+tx

y+tyy+ty

z+tzz+tz

11

Page 5: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 5

Example translationExample translation

Page 6: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 6

RotationRotation

• Rotation (in 3D) requires an axis and an angle (Rotation (in 3D) requires an axis and an angle (rr).).

• The equation changes with the coordinate system The equation changes with the coordinate system (right handed or left handed system)(right handed or left handed system)

• In graphics, assume right handed system unless In graphics, assume right handed system unless otherwise specified. (OpenGL uses right handed otherwise specified. (OpenGL uses right handed system.)system.)

Page 7: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 7

Matrix for Rotation about ZMatrix for Rotation about Z

r (x,y)

(x’,y’)

cos(cos(rr)) -sin(-sin(rr)) 00 00

sin(sin(rr)) cos(cos(rr)) 00 00

00 00 11 00

00 00 00 11

xx

yy

zz

11

=

x’x’

y’y’

z’z’

11

X

Y

Z axis is pointing out of the screen)

Page 8: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 8

Matrix for Rotation about X and YMatrix for Rotation about X and Y

cos(cos(rr)) 00 sin(sin(rr)) 00

00 11 00 00

-sin(-sin(rr)) 00 cos(cos(rr)) 00

00 00 00 11

xx

yy

zz

11

=

x’x’

y’y’

z’z’

11

11 00 00 00

00 cos(cos(rr)) -sin(-sin(rr)) 00

00 sin(sin(r)r) cos(cos(rr)) 00

00 00 00 11

xx

yy

zz

11

=

x’x’

y’y’

z’z’

11

Page 9: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 9

Matrix for ScalingMatrix for Scaling

(x,y)

(sxx,syy)

ssxx00 00 00

00 ssyy00 00

00 00 sszz00

00 00 00 11

xx

yy

zz

11

=

ssxxxx

ssyyyy

sszzzz

11

X

Y

Z axis is pointing out of the screen)

=

x’x’

y’y’

z’z’

11

Page 10: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 10

ShearShear

• Translation of one coordinate of a point is Translation of one coordinate of a point is proportional to the ‘value’ of the other coordinate proportional to the ‘value’ of the other coordinate of the same point.of the same point.– Point : (x,y)Point : (x,y)– After ‘y-shear’: (x+ay,y)After ‘y-shear’: (x+ay,y)– After ‘x-shear’: (x,y+bx)After ‘x-shear’: (x,y+bx)

• Changes the shape of the object.Changes the shape of the object.

Page 11: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 11

Using matrix for ShearUsing matrix for Shear

• Example: Z-shear (Z coordinate does not change)Example: Z-shear (Z coordinate does not change)

11 00 aa 00

00 11 bb 00

00 00 11 00

00 00 00 11

xx

yy

zz

11

=

x+azx+az

y+bzy+bz

zz

11

=

x’x’

y’y’

z’z’

11

Page 12: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 12

Composition of TransformationsComposition of Transformations

• Example: A point P is first translated and then rotated. Example: A point P is first translated and then rotated. Translation matrix T, Rotation Matrix R.Translation matrix T, Rotation Matrix R.

– After Translation: P’= TPAfter Translation: P’= TP– After Rotation: P’’=RP’=RTPAfter Rotation: P’’=RP’=RTP

• Example: A point is first rotated and then translated.Example: A point is first rotated and then translated.– After Rotation: P’= RPAfter Rotation: P’= RP– After Translation: P’’=TP’=TRPAfter Translation: P’’=TP’=TRP

• Since matrix multiplication is not commutative, Since matrix multiplication is not commutative, – RTP = TRPRTP = TRP

Page 13: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 13

Composition of TransformationsComposition of Transformations

X

Y

X

Y

X

Y

T

R

X

Y

X

Y

X

Y

TR

TRP

RTP

Page 14: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 14

Coordinate SystemsCoordinate Systems

• You Say: A point P is “first translated” and “then You Say: A point P is “first translated” and “then rotated”. rotated”.

• You Write: P’ = RTP (write Rotation first, then You Write: P’ = RTP (write Rotation first, then translation, then the point)translation, then the point)

• Say: “Global Coordinate System”Say: “Global Coordinate System”

• Write: “Local Coordinate System”Write: “Local Coordinate System”

• Results of both are same. Interpretation is Results of both are same. Interpretation is different.different.

Page 15: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 15

Local / Global Coordinate SystemsLocal / Global Coordinate Systems

X

Y

X

Y

X

Y

X

Y

X

Y

X

Y

“Local” Y

“Local

” X “Local” Y

“Local

” X

GCS: You say “point is first translated and then rotated”

LCS: You say as you write: “RTP”

Page 16: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 16

Coordinate SystemsCoordinate Systems

OpenGL follows LOCAL COORDINATE SYSTEMOpenGL follows LOCAL COORDINATE SYSTEM

glTranslate(…)glTranslate(…)

glRotate(…)glRotate(…)

glScale(…)glScale(…)

DrawModel()DrawModel()

Means: TRS.P Means: TRS.P

(You issue transformation commands in the order your write!!)(You issue transformation commands in the order your write!!)

Page 17: Gopi -ICS280F02 - Slide 1 Model Transformations. Gopi -ICS280F02 - Slide 2 Popular Linear Transformations TranslationTranslation ScalingScaling RotationRotation.

Gopi -ICS280F02 - Slide 17

EndEnd