1 Modeling Transformations  2D Transformations  3D Transformations  OpenGL Transformation.

Slides:



Advertisements
Similar presentations
1Computer Graphics Homogeneous Coordinates & Transformations Lecture 11/12 John Shearer Culture Lab – space 2
Advertisements

Geometric Transformations
CMPE 466 COMPUTER GRAPHICS
Math 1Hofstra University – CSC171A1 Modeling Objects by Polygonal Approximations Define volumetric objects in terms of surfaces patches that surround the.
Transformations II Week 2, Wed Jan 17
Viewing and Transformation
1 Lecture 7 Geometrical Transformations: 2D transformations 3D transformations Matrix representation OpenGL functions.
2/7/2001Hofstra University – CSC290B1 Review: Math (Ch 4)
Modeling Objects by Polygonal Approximations
3-D Geometry.
Hierarchical Modeling II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Computer Graphics with OpenGL 3e
OpenGL (II). How to Draw a 3-D object on Screen?
2IV60 Computer Graphics 2D transformations
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
Hierarchical Transformations Hierarchical Models Scene Graphs
2IV60 Computer graphics set 4:3D transformations and hierarchical modeling Jack van Wijk TU/e.
COS 397 Computer Graphics Svetla Boytcheva AUBG, Spring 2013.
Transformations Aaron Bloomfield CS 445: Introduction to Graphics
C O M P U T E R G R A P H I C S Stuff CMSC 435 / 634 Transformations 1/29 Geometric Transformations Readings: Chapters 5-6.
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
Transformations Dr. Amy Zhang.
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
Graphics Graphics Korea University kucg.korea.ac.kr Transformations 고려대학교 컴퓨터 그래픽스 연구실.
Geometric Transformations Jehee Lee Seoul National University.
Dx = 2 dy = 3 Y X D Translation A translation is applied to an object by repositioning it along a straight-line path.
Geometric transformations The Pipeline
CSE 681 Review: Transformations. CSE 681 Transformations Modeling transformations build complex models by positioning (transforming) simple components.
CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann.
1 Modeling Transformations Md. Tanvir Al Amin* Lecturer, Dept. of CSE, BUET CSE 409 *Special Thanks to Tanvir Parvez, Fredo Durand,
Week 4 Lecture 1: Hierarchical Modeling Part 1 Based on Interactive Computer Graphics (Angel) - Chapter 10 1 Angel: Interactive Computer Graphics 5E ©
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 40 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 40 Computer Graphics Hierarchy I.
Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 4: Transformations 2
Stages of Vertex Transformation To specify viewing, modeling, and projection transformations, you construct a 4 × 4 matrix M, which is then multiplied.
Geometric Objects and Transformation
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
Transformation.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
1/50 CS148: Introduction to Computer Graphics and Imaging Transforms CS148: Introduction to Computer Graphics and Imaging Transforms.
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
Two-Dimensional Geometric Transformations ch5. 참조 Subjects : Basic Transformations Homogeneous Coordinates Composite Transformations Other Transformations.
Geometric Transformations
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
The Camera Analogy ► Set up your tripod and point the camera at the scene (viewing transformation) ► Arrange the scene to be photographed into the desired.
Computer Graphics I, Fall 2008 Hierarchical Modeling II.
David Luebke1/10/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
Geometric Transformations Sang Il Park Sejong University Many slides come from Jehee Lee’s.
Geometric Transformations UBI 516 Advanced Computer Graphics Aydın Öztürk
Taxonomy of Projections FVFHP Figure Taxonomy of Projections.
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell Hierarchical Modeling.
CS552: Computer Graphics Lecture 4: 2D Graphics. Recap 2D Graphics Coordinate systems 2D Transformations o Translation o Scaling o Rotation Combining.
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
CS559: Computer Graphics Lecture 9: 3D Transformation and Projection Li Zhang Spring 2010 Most slides borrowed from Yungyu ChuangYungyu Chuang.
Homogeneous Coordinates and Matrix Representations Cartesian coordinate (x, y, z) Homogeneous coordinate (x h, y h, z h, h) Usually h = 1. But there are.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
Geometric Transformations. Transformations Linear transformations Rigid transformations Affine transformations Projective transformations T Global reference.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
CSCE 441: Computer Graphics: Hierarchical Models Jinxiang Chai.
OpenGL LAB III.
4. Geometric Objects and Transformations
Modeling Transformation
Computer Graphics - Hierarchical Models-
Hierarchical and Object-Oriented Graphics
CSCE 441: Computer Graphics: Hierarchical Models
Modeling Transformations
Hierarchical and Object-Oriented Graphics
Geometric Objects and Transformations (II)
Dr. Chih-Kuo Yeh 葉智國 Computer Graphics Dr. Chih-Kuo Yeh 葉智國
CSCE 441: Computer Graphics: Hierarchical Models
Presentation transcript:

