1 / 32

Computer Graphics 4

4 September 2012. Computer Graphics, Lee Byung-Gook, Dongseo Univ.. 2. Introduction to transformations. Transformations are useful for:Composing a more complex object using many instances of a single form.Creating a complex object from a single "motif".Moving an object to get a different view of

summer
Download Presentation

Computer Graphics 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    1. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 1 Computer Graphics 4 Lee Byung-Gook Today, we are talking about transformation.Today, we are talking about transformation.

    2. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 2 Introduction to transformations Transformations are useful for: Composing a more complex object using many instances of a single form. Creating a complex object from a single "motif". Moving an object to get a different view of it. Moving an object to animate it. A transformation is a function that takes a point and maps that point into another point.A transformation is a function that takes a point and maps that point into another point.

    3. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 3 Mathematics notation in 3D, let P = (Px, Py, Pz, 1) P can be transformed into Q = (Qx, Qy, Qz, 1) by applying a transformation T Q = T(P) There are an infinite number of possible transformations Some transformations are rather simple Some transformations are rather complex Some transformations distort the shape of an object Some transformations maintain the relative shape of an object

    4. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 4 Affine transformations There is a special class of transformations that maintain the relative shape of objects (the affine transforms). All affine transformations are linear. Therefore, they can be written as: Qx = m11Px + m12Py + m13Pz + m14 Qy = m21Px + m22Py + m23Pz + m24 Qz = m31Px + m32Py + m33Pz + m34 1 = 1

    5. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 5 T is an affine transformation if T(aP + (1-a)Q) = aT(P) + (1-a)T(Q) aP + (1-a)Q is the parametric equation of a line segment. The definition says: "if we can take the line formed by P and Q and transform it, and then if we can get the same line by transforming only P and Q and then forming the line,T is an affine transformation. Definition of affine transformations

    6. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 6 Standard affine transformations Translation Scaling Rotation Shearing Standard affine transformations include translation, rotation, scaling, and shearing. Standard affine transformations include translation, rotation, scaling, and shearing.

    7. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 7 Translation a displacement a move in a linear direction it is not affected by the location of the origin Translation is an operation that displaces points by a fixed distance in a given direction. To specify a translation, we need only to specify a displacement vector (dx, dy, dz), because the transformed points given by Qx = Px+dx, Qy=Py+dy, Qz=Qz+dz For all points P on the object. Translation is an operation that displaces points by a fixed distance in a given direction. To specify a translation, we need only to specify a displacement vector (dx, dy, dz), because the transformed points given by Qx = Px+dx, Qy=Py+dy, Qz=Qz+dz For all points P on the object.

    8. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 8 Scaling to enlarge (or shrink) a point at the origin is never effected by scaling objects always scale about the origin Scaling can make an object bigger or smaller. Scaling transformations have a fixed point at the origin is never effected by scaling. Scaling can make an object bigger or smaller. Scaling transformations have a fixed point at the origin is never effected by scaling.

    9. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 9 Scaling if an object is not centered about the origin, scaling also moves it uniform scaling (Sx = Sy = Sz) differential scaling (Sx ? Sy or Sx ? Sz or Sy ? Sz) a negative scale factor reflects (flips) about an axis -Sx: reflects about the Y axis -Sy: reflects about the X axis -Sx and -Sy reflects about the line (x=-y) For s>1, the object gets longer in the specified direction; for 0<=s<=1, the object gets smaller in that direction. Negative values of s give us reflection about the fixed point, in the scaling direction.For s>1, the object gets longer in the specified direction; for 0<=s<=1, the object gets smaller in that direction. Negative values of s give us reflection about the fixed point, in the scaling direction.

    10. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 10 Rotation to move in a circular direction to rotate about the origin the angle is always considered a counter-clockwise rotation. derivation: Qx = r cos(?+?) = r (cos(?)cos(?) - sin(?)sin(?)) = r cos(?)cos(?) - r sin(?)sin(?) = Px cos(?) - Py sin(?) Qy = r sin(?+?) = r (sin(?)cos(?) + cos(?)sin(?)) = r sin(?)cos(?) + r cos(?)sin(?) = Px sin(?) + Py cos(?) Rotation is more difficult to specify than translation, because more parameters are involved. We start with the simple example of rotating a point about the origin in a two-dimensional plane. A two dimensional point at P in this frame is rotated about the origin by the angle theta to the position Q. We can obtain the standard equations describing this rotation by representing P and Q in polar form: These equations can be written in matrix form as :Rotation is more difficult to specify than translation, because more parameters are involved. We start with the simple example of rotating a point about the origin in a two-dimensional plane. A two dimensional point at P in this frame is rotated about the origin by the angle theta to the position Q. We can obtain the standard equations describing this rotation by representing P and Q in polar form: These equations can be written in matrix form as :

    11. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 11 Rotation Rotation about Z Rotation about Y Rotation about X where c = cos(angle), s = sin(angle)

    12. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 12 Rotation In 3D, there are an infinite number of axes about which to rotate. It can be shown that any rotation about any arbitrary axis can be decomposed into a series of "elementary rotations" about the coordinate axes. We assume the convention that all rotations follow the right-hand rule: "put your thumb along the axis of rotation and your fingers curl in the positive angle direction

    13. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 13 Shearing to shear in x: (Px + hPy, Py, Pz); slant vertically to shear in y: (Px, gPx+Py, Pz); slant horizontally Consider a rectangle in 2 dimensional space. If we pull the top to the right, we shear the object in the x direction. Consider a rectangle in 2 dimensional space. If we pull the top to the right, we shear the object in the x direction.

    14. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 14

    15. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 15

    16. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 16 glLoadIdentity The glLoadIdentity function replaces the current matrix with the identity matrix. void glLoadIdentity( void ); Remarks The glLoadIdentity function replaces the current matrix with the identity matrix. It is semantically equivalent to calling glLoadMatrix with the identity matrix but in some cases it is more efficient.

    17. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 17 glTranslate[d,f] The glTranslated and glTranslatef functions multiply the current matrix by a translation matrix. void glTranslated( GLdouble x, GLdouble y, GLdouble z ); void glTranslatef( GLfloat x, GLfloat y, GLfloat z ); Parameters x, y, z : The x, y, and z coordinates of a translation vector. Remarks The glTranslate function moves the coordinate system origin to the point specified by (x, y, z).

    18. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 18 Exercise From lab04 Translate rectangular using keyboard event x : translate -translateDelta on X axis X : translate translateDelta on X axis y : translate -translateDelta on Y axis Y : translate translateDelta on Y axis z : translate -translateDelta on Z axis Z : translate translateDelta on Z axis

    19. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 19

    20. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 20

    21. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 21 glRotate[d,f] The glRotated and glRotatef functions multiply the current matrix by a rotation matrix. void glRotated( GLdouble angle, GLdouble x, GLdouble y, GLdouble z ); void glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ); Parameters angle : The angle of rotation, in degrees. x, y, z : The x, y, and z coordinates of a vector, respectively. Remarks The glRotate function computes a matrix that performs a counterclockwise rotation of angle degrees about the vector from the origin through the point (x, y, z).

    22. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 22

    23. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 23

    24. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 24 glutIdleFunc glutIdleFunc sets the global idle callback. void glutIdleFunc(void (*func)(void)); Description glutIdleFunc sets the global idle callback to be func so a GLUT program can perform background processing tasks or continuous animation when window system events are not being received. If enabled, the idle callback is continuously called when events are not being received.

    25. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 25 glutPostRedisplay glutPostRedisplay marks the current window as needing to be redisplayed. void glutPostRedisplay(void); Description Mark the normal plane of current window as needing to be redisplayed. The next iteration through glutMainLoop, the windows display callback will be called to redisplay the windows normal plane. Multiple calls to glutPostRedisplay before the next display callback opportunity generates only a single redisplay callback. glutPostRedisplay may be called within a windows display or overlay display callback to remark that window for redisplay.

    26. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 26 Exercise From lab05 Rotate rectangular using mouse event Reference : lab04

    27. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 27

    28. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 28

    29. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 29 glScale[d,f] The glScaled and glScalef functions multiply the current matrix by a general scaling matrix. void glScaled( GLdouble x, GLdouble y, GLdouble z ); void glScalef( GLfloat x, GLfloat y, GLfloat z ); Parameters x, y, z : Scale factors along the x, y, and z axes, respectively. Remarks The glScale function produces a general scaling along the x, y, and z axes. The three arguments indicate the desired scale factors along each of the three axes.

    30. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 30

    31. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 31 Homework 3. In two weeks From lab05 Rotate rectangle about origin Using glutMouseFunc, glutMotionFunc Rotation angle(xTheta, yTheta) depend on the mouse movement while left mouse buttons are pressed

    32. 4 September 2012 Computer Graphics, Lee Byung-Gook, Dongseo Univ. 32 The first interactive OpenGL tutor POT was conceived in 1998 by Sumanta Guha, Mahesh Kumar and Ichiro Suzuki at the University of Wisconsin-Milwaukee, for use by the computer graphics students at UWM as well as the graphics community. Since POT ran only on UNIX platforms, we received many requests for versions that could run on other platforms. Since 1999 Binh Le continued developing the tutorial and created a Java version JPot. This is the current release, and the important features are as follows: JPot is platform independent. The interface is improved. There are more lessons. A tool is provided to generate lessons automatically. As an accademic project, JPot is free for all non-commercial uses, and we are strongly welcome other contributions for JPot. Even though we can not be responsible for any consequence of using it, we still try our best to assist you when you have problem regarding using and working on JPot. The first interactive OpenGL tutor POT was conceived in 1998 by Sumanta Guha, Mahesh Kumar and Ichiro Suzuki at the University of Wisconsin-Milwaukee, for use by the computer graphics students at UWM as well as the graphics community. Since POT ran only on UNIX platforms, we received many requests for versions that could run on other platforms. Since 1999 Binh Le continued developing the tutorial and created a Java version JPot. This is the current release, and the important features are as follows: JPot is platform independent. The interface is improved. There are more lessons. A tool is provided to generate lessons automatically. As an accademic project, JPot is free for all non-commercial uses, and we are strongly welcome other contributions for JPot. Even though we can not be responsible for any consequence of using it, we still try our best to assist you when you have problem regarding using and working on JPot.

More Related