Download presentation
Presentation is loading. Please wait.
Published bySimon Fisher Modified over 8 years ago
1
Modeling Transformations Mario Costa Sousa University of Calgary CPSC 453, Fall 2001 Mario Costa Sousa University of Calgary CPSC 453, Fall 2001
2
3D object RENDERING ANIMATION MODELING 2D image IMAGE PROCESSING ~44% ~4% ~8% representation : ~9% IMAGING 10% (~ 35%)
3
1.INTRODUCTION 2.IMAGING 3.3D RENDERING OVERVIEW 4.MODELING (1) shapes and transformations 1.Modeling Transformations 2.Overview of 3D Object Representation 5.RENDERING (1, 2, 3, 4) 6.MODELING (2) 7.ANIMATION 8.TOPICS 1.INTRODUCTION 2.IMAGING 3.3D RENDERING OVERVIEW 4.MODELING (1) shapes and transformations 1.Modeling Transformations 2.Overview of 3D Object Representation 5.RENDERING (1, 2, 3, 4) 6.MODELING (2) 7.ANIMATION 8.TOPICS CPSC 453 – Computer Graphics I
4
3D Scene Representation Approximated by 3D primitives PointPoint Line segmentLine segment PolygonPolygon Curved surfaceCurved surface Solid objectSolid object etc.etc.
5
3D Rendering Pipeline Object definition Compose scene Define view reference Define lighting Cull Clip to 3D view volume Hidden surface removal RasterizationShading Local coordinate space World coordinate space View space 3D screen space Display space Modeling transformation View transformation 1.INTRODUCTION 2.IMAGING 3.3D RENDERING OVERVIEW 4.MODELING (1) shapes and transformations 1.Modeling Transformations 2.Overview of 3D Object Representation 5.RENDERING (1, 2, 3, 4) 6.MODELING (2) 7.ANIMATION 8.TOPICS
6
Modeling Transformations Readings Chapter 1 – Mathematical fundamentals of computer graphics Chapter 2 – Representation and modeling of three-dimensional objects (1) Chapter 2 – State management and drawing geometric objects Appendix F – Homogeneous coordinates and transformation matrices
7
Vector Tools for GraphicsVector Tools for Graphics Transformations of ObjectsTransformations of Objects Vector Tools for GraphicsVector Tools for Graphics Transformations of ObjectsTransformations of Objects 4. MODELING (1) : 1. Modeling Transformations Topics
8
Review vector arithmeticReview vector arithmetic Relate vectors to objects in graphicsRelate vectors to objects in graphics Relate geometric concepts to their algebraic representationsRelate geometric concepts to their algebraic representations Describe lines and planes parametricallyDescribe lines and planes parametrically Distinguish points and vectors properlyDistinguish points and vectors properly Exploit the dot product in graphicsExploit the dot product in graphics Develop tools for working with objects in 3D spaceDevelop tools for working with objects in 3D space Review vector arithmeticReview vector arithmetic Relate vectors to objects in graphicsRelate vectors to objects in graphics Relate geometric concepts to their algebraic representationsRelate geometric concepts to their algebraic representations Describe lines and planes parametricallyDescribe lines and planes parametrically Distinguish points and vectors properlyDistinguish points and vectors properly Exploit the dot product in graphicsExploit the dot product in graphics Develop tools for working with objects in 3D spaceDevelop tools for working with objects in 3D space Vector Tools for Graphics Goals
9
Why Are Vectors So Important? Example : 3 problems For the coordinate given, where is the center of the circle located? Where does the image of the tree appear on the viewplane, and what is its exact shape? Given the positions of the cone, cube and viewing camera, where exactly does the reflected image appear, and what is its color and shape?
10
Some Basics Coordinate Systems a) Two-dimensional b) Right-handed Math, engineering, physics, … Set up models for objects (local and world spaces) c) Left-handed Natural in computer graphics Viewing systems and “cameras” (view space)
11
Review 3D Vector : specifies a direction and a magnitude Represented by three coordinates Magnitude Has no location typedef struct { Coordinate dx; Coordinate dy; Coordinate dz; } Vector; (dx1, dy1, dz1) (dx2, dy2, dz2) Displacement
12
Review Operations
13
Review Linear combinations Affine combinations Two special cases: Convex combinations Often forced to sum to unity: and
14
Review “set of all convex combinations” Example: vector that is 20% on the way from v1 to v3 along L:
15
Review Magnitude Unit vector Normalizing At times, we refer to a unit vector as direction
16
Dot Product Angle between Two Vectors Sign and Perpendicularity “perpendicular” orthogonal normal
17
Vector Tools for Graphics (more later…)Vector Tools for Graphics (more later…) Transformations of ObjectsTransformations of Objects Vector Tools for Graphics (more later…)Vector Tools for Graphics (more later…) Transformations of ObjectsTransformations of Objects 4. MODELING (1) : 1. Modeling Transformations Topics
18
Developing tools for transforming one picture into anotherDeveloping tools for transforming one picture into another Introduce the fundamental concepts of affine transformations (combinations of rotations, scalings, translations)Introduce the fundamental concepts of affine transformations (combinations of rotations, scalings, translations) Develop functions that apply affine transformations to objectsDevelop functions that apply affine transformations to objects Modeling transformations in OpenGLModeling transformations in OpenGL Developing tools for transforming one picture into anotherDeveloping tools for transforming one picture into another Introduce the fundamental concepts of affine transformations (combinations of rotations, scalings, translations)Introduce the fundamental concepts of affine transformations (combinations of rotations, scalings, translations) Develop functions that apply affine transformations to objectsDevelop functions that apply affine transformations to objects Modeling transformations in OpenGLModeling transformations in OpenGL Transformations of Objects Goals
19
Introduction Control over the size, orientation, and position of objects of interest Each 3D point in the house: Scaling Rotation Translation Very useful in a number of situations: 1.Scene composition 2.“Motif” design 3.Viewing 4.Computer animation
20
Introduction Scene Composition Many instances of a simple form 3D primitives
21
Introduction “Motif” design Viewing Computer Animation
22
CPSC 453’s Framework for Interactive Graphics Graphics system Application program Imaging Modeling Application model Rendering Image Processing Animation User Interface OpenGL 3D graphics and modeling library Object-Oriented Design, C/C++
23
Application program OpenGL Command Buffer Transform and Lighting Rasterization Frame buffer OpenGL API Calls OpenGL OpenGL pipeline (simplified version)
24
Introduction OpenGL Pipeline glBegin(GL_LINES) glVertex3f(…); // send P1 through the pipeline glVertex3f(…); // send P2 through the pipeline glVertex3f(…); // send P3 through the pipeline glEnd(); CT : “Current Transformation”: Crucial tool Essential to know how to adjust it
25
Introduction Transforming Points and Objects Homogeneous representation or
26
Introduction Affine Transformations The coordinates of Q are linear combinations of those of P
27
Introduction Elementary 2D Affine Transformations Translation Scaling Rotation
28
Introduction Inverse of an Affine Transformation Translation Scaling Rotation
29
Composing (or Concatenating) Affine Transformations Introduction Example: Translate by (3, -4) Then rotate through 30 degrees Then scale by (2, -1) Then translate by (0.15) And finally, rotate through –30 degrees When homogeneous coordinates are used, affine transformations are composed by simple matrix multiplication
30
Example : Rotating about an arbitrary point Introduction 1.Translate point P through vector v = (-Vx, -Vy) 2.Rotate about the origin through angle theta 3.Translate P back through v
31
Transforming Points and Objects Homogeneous representation 3D Affine Transformations
32
Elementary 3D Affine Transformations Translation Scaling
33
3D Affine Transformations Rotations x-roll: y-roll: z-roll:
34
3D Affine Transformations Rotations
35
Order does matter 3D rotation matrices do not commute Combining Rotations Composing (or Concatenating): Same as in 2D case
36
Affine Transformations in a Program House #1 glBegin(GL_LINES) glVertex2f(V[0].x, V[0].y); glVertex2f(V[1].x, V[1].y); glVertex2f(V[2].x, V[0].y); …. // the remaining points glEnd(); House #2 ?
37
The Canvas Class class Canvas { private: Point2 CP; // current position in world float CD; // current direction in degrees public: Canvas(int width, int height, char* title); ~Canvas(); void setWindow(float l, float r, float b, float t); void lineTo(float x, float y); void moveTo(float x, float y); void turn(float ang); void turnTo(float ang); void forward(float dist, int vis); };
38
Affine Transformations in a Program House #1 cvs.moveTo (V[0]); cvs.lineTo (V[1]); cvs.lineTo (V[2]); …. // the remaining points House #2 ?
39
Affine Transformations in a Program House #2 : The Hard Way cvs.moveTo ( transform2D (CT, V[0]) ); cvs.lineTo ( transform2D (CT, V[1]) ); cvs.lineTo ( transform2D (CT, V[2]) ); …. // the remaining points Q = transform2D(CT, P);
40
Affine Transformations in a Program House #2 : The Easy Way Q = transform2D(CT, P); OpenGL cvs.moveTo (V[0]); cvs.lineTo (V[1]); cvs.lineTo (V[2]); …. // the remaining points OpenGL maintains modelview matrix CT : modelview matrix
41
Affine Transformations in a Program glScaled(sx, sy, 1.0); glTranslated(dx, dy, 0.0); glRotated(angle, 0.0, 0.0, 1.0); modelview matrix Alter the modelview matrix Do not set CT directly Each postmultiplies the CT : CT = CT * M
42
Back to Canvas… void Canvas :: initCT() // initialize the CT (model view matrix) { glMatrixMode(GL_MODELVIEW); // informs OpenGL which matrix we are altering glLoadIdentity(); // set CT to the identity matrix } void Canvas :: rotate2D(double angle) { glMatrixMode(GL_MODELVIEW); glRotated(angle, 0.0, 0.0, 1.0); // set CT to CT * (2D rotation) } void Canvas :: translate2D(double dx, double dy) { glMatrixMode(GL_MODELVIEW); glTranslated(dx, dy, 0.0); // set CT to CT * (2D translation) } void Canvas :: scale2D(double sx, double sy) { glMatrixMode(GL_MODELVIEW); glScaled(sx, sy, 1.0); // set CT to CT * (2D scaling) }
43
Examples Object definition Compose scene Define view reference Define lighting Local coordinate space World coordinate space Modeling transformation Local coordinate space World coordinate space Object definition Compose scene
44
Examples Drawing snowflakes void drawFlake() { for (int count = 0; count < 6; count++) { flakeMotif(); cvs.scale2D(1.0, -1.0); flakeMotif(); cvs.scale2D(1.0, -1.0); cvs.rotate2D(60.0); } }
45
Examples A flurry of snowflakes while (!bored) { cvs.initCT(); cvs.translate2D ( random amount, random amount ); drawFlake(); }
46
Examples Patterns from a motif const int numMotifs = 12; for (int i = 0; i < numMotifs ; i++) { cvs.initCT(); cvs.rotate2D ( i * 360 / numMotifs ); cvs.translate2D(0.0, H); drawDino(); }
47
Saving the CT for Later Use Top matrix : actual CT void Canvas :: pushCT(void) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); } void Canvas :: popCT(void) { glMatrixMode(GL_MODELVIEW); glPopMatrix(); }
48
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT();
49
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT(); CT1 = identity
50
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT(); CT2 = identity CT1 = identity
51
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT(); CT2 = identity * translation (W, H) CT1 = identity
52
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT(); CT2 = identity * translation (W, H) CT1 = identity CT3 = identity * translation (W, H)
53
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT(); CT2 = identity * translation (W, H) CT1 = identity CT3 = identity * translation (W, H)
54
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT(); CT2 = identity * translation (W, H) CT1 = identity CT3 = identity * translation (W, H) * translation (L, 0)
55
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT(); CT2 = identity * translation (W, H) CT1 = identity CT3 = identity * translation (W, H) * translation (L, 0)
56
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT(); CT2 = identity * translation (W, H) CT1 = identity CT3 = identity * translation (W, H) * translation (L, 0) * translation (L, 0)
57
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT(); CT2 = identity * translation (W, H) CT1 = identity CT3 = identity * translation (W, H) * translation (L, 0) * translation (L, 0)
58
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT(); CT2 = identity * translation (W, H) CT1 = identity
59
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT(); CT2 = identity * translation (W, H) * translation (0, D) CT1 = identity
60
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT(); CT2 = identity * translation (W, H) * translation (0, D) CT1 = identity CT3 = identity * translation (W, H) * translation (0, D)
61
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT(); CT2 = identity * translation (W, H) * translation (0, D) CT1 = identity CT3 = identity * translation (W, H) * translation (0, D)
62
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT(); CT2 = identity * translation (W, H) * translation (0, D) CT1 = identity CT3 = identity * translation (W, H) * translation (0, D) * translation (L, 0)
63
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT(); CT2 = identity * translation (W, H) * translation (0, D) CT1 = identity CT3 = identity * translation (W, H) * translation (0, D) * translation (L, 0) until…
64
Tilings made easy cvs.pushCT(); cvs.translate2D (W, H); for (int row = 0; row < 3; row++) { cvs.pushCT(); for (int row = 0; row < 3; row++) { motif(); cvs.translate2D (L, 0); } cvs.popCT(); cvs.translate2D (0, D); } cvs.popCT(); CT1 = identity
65
CAD program Code ?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.