1 Modeling Transformations  2D Transformations  3D Transformations  OpenGL Transformation

2 2D-Transformations  Basic Transformations  Homogeneous coordinate system  Composition of transformations

3 Translation – 2D x’ = x + d x y’ = y + d y

4 Scaling – 2D Types of Scaling:  Differential ( s x != s y )  Uniform ( s x = s y )

Rotation – 2D rotated original

6 Rotation – 2D

7 Mirror Reflection

8 Shearing Transformation

9 Inverse 2D - Transformations

10 Homogeneous Co-ordinates  Translation, scaling and rotation are expressed (non-homogeneously) as: –translation: P = P + T –Scale: P = S · P –Rotate: P = R · P  Composition is difficult to express, since translation not expressed as a matrix multiplication  Homogeneous coordinates allow all three to be expressed homogeneously, using multiplication by 3  matrices  W is 1 for affine transformations in graphics

11 Homogeneous Co-ordinates  P 2d is a projection of P h onto the w = 1 plane  So an infinite number of points correspond to : they constitute the whole line (tx, ty, tw) x y w P h (x,y,w) P 2d (x,y,1) w=1

12 Classification of Transformations 1.Rigid-body Transformation Preserves parallelism of lines Preserves angle and length e.g. any sequence of R(  ) and T(dx,dy) 2.Affine Transformation Preserves parallelism of lines Doesn’t preserve angle and length e.g. any sequence of R(  ), S(sx,sy) and T(dx,dy)

13 Properties of rigid-body transformation The following Matrix is Orthogonal if the upper left 2X2 matrix has the following properties 1.A) Each row are unit vector. sqrt(r 11 * r 11 + r 12 * r 12 ) = 1 B) Each column are unit vector. sqrt(c 11 * c 11 + c 12 * c 12 ) = 1 2.A) Rows will be perpendicular to each other (r 11, r 12 ). ( r 21, r 22 ) = 0 B) Columns will be perpendicular to each other (c 11, c 12 ). (c 21,c 22 ) = 0 e.g. Rotation matrix is orthogonal Orthogonal Transformation  Rigid-Body Transformation For any orthogonal matrix B  B -1 = B T

14 Commutativity of Transformation Matrices In general matrix multiplication is not commutative For the following special cases commutativity holds i.e. M 1.M 2 = M 2.M 1 M1M1 M2M2 Translate Scale Rotate Uniform ScaleRotate Some non-commutative Compositions:  Non-uniform scale, Rotate  Translate, Scale  Rotate, Translate Original Transitional Final

15 Associativity of Matirx Multiplication Create new affine transformations by multiplying sequences of the above basic transformations. q = CBA p q = ( ( CB ) A ) p = ( C ( B A ))p = C ( B ( A p) ) etc. matrix multiplication is associative. But to transform many points, best to do M = CBA then do q = M p for any point p to be rendered. To transform just a point, better to do q = C ( B ( A p)) For geometric pipeline transformation, define M and set it up with the model-view matrix and apply it to any vertex subsequently defined to its setting.

