2002 by Jim X. Chen George Mason University Transformation and Viewing.1. Plane Example: J2_0_2DTransform.

Slides:



Advertisements
Similar presentations
Computer Graphics 2D & 3D Transformation.
Advertisements

Transformations Ed Angel Professor Emeritus of Computer Science
Geometric Transformations
Translate, Rotate, Matrix Pages Function Function Definition Calling a function Parameters Return type and return statement.
1 Computer Graphics Week6 –Basic Transformations- Translation & Scaling.
2D TRANSFORMATIONS. 2D Transformations What is transformations? –The geometrical changes of an object from a current state to modified state. Why the.
Transformations II Week 2, Wed Jan 17
1 Lecture 7 Geometrical Transformations: 2D transformations 3D transformations Matrix representation OpenGL functions.
Elementary 3D Transformations - a "Graphics Engine" Transformation procedures Transformations of coordinate systems Translation Scaling Rotation.
2.1 si SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling.
1 Geometrical Transformation Tong-Yee Lee. 2 Modeling Transform Specify transformation for objects Allow definitions of objects in own coordinate systems.
Transformations CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
CS 4731: Computer Graphics Lecture 8: 3D Affine transforms Emmanuel Agu.
2D Transformations x y x y x y. 2D Transformation Given a 2D object, transformation is to change the object’s Position (translation) Size (scaling) Orientation.
2D Transformations Unit - 3. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale it.
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
Geometric Objects and Transformations Chapter 4. Points, Scalars and Vectors  Points - position in space  Scalars - real numbers, complex numbers obey.
UniS CS297 Graphics with Java and OpenGL Viewing, the model view matrix.
CS 480/680 Computer Graphics Representation Dr. Frederick C Harris, Jr. Fall 2012.
CS 480/680 Computer Graphics Transformations Dr. Frederick C Harris, Jr.
Chapter 4 10 February Agenda Program 2 – Due 2/17 Chapter 4 – transformations GLUT solids.
2D Transformations.
Geometric Transforms Changing coordinate systems.
Lecture 3 Transformations.
 2D Transformations 2D Transformations  Translation Translation  Rotation Rotation  Scaling Scaling.
