3D Transformations

20
3D Transformations 3D Transformations

description

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 - PowerPoint PPT Presentation

Transcript of 3D Transformations

Page 1: 3D Transformations

3D Transformations3D Transformations

Page 2: 3D Transformations

Translation x’ = x + txy’ = y + tyz’ = z + tz

P = P’ =

T =

P’ = T . P

1 0 0 tx0 1 0 ty0 0 1 tz0 0 0 1

xyz1

x’y’z’1

x

y

P

P’

z

Page 3: 3D Transformations

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 00 sy 0 00 0 sz 00 0 0 1

x

y

z

Page 4: 3D Transformations

Rotation z-axis rotationx’ = x.cos– y.siny’ = x.sin y.cosz’ = z

R =

P’ = R . P

cos -sin sin cos

x

y

z

Page 5: 3D Transformations

Rotation x-axis rotationreplace x -> y -> z -> x in z-axis rotation y’ = y.cos– z.sinz’ = y.sin z.cosx’ = x

R =

y-axis rotationreplace x -> y -> z -> x in x-axis rotationz’ = z.cos– x.sinx’ = z.sin x.cosy’ = y

R =

1 0 0 0 0 cos -sin 0 0 sin cos 00 0 0 1

x

y

z

cos 0 -sin 0 0 1 0 0sin 0 cos 0

0 0 0 1

x

y

z

z-axis rotationx’ = x.cos– y.siny’ = x.sin y.cosz’ = z

Page 6: 3D Transformations

Rotation

Rotation about an arbitrary axis parallel to a coordinate axis

P’ = T-1 . Rx() . T. Px

y

z

Page 7: 3D Transformations

Rotation

x

y

z

Rotation about an arbitrary axis NOT parallel to a coordinate axis

Page 8: 3D Transformations

Rotation

x

y

z

Rotation about an arbitrary axis NOT parallel to a coordinate axis

1. Translate so that rotation axis passes through the origin

Page 9: 3D Transformations

Rotation

x

y

z

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

Page 10: 3D Transformations

Rotation

x

y

z

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

Page 11: 3D Transformations

Rotation

x

y

z

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

Page 12: 3D Transformations

Rotation

x

y

z

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

Page 13: 3D Transformations

Reflection

1800 rotation about x-axis

a combination of translation and rotation

y

x

z

x

z

y

Page 14: 3D Transformations

Shear

y

x

z

y

x

z

1 0 shx –shx.zref0 1 shy –shy.zref0 0 1 0 0 0 0 1

Page 15: 3D Transformations

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)

Page 16: 3D Transformations

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’

Page 17: 3D Transformations

OpenGL

glMatrixMode(GL_MODELVIEW);

glLoadIdentity ( );

glMultMatrixf(M2);

glMultMatrixf(M1);

/* M = M2 . M1 */

Page 18: 3D Transformations

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

Page 19: 3D Transformations

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);

Page 20: 3D Transformations

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);