16 Rotation of  about P(h,k): R ,P R ,P = Q(x,y) P(h,k) Step 1: Translate P(h,k) to origin T(-h,-k) Q 1 (x ’,y ’ ) P 1 (0,0) Step 2: Rotate  w.r.t to origin R*R* Q 2 (x ’,y ’ ) P 2 (0,0) Step 3: Translate (0,0) to P(h,k0) T(h,k) * P 3 (h,k) Q 3 (x ’ +h, y ’ +k)

17 Scaling w.r.t. P(h,k): S sx,sy,p T(-h,-k)S(s x,s y )*T(h,k) * S sx,sy,P = (4,3) (1,1)(4,1) S 3/2,1/2,(1,1) Step 1: Translate P(h,k) to origin (4,2) (0,0)(4,0) T(-1,-1) Step 2: Scale S(s x,s y ) w.r.t origin (6,1) (6,0)(0,0) S(3/2,1/2) (7,1) Step 3: Translate (0,0) to P(h,k) (7,2) (1,1) T(1,1)

18 Reflection about line L, M L Step 1: Translate (0,b) to origin T(0,-b)M L = Step 2: Rotate -  degrees Step 3: Mirror reflect about X-axis R(-  ) * T(0,b) * Step 4: Rotate  degrees Step 5: Translate origin to (0,b) M x * R(  ) *

19 Problems to be solved: Schaum’s outline series: Problems:  4.1  4.2  4.3, 4.4, 4.5 => R ,P  4.6, 4.7, 4.8 => S sx,sy,,P  4.9, 4.10, 4.11, 4.21 => M L  4.12 => Shearing  Pg-281(1.24), Pg-320(5.19) => Circular view-port

20 3D Transformations  Basics of 3D geometry  Basic 3D Transformations  Composite Transformations

21 Orientation  Thumb points to +ve Z-axis  Fingers show +ve rotation from X to Y axis

22 Vectors in 3D Have length and direction V = [x v, y v, z v ] Length is given by the Euclidean Norm ||V|| =  ( x v 2 + y v 2 + z v 2 ) Dot Product V U = [x v, y v, z v ][x u, y u, z u ] = x v *x u + y v *y u + z v *z u = ||V|| || U|| cos ß Cross Product V  U = [y v *z u - z v y u, -x v *z u + z v *x u, x v *y u – y v *x u ] =  ||V|| || U|| sin ß V  U = - ( U x V) (xv,yv,zv) V=aI+bJ+cK x y z

23 3D Equation of Curve & Line  Parametric equations of Curve & Line  Curve  Line P 0 (x 0,y 0,z 0 ) P 1 (x 1,y 1,z 1 ) t > 1 V t < 0 t =1 t = 0 0 < t < 1 x y z C

24 3D Equation of Surface & Plane  Parametric equations of Surface & Plane  Surface  Plane : with Normal, N P0P0 N

25 3D Plane  Ways of defining a plane 1. 3 points P 0, P 1, P 2 on the plane 2. Plane Normal N & P 0 on plane 3. Plane Normal N & a vector V on the plane Plane Passing through P 0, P 1, P 2 P0P0 P1P1 P2P2 N V

26 Affine Transformation  Transformation – is a function that takes a point (or vector) and maps that point (or vector) into another point (or vector).  A coordinate transformation of the form: x’ = a xx x + a xy y + a xz z + b x, y’ = a yx x + a yy y + a yz z + b y, z’ = a zx x + a zy y + a zz z + b z, is called a 3D affine transformation.  The 4 th row for affine transformation is always [ ].  Properties of affine transformation: –translation, scaling, shearing, rotation (or any combination of them) are examples affine transformations. –Lines and planes are preserved. –parallelism of lines and planes are also preserved, but not angles and length.

27 Translation – 3D

28 Scaling – 3D Original scale all axes scale Y axis

29 Rotation – 3D For 3D-Rotation 2 parameters are needed  Angle of rotation  Axis of rotation Rotation about z-axis:

30 Rotation about Y-axis & X-axis About x-axis About y-axis

31 Shear along Z-axis y x z

32 Object Transformation  Line: Can be transformed by transforming the end points  Plane:(described by 3-points) Can be transformed by transforming the 3-points  Plane:(described by a point and Normal) Point is transformed as usual. Special treatment is needed for transforming Normal