CGPage: 1 東吳資訊科學 江清水 3.1 2D Geometry - points and polygons X Y A point in 2D is represented by two real numbers (X,Y) A line segment is represented by.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
Geometric Objects and Transformation
1 Computer Graphics Week9 -3D Geometric Transformation.
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
Transformational Geometry CS418 Computer Graphics John C. Hart.
CSE Real Time Rendering Week 5. Slides(Some) Courtesy – E. Angel and D. Shreiner.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
Two-Dimensional Geometric Transformations A two dimensional transformation is any operation on a point in space (x, y) that maps that point's coordinates.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Lecture 3 Transformations. 2D Object Transformations The functions used for modifying the size, location, and orientation of objects or of the camera.
CS COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
1 By Dr. HANY ELSALAMONY.  We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations.
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.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
Computer Graphics I, Fall 2010 Transformations.
1 Teaching Innovation - Entrepreneurial - Global The Centre for Technology enabled Teaching & Learning, N Y S S, India DTEL DTEL (Department for Technology.
2002 by Jim X. Chen: Drawing Geometric Models.1. Objectives –OpenGL drawing primitives and attributes –OpenGL polygon face.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Transformations Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Computer Graphic 2 D Transformation.
Modeling Transformation
Modeling Transformations Mario Costa Sousa University of Calgary CPSC 453, Fall 2001 Mario Costa Sousa University of Calgary CPSC 453, Fall 2001.
Transformations. Modeling Transformations  Specify transformations for objects  Allows definitions of objects in own coordinate systems  Allows use.
1 U08181 Computer Graphics Clipping Transformations –Transformations and matrices –Homogeneous matrices –Transformations in SVG.
Objectives Introduce standard transformations Introduce standard transformations Derive homogeneous coordinate transformation matrices Derive homogeneous.
2D Geometry - points and polygons
Pattern filling in scan-conversion Antialiasing
Modeling Transformations
2D Transformations with Matrices
Review: Transformations
3D Geometric Transformations
Transformation and Viewing
Line and Character Attributes 2-D Transformation
Transformations 6 University of British Columbia
Unit-5 Geometric Objects and Transformations-II
4-4 Geometric Transformations with Matrices
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Plane 2D GEOMETRICAL TRANSFORMATIONS Example: J2_0_2DTransform
Geometric Objects and Transformations (II)
Translate, Rotate, Matrix
Animation Pages
Presentation transcript:

by Jim X. Chen George Mason University Transformation and Viewing.1. Plane Example: J2_0_2DTransform

by Jim X. Chen George Mason University Transformation and Viewing.2. 2D TRANSFORMATIONS Translate We have: P’ P d x d y y x

by Jim X. Chen George Mason University Transformation and Viewing.3. Scale or

by Jim X. Chen George Mason University Transformation and Viewing.4. Rotate or P’ = RP x’ = rcos(  ); y’ = rsin(  ); x’ = r(cos  cos  – sin  sin  ); y’ = r(sin  cos  + cos  sin  ); r 

by Jim X. Chen George Mason University Transformation and Viewing.5. Homogeneous coordinates P’ = T+P; P’ = S*P; P’ = R*P; If points are expressed in homogeneous coordinates, all three transformations can be treated as multiplications. That is, P’ = T(d x,d y ) P That is, P’ = S (S x,S y ) P That is, P’ = R(  ) P

by Jim X. Chen George Mason University Transformation and Viewing.6. // Let’s say the current matrix on matrix[3][3] is M my2dLoadIdentity();// M<=I; my2dTranslatef(float dx, float dy); // M<=MT(dx, dy); my2dRotatef(  ); // M<= MR(  ); my2dScalef(float sx, float sy); // M<=MS(sx, sy); Example: J2_0_2DTransform Float M[3][3]; // Current Matrix multiply Implementation (my2dGL)

by Jim X. Chen George Mason University Transformation and Viewing.7. Combination of translations and transformation matrix  ' 22 '' 11 ',,,PddTPPddTp yxyx  p ''  Float matrix[3][3]; my2dLoadIdentity(); my2dTranslatef(dx2,dy2); my2dTranslatef(dx1,dy1); transDraw(p); // what is transDraw? transDraw(object); // vertices are transformed first // before rendering transDraw(float x, y) { mult(&x, &y, matrix); // (x, y) is transformed by the matrix Draw(x, y); }  2211,,ddTPddT yxyx p p’ p’’

Example: J2_0_2DTransform public void display(GLAutoDrawable drawable) { if (cnt 200) { flip = -flip; } cnt = cnt+flip; gl.glClear(GL.GL_COLOR_BUFFER_BIT); // white triangle is scaled gl.glColor3f(1, 1, 1); my2dLoadIdentity(); my2dScalef(cnt, cnt); transDrawTriangle(vdata[0], vdata[1], vdata[2]); // red triangle is rotated and scaled gl.glColor3f(1, 0, 0); my2dRotatef((float)cnt/15); transDrawTriangle(vdata[0], vdata[1], vdata[2]); // green triangle is translated, rotated, and scaled gl.glColor3f(0, 1, 0); my2dTranslatef((float)cnt/100, 0.0f); transDrawTriangle(vdata[0], vdata[1], vdata[2]); } 2002 by Jim X. Chen George Mason University

Transformation and Viewing.9. COMPOSITION OF 2D TRANSFORMATION To rotate about a point P1 1. Translate so that P1 is at the origin 2. Rotate 3. Translate so that the point returns to P1(x1, y1) T(x1, y1)R(  )T(-x1, -y1) 2D Examples Plane Lab Plane Lab x y o    B f C f A f Example J2_1_Clock2d

by Jim X. Chen George Mason University Transformation and Viewing.10. Example 1: draw a current time clock in 2D space h’=T(c)R(-  )T(-c)h drawHand(c, h’); y y y y x' 1 y' x y  cos  sin 0  sin–  cos x 0 – 0 1 y 0 – x 1 y 1 1 =

by Jim X. Chen George Mason University Transformation and Viewing.11. h’=T(c)R(-  )T(-c)h drawHand(c, h’); Float matrix[3][3]; my2dLoadIdentity(); my2dTranslatef(x0, y0); my2dRotatef(-  ); my2dTranslatef(-x0, -y0); transDraw(c, h); //transVertex(V, V1);

J2_1_Clock2d public void display(GLAutoDrawable glDrawable) { my2dLoadIdentity(); my2dTranslatef(c[0], c[1]); my2dRotatef(-hAngle); my2dTranslatef(-c[0], -c[1]); transDrawClock(c, h); } 2002 by Jim X. Chen George Mason University

Transformation and Viewing.13. Example 2: Reshape a rectangular area: T(P 2 )S(s x,s y )T(-P 1 )P After reshaping, the area and all the vertices (or models) in the area go through the same transformation Example: J2_2_Reshape

J2_2_Reshape: Mouse 2002 by Jim X. Chen George Mason University public class J2_2_ReshapePushPop extends J2_1_Clock2d implements MouseMotionListener { // the point to be dragged as the lowerleft corner private static float P1[] = {-WIDTH/4, -HEIGHT/4}; // the lowerleft and upperright corners of the rectangle private static float v0[] = {-WIDTH/4, -HEIGHT/4}; private static float v1[] = {WIDTH/4, HEIGHT/4}; // reshape scale value private float sx = 1, sy = 1; ……

J2_2_Reshape: Mouse 2002 by Jim X. Chen George Mason University public class J2_2_ReshapePushPop extends J2_1_Clock2d implements MouseMotionListener { …… // when mouse is dragged, a new lowerleft point and scale value for the rectangular area public void mouseDragged(MouseEvent e) { float wd1 = v1[0]-v0[0]; float ht1 = v1[1]-v0[1]; // The mouse location, new lowerleft corner P1[0] = e.getX()-WIDTH/2; P1[1] = HEIGHT/2-e.getY(); float wd2 = v1[0]-P1[0]; float ht2 = v1[1]-P1[1]; // scale value of the current rectangular area sx = wd2/wd1; sy = ht2/ht1; }

J2_2_Reshape: display 2002 by Jim X. Chen George Mason University public void display(GLAutoDrawable glDrawable) { // reshape according to the current scale my2dLoadIdentity(); my2dTranslatef(P1[0], P1[1]); my2dScalef(sx, sy); my2dTranslatef(-v0[0], -v0[1]); … }

by Jim X. Chen George Mason University Transformation and Viewing.17. Robot Arm Robot Arm Example 3: draw an arbitrary 2D robot arm: Example: J2_3_Robot2d

by Jim X. Chen George Mason University

y o A B C x y o  A f B’ C’ x y o    B f C f A f x y o   B f C ’ ’ A f Initial position: (A, B, C) Step 1 Step 2Step 3 Final position Method I: x Float matrix[3][3]; my2dLoadIdentity(); // Af=R(a)A; B1=R(a)B; C1=R(a)C; my2dRotatef(  ); transVertex(A, Af); transVertex(B, B1); transVertex(C, C1); Draw (O, Af); my2dLoadIdentity(); // M=T(Af)R(b)T(-Af); my2dTranslatev(Af); my2dRotatef(  ); my2dTranslatev(-Af); //Bf=MB1; C2=MC1 transVertex(B1, Bf); transVertex(C1, C2); Draw(Af, Bf); my2dLoadIdentity(); // M = T(Bf)R(g)T(-Bf); my2dTranslatev(Bf); my2dRotatef(  ); my2dTranslatev(-Bf); transVertex(C2, Cf); Draw(Bf, Cf);

C y o A B Step 1 x 2002 by Jim X. Chen George Mason University x y o  C’’ A B’ x y o  C’ A B Step 2 Method II:  A f = R(  )A; B f = R(  )B’ = R(  )T(A)R(  )T(-A)B; C f = R(  )C’’ = R(  )T(A)R(  )T(-A)T(B)R(  )T(-B)C. OpenGL doesn’t return the transformed positions Float matrix[3][3]; my2dLoadIdentity(); my2dRotatef(  ); transDraw(O, A); // I*R(a) // we may consider local coordinates: origin at A my2dTranslatev(A); my2dRotatef(  ); my2dTranslatev(-A); transDraw(A, B); // I*R(a)T(A)R(b)T(-A) // we may consider local coordinates: origin at B my2dTranslatev(B); my2dRotatef(  ); my2dTranslatev(-B); transDraw(B, C); x y o    B f C f A f

by Jim X. Chen George Mason University A f = R(  )A; B f = T(A f )T(-A)B’ =T(A f )R(  )T(-A)B; C f = T(B f )T(-B)C’ =T(B f )R(  )T(-B)C. Float matrix[3][3]; my2dLoadIdentity(); my2dRotatef(  ); transVertex(A, Af); Draw (O, Af); my2dLoadIdentity(); my2dTranslatev(Af); my2dRotatef(  +  ); my2dTranslatev(-A); transVertex(B, Bf); Draw (Af, Bf); my2dLoadIdentity(); my2dTranslatev(Bf); my2dRotatef(  +  ); my2dTranslatev(-B); transVertex(C2, Cf); Draw(Bf, Cf); x y o    B f C f A f Step 3 Final position C y o A B Step 1 x

by Jim X. Chen George Mason University Transformation and Viewing.22. TRANSFORMATION MATRIX STACK Simulate a real clock? Animate robot arm? Need multiple matrices to save different states? Matrix stack Float matrix[POINTER][3][3]; myPushMatrix(); pointer++; copy the matrix from (pointer – 1); myPopMatrix(); pointer--; multiply

Matrix Stack J2_2_Reshape my2dLoadIdentity(); my2dTranslatef(P1[0], P1[1]); my2dScalef(sx, sy); my2dTranslatef(-v0[0], -v0[1]); my2dTranslatef(c[0], c[1]); my2dScalef(1.2f, 1.2f); my2dRotatef(-hAngle); my2dTranslatef(-c[0], -c[1]); transDrawClock(c, h); J2_2_ReshapePushPop my2dLoadIdentity(); my2dTranslatef(P1[0], P1[1]); my2dScalef(sx, sy); my2dTranslatef(-v0[0], -v0[1]); my2dPushMatrix(); my2dTranslatef(c[0], c[1]); my2dRotatef(-hAngle); my2dTranslatef(-c[0], -c[1]); transDrawClock(c, h); my2dPopMatrix(); 2002 by Jim X. Chen George Mason University At this point of program running, the current matrix on the matrix stack is different

OpenGL Matrix Stacks & Transformation 2002 by Jim X. Chen George Mason University public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) { super.reshape(drawable, x, y, w, h); //1. specify drawing into only the back_buffer gl.glDrawBuffer(GL.GL_BACK); //2. origin at the center of the drawing area gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(-w / 2, w / 2, -h / 2, h / 2, -1, 1); // matrix operations on MODELVIEW matrix stack gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); //3. interval to swap buffers to avoid rendering too fast gl.setSwapInterval(1); }

OpenGL Transformation Implementation my2dLoadIdentity(); transDrawArm(O, A); my2dTranslatef(A[0], A[1]); my2dRotatef(b); my2dTranslatef(-A[0], -A[1]); transDrawArm(A, B); my2dTranslatef(B[0], B[1]); my2dRotatef(g); my2dTranslatef(-B[0], -B[1]); transDrawArm(B, C); gl.glLoadIdentity(); drawArm(O, A); gl.glTranslatef(A[0], A[1], 0.0f); gl.glRotatef(beta, 0.0f, 0.0f, 1.0f); gl.glTranslatef(-A[0], -A[1], 0.0f); drawArm(A, B); gl.glTranslatef(B[0], B[1], 0.0f); gl.glRotatef(gama, 0.0f, 0.0f, 1.0f); gl.glTranslatef(-B[0], -B[1], 0.0f); drawArm(B, C); 2002 by Jim X. Chen George Mason University Example: J2_3_Robot2d Example: J2_4_Robot

by Jim X. Chen George Mason University Transformation and Viewing.26. Homework 1. Build up your own matrix system that includes - Double matrix[POINTER][3][3]; - void my2dLoadIdentity(); - void my2dTranslated(double x, double y); - void my2dRotated(double a); - void my2dScaled(double x, double y); - void myTransVertex(double x, double y, double x1, double y1); - void my2dPushMatrix(); - void my2dPopMatrix(); 2. Use your system to achieve the rotation of your pentagon or other objects in your circle. Then, you add a clock hand at each vertex of your pentagon or objects.

by Jim X. Chen: 27 HW5: 2012 Fall Class 1.Continue from previous homework; 2.Modify your code: draw a unit-size sphere at the origin; 3.Using OpenGL transformation on MODELVIEW Matrix Stack, rotate, scale, and translate the spheres to the locations in animation; (40%) 4.Use PushMatrix and PopMatrix on the Matrix Stack (40%)