Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transformations.

Similar presentations


Presentation on theme: "Transformations."— Presentation transcript:

1 Transformations

2 Last Time? Ray representation Generating rays from eye point / camera
orthographic camera perspective camera Find intersection point & surface normal Primitives: spheres, planes, polygons, triangles, boxes

3 Assignment 0 – main issues
Respect specifications! Don’t put too much in the main function Use object-oriented design Especially since you will have to build on this code Perform good memory management Use new and delete Avoid unnecessary temporary variables Use enough precision for random numbers Sample a distribution using cumulative probability

4 Outline Intro to Transformations Classes of Transformations
Representing Transformations Combining Transformations Transformations in Modeling Adding Transformations to our Ray Tracer

5 What is a Transformation?
Maps points (x, y) in one coordinate system to points (x', y') in another coordinate system For example, IFS: x' = ax + by + c y' = dx + ey + f

6 Simple Transformations
Can be combined Are these operations invertible? Yes, except scale = 0

7 Transformations are used:
Position objects in a scene (modeling) Change the shape of objects Create multiple copies of objects Projection for virtual cameras Animations

8 Outline Intro to Transformations Classes of Transformations
Representing Transformations Combining Transformations Transformations in Modeling Adding Transformations to our Ray Tracer

9 Rigid-Body / Euclidean Transforms
Preserves distances Preserves angles Rigid / Euclidean Identity Translation Rotation

10 Similitudes / Similarity Transforms
Preserves angles Similitudes Rigid / Euclidean Identity Translation Isotropic Scaling Rotation

11 Linear Transformations
Similitudes Linear Rigid / Euclidean Scaling Identity Translation Isotropic Scaling Reflection Rotation Shear

12 Linear Transformations
L(p + q) = L(p) + L(q) L(ap) = a L(p) Similitudes Linear Rigid / Euclidean Scaling Identity Translation Isotropic Scaling Reflection Rotation Shear

13 Affine Transformations
preserves parallel lines Affine Similitudes Linear Rigid / Euclidean Scaling Identity Translation Isotropic Scaling Reflection Rotation Shear

14 Projective Transformations
preserves lines Projective Affine Similitudes Linear Rigid / Euclidean Scaling Identity Translation Isotropic Scaling Reflection Rotation Shear Perspective

15 Perspective Projection

16 General (free-form) transformation
Does not preserve lines Not as pervasive, computationally more involved Won’t be treated in this course From Sederberg and Parry, Siggraph 1986

17 Outline Intro to Transformations Classes of Transformations
Representing Transformations Combining Transformations Transformations in Modeling Adding Transformations to our Ray Tracer

18 How are Transforms Represented?
x' = ax + by + c y' = dx + ey + f x' y' a b d e x y c f = + p' = M p t

19 Homogeneous Coordinates
Add an extra dimension in 2D, we use 3 x 3 matrices In 3D, we use 4 x 4 matrices Each point has an extra value, w x' y' z' w' a e i m b f j n c g k o d h l p x y z w = p' = M p

20 Translation in homogenous coordinates
x' = ax + by + c y' = dx + ey + f Affine formulation Homogeneous formulation x' y‘ 1 a b d e 0 0 c f 1 x y 1 x' y' a b d e x y c f = = + p' = M p t p' = M p

21 Homogeneous Coordinates
Most of the time w = 1, and we can ignore it If we multiply a homogeneous coordinate by an affine matrix, w is unchanged x' y' z' 1 a e i b f j c g k d h l 1 x y z 1 =

22 Homogeneous Visualization
Divide by w to normalize (homogenize) W = 0? Point at infinity (direction) (0, 0, 1) = (0, 0, 2) = … w = 1 (7, 1, 1) = (14, 2, 2) = … (4, 5, 1) = (8, 10, 2) = … w = 2

23 Translate (tx, ty, tz) Translate(c,0,0) y Why bother with the extra dimension? Because now translations can be encoded in the matrix! p p' x c x' y' z' 1 x' y' z' 1 1 1 tx ty tz 1 x y z 1 =

24 Scale (sx, sy, sz) Isotropic (uniform) scaling: sx = sy = sz x' y' z'
Scale(s,s,s) y p' Isotropic (uniform) scaling: sx = sy = sz p q' q x x' y' z' 1 sx sy sz 1 x y z 1 =

25 Rotation About z axis x' y' z' 1 cos θ sin θ -sin θ cos θ 1 1 x y z 1
ZRotate(θ) y p' About z axis θ p x z x' y' z' 1 cos θ sin θ -sin θ cos θ 1 1 x y z 1 =