33 Composite Transformations – 3D Some of the composite transformations to be studied are:  A V,N = aligning a vector V with a vector N  R ,L = rotation about an axis L( V, P )  S sx,sy,P = scaling w.r.t. point P

34 A V : aligning vector V with k A v =R ,i

35 A V : aligning vector V with k A v =R ,i R - ,j *

36 A V : aligning vector V with k  A V -1 = A V T  A V,N = A N -1 * A V

37 R ,L : rotation about an axis L Let the axis L be represented by vector V and passing through point P 1. Translate P to the origin 2. Align V with vector k 3. Rotate  about k 4. Reverse step 2 5. Reverse step 1 R ,L =T -P A V *R ,k * A V -1 *T -P -1 *

38 M N,P : Mirror reflection Let the plane be represented by plane normal N and a point P in that plane x y z N P

39 M N,P : Mirror reflection Let the plane be represented by plane normal N and a point P in that plane 1. Translate P to the origin M N,P =T -P x y z N P

40 M N,P : Mirror reflection Let the plane be represented by plane normal N and a point P in that plane 1. Translate P to the origin 2. Align N with vector k M N,P =T -P A N * N P x y z

41 M N,P : Mirror reflection Let the plane be represented by plane normal N and a point P in that plane 1. Translate P to the origin 2. Align N with vector k 3. Reflect w.r.t xy-plane M N,P =T -P A N *S 1,1,-1 * N P x y z

42 x y z M N,P : Mirror reflection Let the plane be represented by plane normal N and a point P in that plane 1. Translate P to the origin 2. Align N with vector k 3. Reflect w.r.t xy-plane 4. Reverse step 2 M N,P =T -P A N *S 1,1,-1 *A N -1 *

43 M N,P : Mirror reflection Let the plane be represented by plane normal N and a point P in that plane 1. Translate P to the origin 2. Align N with vector k 3. Reflect w.r.t xy-plane 4. Reverse step 2 5. Reverse step 1 M N,P =T -P A N *S 1,1,-1 *A N -1 *T -P -1 * x y z N P

44 Further Composition  The Composite Transform must have –Translation of P 1 to Origin  T z x y T –Some Combination of Rotations  R R x y zz x y Fig. 1 Fig. 2  Translate points in fig. 1 into points in fig 2 such that: –P 3 is moved to yz plane –P 2 is on z-axis –P 1 is at Origin

45 Finding R

46 Finding R z R z x y x y z RzRz

47 R x y z z x y Finding R x RxRx RzRz

48 Finding R y R x y z z x y RxRx RzRz RyRy

49 Problems to be solved: Schaum’s outline series: Problems:  6.1  6.2, 6.5, 6.9, 6.10, 6.11, 6.12  A v  6.3, 6.4  R ,L  6.6, 6.7, 6.8  M N,P

50 Transformations in OpenGL  OpenGL transformation commands  Transformation Order  Hierarchical Modeling

51 Transformations in OpenGL  OpenGL uses 3 stacks to maintain transformation matrices: –Model & View transformation matrix stack –Projection matrix stack –Texture matrix stack  You can load, push and pop the stack  The top most matrix from each stack is applied to all graphics primitive until it is changed M N Model-View Matrix Stack Projection Matrix Stack Graphics Primitives (P) Output NMP

52 General Transformation Commands  Specify current matrix (stack) : –void glMatrixMode(GLenum mode) Mode : GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE  Initialize current matrix. –void glLoadIdentity(void) Sets the current matrix to 4X4 identity matirx –void glLoadMatrix{f|d}(cost TYPE *M) Sets the current matrix to 4X4 matrix specified by M Note: current matrix  Top most matrix of the current matrix stack A B C A B I A B M glLoadMatrix(M) glLoadIdentity

53 General Transformation Commands  Concatenate Current Matrix: –void glMultMatrix(const TYPE *M) Multiplies current matrix C, by M. i.e. C = C*M –Caveat: OpenGL matrices are stored in column major order. –Best use utility function glTranslate, glRotate, glScale for common transformation tasks.

