1 / 20

3D Transformations

3D Transformations. y. P’. P. x. z. Translation. x’ = x + tx y’ = y + ty z’ = z + tz P = P’ = T = P’ = T . P. x y z 1. x’ y’ z’ 1. 1 0 0 tx 0 1 0 ty 0 0 1 tz 0 0 0 1. y. x. z. Rotation. z-axis rotation x’ = x.cos q – y.sin q

gafna
Download Presentation

3D Transformations

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. 3D Transformations

  2. y P’ P x z Translation x’ = x + tx y’ = y + ty z’ = z + tz P = P’ = T = P’ = T . P x y z 1 x’ y’ z’ 1 1 0 0 tx 0 1 0 ty 0 0 1 tz 0 0 0 1

  3. y x z Rotation z-axis rotation x’ = x.cosq – y.sinq y’ = x.sinq + y.cosq z’ = z R = P’ = R . P cos q -sin q 0 0 sin q cos q 0 0 0 0 1 0 0 0 0 1

  4. y x z y x z Rotation x-axis rotation replace x -> y -> z -> x in z-axis rotation y’ = y.cosq – z.sinq z’ = y.sinq + z.cosq x’ = x R = y-axis rotation replace x -> y -> z -> x in x-axis rotation z’ = z.cosq – x.sinq x’ = z.sinq + x.cosq y’ = y R = 1 0 0 0 0 cos q -sin q 0 0 sin q cos q 0 0 0 0 1 cos q 0 -sin q 0 0 1 0 0 sin q 0 cos q 0 0 0 0 1

  5. Rotation Rotation about an arbitrary axis parallel to a coordinate axis P’ = T-1 . Rx(q) . T. P y x z

  6. Rotation Rotation about an arbitrary axis NOT parallel to a coordinate axis y x z

  7. Rotation Rotation about an arbitrary axis NOT parallel to a coordinate axis 1. Translate so that rotation axis passes through the origin y x z

  8. Rotation Rotation about an arbitrary axis NOT parallel to a coordinate axis 1. Translate so that rotation axis passes through the origin 2. Rotate so that rotation axis coincides with a coordinate axis y x z

  9. Rotation Rotation about an arbitrary axis NOT parallel to a coordinate axis 1. Translate so that rotation axis passes through the origin 2. Rotate so that rotation axis coincides with a coordinate axis 3. Rotate y x z

  10. Rotation Rotation about an arbitrary axis NOT parallel to a coordinate axis 1. Translate so that rotation axis passes through the origin 2. Rotate so that rotation axis coincides with a coordinate axis 3. Rotate 4. Inverse rotation y x z

  11. Rotation Rotation about an arbitrary axis NOT parallel to a coordinate axis 1. Translate so that rotation axis passes through the origin 2. Rotate so that rotation axis coincides with a coordinate axis 3. Rotate 4. Inverse rotation 5. Inverse translation y x z

  12. Scaling S = P’ = S . P wrt a fixed point (xf, yf, zf) : T(xf, yf, zf) . S(sx, sy, sz) . T(-xf, -yf, -zf) sx 0 0 0 0 sy 0 0 0 0 sz 0 0 0 0 1 y x z

  13. x z Reflection 1800 rotation about x-axis a combination of translation and rotation y x z y

  14. y x z Shear 1 0 shx –shx.zref 0 1 shy –shy.zref 0 0 1 0 0 0 0 1 y x z

  15. OpenGL • glTranslate*(tx, ty, tz) • f (float) • d (double) • glRotate* (theta, vx, vy, vz) • (vx, vy, vz) vector defines the orientation of the rotation axis that passes through the coordinate origin • glScale*(sx, sy, sz)

  16. OpenGL • glMatrixMode(GL_MODELVIEW) • sets up the matrix for transformations (4x4 modelview matrix) • glLoadIdentity ( ) • assigns identity matrix to the current matrix • glLoadMatrix*(16-element array) • assigns a 16-element array (in column major order) to the current matrix • glMultMatrix*(16-element array) • postmultiplies a 16-element array (M’) with the current matrix (M) : M <- M.M’

  17. OpenGL glMatrixMode(GL_MODELVIEW); glLoadIdentity ( ); glMultMatrixf(M2); glMultMatrixf(M1); /* M = M2 . M1 */

  18. OpenGL Matrix Stack • Initially stack contains identity matrix • Maximum stack depth is 32 • glGetIntegerv (GL_MAX_MODELVIEW_STACK_DEPTH, stacksize) • returns the number of positions available in the modelview stack • glGetIntegerv (GL_MODELVIEW_STACK_DEPTH, nummats) • returns the number of matrices currently in the stack • glPushMatrix() • copies the current matrix at the top of the stack • glPopMatrix() • destroys the matrix at the top of the stack

  19. OpenGL glMatrixMode(GL_MODELVIEW); glColor3f(0.0, 0.0, 1.0); Recti(50, 100, 200, 150); glColor3f(1.0, 0.0, 0.0); glTranslatef(-200.0, -50.0, 0.0); Recti(50, 100, 200, 150); glLoadIdentity ( ); glRotatef(90.0, 0.0, 0.0, 1.0); Recti(50, 100, 200, 150); glLoadIdentity ( ); glScalef(-0.5, 1.0, 1.0); Recti(50, 100, 200, 150);

  20. OpenGL glMatrixMode(GL_MODELVIEW); glColor3f(0.0, 0.0, 1.0); Recti(50, 100, 200, 150); glPushMatrix(); glColor3f(1.0, 0.0, 0.0); glTranslatef(-200.0, -50.0, 0.0); Recti(50, 100, 200, 150); glPopMatrix(); glPushMatrix(); glRotatef(90.0, 0.0, 0.0, 1.0); Recti(50, 100, 200, 150); glPopMatrix(); glScalef(-0.5, 1.0, 1.0); Recti(50, 100, 200, 150);

More Related