Presentation is loading. Please wait.

Presentation is loading. Please wait.

Geometric Transformations

Similar presentations


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

1 Geometric Transformations
Lab 6 Lab 6 Geometric Transformations Geometric Transformations

2 current matrix. That is, after
 The glPushMatrix function pushes the current matrix stack down by one, duplicating the current matrix. That is, after a glPushMatrix call, the matrix on the top of the stack is identical to the one below it.  The glPopMatrixfunction pops the current matrix stack, replacing the current matrix with the one below it on the stack. Initially, each of the stacks contains one matrix, an identity matrix.

3 1. Translation 2. Rotation 3. Scaling

4 glTranslatef(Glfloat x , Glfloat y , Glfloat z);
The glTranslate* function multiplies the current matrix by a translation matrix. float glTranslatef(Glfloat x , Glfloat y , Glfloat z); Double glTranslated(Gldouble x, Gldouble y, Gldouble z); Displacement on  X: x axis  Y: y axis  Z: z axis

5 glColor3ub (0, 102,0); glBegin(GL_TRIANGLES); glVertex2f(1,1);
glVertex2f(5,5); glVertex2f(9,1); glEnd(); glTranslatef(7,8,0); glColor3ub (0, 204,0); glBegin(GL_TRIANGLES); glVertex2f(1,1); glVertex2f(5,5); glVertex2f(9,1); glEnd();

6 glColor3ub (204,0,102); glutSolidTorus(1.5,4,15,70); glTranslatef(-9,-10,-2); glColor3ub(255,67,130); GlutSolidTorus(1.5,4,15,70);

7 The glRotated, glRotatef functions computes a matrix that performs a counterclockwise rotation of angle degrees about the vector from the origin through the point (x, y, z). Then multiplies the current matrix by a rotation matrix.

8 glRotatef(Glfloat angle,Glfloat x ,Glfloat y ,Glfloat z); Double
glRotated(Glfloat angle,Gldouble x,Gldouble y,Gldouble z);  glRotatef(Ө, 0, 0, 0)  glRotatef(-Ө, 0, 0, 0)  Ө --> anticlockwise rotation  -Ө --> Clockwise rotation  0, 0 -> x,y -> Rotation about the origin

9 glColor3ub (37, 66, 101); glBegin(GL_TRIANGLES); glVertex2f(4,3); glVertex2f(8,12); glVertex2f(12,3); glEnd(); glRotatef(180,0,0,0); glColor3ub (112, 153,202); glBegin(GL_TRIANGLES); glVertex2f(4,3); glVertex2f(8,12); glVertex2f(12,3); glEnd();

10 glColor3ub (37, 66, 101); glBegin(GL_TRIANGLES); glVertex2f(4,3);
glVertex2f(8,12); glVertex2f(12,3); glEnd(); glRotatef(180,1,0,0); glColor3ub (112, 153,202); glBegin(GL_TRIANGLES); glVertex2f(4,3); glVertex2f(8,12); glVertex2f(12,3); glEnd();

11 Rotation around the point is not the origin point:
Displacement the body until point rotation 1. match origin point. Rotate the body around the origin point 2. Inverse displacement for body (back the rotation point to its original position) 3. Rotation around the axis In the 3D When  glRotatef(180,1,0,0);X  glRotatef(180,0,1,0);Y  glRotatef(180,0,0,1);Z

12 Rotation around the axis In the third dimension: glPopMatrix();
glPushMatrix(); glColor3ub (153, 102,51); glRotatef(180,1,0,0); glTranslatef(8,6,3); glutSolidTeapot(4.5); glPopMatrix(); // y glPushMatrix(); glColor3ub (78, 110,20); glRotatef(180,0,1,0); glTranslatef(8,6,3); glutSolidTeapot(4.5); glPopMatrix(); // z glPushMatrix(); glColor3ub (128, 181,33); glRotatef(180,0,0,1); glTranslatef(8,6,3); glutSolidTeapot(4.5); glPopMatrix();

13 The glScaled and glScalef functions produces a general scaling matrix along the x, y, and z axes. The three arguments indicate the desired scale factors along each of the three axes. Then multiply the current matrix by a general scaling matrix.

14 Float glScalef(Glfloat x , Glfloat y , Glfloat z); Double glScaled(Gldouble x, Gldouble y, Gldouble z); x , y ,z >1  Enlarge the size x , y ,z > 0 and x , y ,z <1  Reduce the size x , y ,z < 0  Inverse

15 // blue TRIANGLES glColor3ub (33,88,104); glBegin(GL_TRIANGLES); glVertex3f(4,3,0); glVertex3f(6,6,0); glVertex3f(8,3,0); glEnd(); glPushMatrix(); // Light blue glScalef(2, 2.5, 2); glColor3ub (55,149,175); glBegin(GL_TRIANGLES); glVertex3f(4,3,0); glVertex3f(6,6,0); glVertex3f(8,3,0); glEnd(); glPopMatrix(); // red TRIANGLES glPushMatrix(); glScalef(0.5, 0.6, 0.5); glColor3ub (252,20,53); glBegin(GL_TRIANGLES); glVertex3f(4,3,0); glVertex3f(6,6,0); glVertex3f(8,3,0); glEnd(); glPopMatrix();

16 Scaling body for a fixed point in the second dimension :
Displacement the body until fixed point match 1. origin point. Change the body size 2. Inverse displacement for body (back the fixed point to its original position) 3.

17 glPushMatrix(); glTranslatef(7.5,5.5,0); glScalef(2, 2, 2); glTranslatef(-7.5,-5.5,0); glColor3ub (255,130,45); glBegin(GL_TRIANGLES); glVertex3f(4,3,0); glVertex3f(7.5,10,0); glVertex3f(11,3,0); glEnd(); glPopMatrix(); glColor3ub (255,51,0); glBegin(GL_TRIANGLES); glVertex3f(4,3,0); glVertex3f(7.5,10,0); glVertex3f(11,3,0); glEnd();


Download ppt "Geometric Transformations"

Similar presentations


Ads by Google