54 Transformations and OpenGL ®  Each time an OpenGL transformation M is called the current MODELVIEW matrix C is altered: glTranslatef(1.5, 0.0, 0.0); glRotatef(45.0, 0.0, 0.0, 1.0); Note: v is any vertex placed in rendering pipeline v’ is the transformed vertex from v.

55 Sample Instance Transformation glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(...); glRotatef(...); glScalef(...); gluCylinder(...);

56 Thinking About Transformations As a Global System  Objects moves but coordinates stay the same  Think of transformation in reverse order as they appear in code As a Local System  Objects moves and coordinates move with it  Think of transformation in same order as they appear in code  There is a World Coordinate System where:  All objects are defined  Transformations are in World Coordinate space Two Different Views

57 Local View  Translate Object  Then Rotate Order of Transformation TR glLoadIdentity(); glMultiMatrixf( T); glMultiMatrixf( R); draw_ the_ object( v); v’ = ITRv Global View  Rotate Object  Then Translate Effect is same, but perception is different

58 Order of Transformation RT glLoadIdentity(); glMultiMatrixf( R); glMultiMatrixf( T); draw_ the_ object( v); v’ = ITRv Local View  Rotate Object  Then Translate Global View  Translate Object  Then Rotate Effect is same, but perception is different

59 Hierarchical Modeling  Many graphical objects are structured  Exploit structure for –Efficient rendering –Concise specification of model parameters –Physical realism  Often we need several instances of an object –Wheels of a car –Arms or legs of a figure –Chess pieces  Encapsulate basic object in a function  Object instances are created in “standard” form  Apply transformations to different instances  Typical order: scaling, rotation, translation

60 OpenGL & Hierarchical Model A B C C glPushMatrix –void glPushMatrix(void); A B glPushMatrix –void glPoipMatrix(void); A B C C m glGetFloatv –void glGetFloatv(GL_MODELVIEW_MATRIX, *m); A B C  Some of the OpenGL functions helpful for hierarchical modeling are:

61 Scene Graph  A scene graph is a hierarchical representation of a scene  We will use trees for representing hierarchical objects such that: –Nodes represent parts of an object –Topology is maintained using parent-child relationship –Edges represent transformations that applies to a part and all the subparts connected to that part typedef struct treenode { GLfloat m[16];// Transformation void (*f) ( );// Draw function struct treenode *sibling; struct treenode *child; } treenode; Scene SunStar X EarthVenusSaturn MoonRing

62 Example - Torso  Initializing transformation matrix for node treenode torso, head,...; /* in init function */ glLoadIdentity(); glRotatef(...); glGetFloatv(GL_MODELVIEW_MATRIX, torso.m);  Initializing pointers torso.f = drawTorso; torso.sibling = NULL; torso.child = &head;

63 Generic Traversal  To render the hierarchy: –Traverse the scene graph depth-first –Going down an edge: push the top matrix onto the stack apply the edge's transformation(s) –At each node, render with the top matrix –Going up an edge: pop the top matrix off the stack

64 Generic Traversal : Torso  Recursive definition void traverse (treenode *root) { if (root == NULL) return; glPushMatrix(); glMultMatrixf(root->m); root->f(); if (root->child != NULL) traverse(root->child); glPopMatrix(); if (root->sibling != NULL) traverse(root->sibling); }  C is really not the right language for this !!

65 Viewing Transformation

66 Viewing Pipeline Revisited xwxw ywyw zwzw pwpw Modeling Transform World Coordinate s PwPw yoyo xoxo zozo popo Graphics Primitives PoPo Object Coordinates yeye xexe -z e pepe Viewing Transform PePe Eye Coordinate s

67 Viewing Transformation in OpenGL  To setup the modelview matrix, OpenGL provides the following function: gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz )

68 Implementation Orthogonal Frame We want to construct an Orthogonal Frame such that, (1)point eye (1) its origin is the point eye (2)point center (2) its -z basis vector points towards the point center (3)up vector (3) the up vector projects to the up direction (+ve y-axis) C Let C (for camera) denote this frame. Clearly,

69 Thank You