26 Rotation Rotate(k, θ) y About (kx, ky, kz), a unit vector on an arbitrary axis (Rodrigues Formula) θ k x z x' y' z' 1 kxkx(1-c)+c kykx(1-c)+kzs kzkx(1-c)-kys kzkx(1-c)-kzs kzkx(1-c)+c kzkx(1-c)-kxs kxkz(1-c)+kys kykz(1-c)-kxs kzkz(1-c)+c 1 x y z 1 = where c = cos θ & s = sin θ

27 Storage Often, w is not stored (always 1)
Needs careful handling of direction vs. point Mathematically, the simplest is to encode directions with w=0 In terms of storage, using a 3-component array for both direction and points is more efficient Which requires to have special operation routines for points vs. directions

28 Outline Intro to Transformations Classes of Transformations
Representing Transformations Combining Transformations Transformations in Modeling Adding Transformations to our Ray Tracer

29 How are transforms combined?
Scale then Translate (5,3) Scale(2,2) (2,2) Translate(3,1) (1,1) (3,1) (0,0) (0,0) Use matrix multiplication: p' = T ( S p ) = TS p 1 1 1 3 1 1 2 2 1 2 2 3 1 TS = = Caution: matrix multiplication is NOT commutative!

30 Non-commutative Composition
Scale then Translate: p' = T ( S p ) = TS p (5,3) Scale(2,2) (2,2) Translate(3,1) (1,1) (3,1) (0,0) (0,0) Translate then Scale: p' = S ( T p ) = ST p (8,4) Translate(3,1) (4,2) Scale(2,2) (1,1) (6,2) (3,1) (0,0)

31 Non-commutative Composition
Scale then Translate: p' = T ( S p ) = TS p 1 1 3 1 2 2 1 2 2 3 1 TS = = Translate then Scale: p' = S ( T p ) = ST p 2 1 2 1 1 1 3 1 1 2 2 6 2 ST = =

32 Today Intro to Transformations Classes of Transformations
Representing Transformations Combining Transformations Transformations in Modeling Adding Transformations to our Ray Tracer

33 Transformations in Modeling
Position objects in a scene Change the shape of objects Create multiple copies of objects Projection for virtual cameras Animations

34 Scene Description Scene Materials (much more next week) Camera Lights
Background Objects

35 Simple Scene Description File
OrthographicCamera { center direction up 0 1 0 size 5 } Lights { numLights 1 DirectionalLight { direction color } } Background { color } Materials { numMaterials <n> <MATERIALS> } Group { numObjects <n> <OBJECTS> }

36 Class Hierarchy Object3D Cone Sphere Cylinder Triangle Plane Group

37 Why is a Group an Object3D?
Logical organization of scene

38 Ray-group intersection
Recursive on all sub-objects

39 Simple Example with Groups
numObjects 3 Box { <BOX PARAMS> } Box { <BOX PARAMS> } } numObjects 2 Sphere { <SPHERE PARAMS> } Sphere { <SPHERE PARAMS> } } } Plane { <PLANE PARAMS> } }

40 Adding Materials Group { numObjects 3 Material { <BLUE> }
Box { <BOX PARAMS> } Box { <BOX PARAMS> } } numObjects 2 Material { <BROWN> } Material { <GREEN> } Material { <RED> } Sphere { <SPHERE PARAMS> } Material { <ORANGE> } Sphere { <SPHERE PARAMS> } } } Material { <BLACK> } Plane { <PLANE PARAMS> } }

41 Adding Transformations

42 Class Hierarchy with Transformations
Object3D Cone Cylinder Group Sphere Plane Transform Triangle

43 Why is a Transform an Object3D?
To position the logical groupings of objects within the scene

44 Simple Example with Transforms
Group { numObjects 3 Transform { ZRotate { 45 } Box { <BOX PARAMS> } Box { <BOX PARAMS> } } } Translate { } numObjects 2 Box { <BOX PARAMS> } } Sphere { <SPHERE PARAMS> } Sphere { <SPHERE PARAMS> } } } } Plane { <PLANE PARAMS> } }

45 Nested Transforms p' = T ( S p ) = TS p same as Translate Translate
Scale Scale same as Sphere Sphere Transform { Translate { } Scale { } Sphere { center 0 0 0 radius 1 } } } Transform { Translate { } Scale { } Sphere { center 0 0 0 radius 1 } }


Download ppt "Transformations."

Similar presentations


Ads by Google