Download presentation
Presentation is loading. Please wait.
Published byMarvin Lamb Modified over 8 years ago
1
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 cases where h 1. h = 0 indicates a point at infinity (x, y, z) (x h, y h, z h, h)(x h, y h, z h, h) (x, y, z)
2
With homogeneous coordinates, we can express all 3D transformations as matrix multiplications. or
3
Translation (t x, t y, t z ) x y Translation Vector (t x, t y, t z ) z (x, y, z) (x', y', z')
4
Scaling x y Scaling factors s x, s y, s z Uniform scaling s x = s y = s z z x y z
5
Reflection Reflection about xy plane Reflection about xz planeReflection about yz plane
6
Shear Shear in xy plane about z axis x y z x y z
7
Rotation 3D rotation: Axis of rotation Rotation angle Looking along the negative direction of rotation axis, positive rotation angle produces counterclockwise rotation. Axis of rotation Right-hand rule: If right hand thumb points to the direction of rotation axis, then the other fingers point to the rotation direction of positive rotation angle.
8
Rotation about Coordinate Axes Rotation about z axis: x y z Use cyclic permutation to generate rotation equation about other axes:
9
Rotation about x axis: x y z
10
Rotation about y axis: x y z
11
Quaternion Quaternion definition Scalar part sVector part v = (v x, v y, v z ) Quaternion operation
12
Rotation with arbitrary rotation axis passing through origin x y z Axis of rotation u : Rotation angle u :Unit vector along axis of rotation quaternion for rotation: quaternion for point P (x, y, z): quaternion for point P' (x', y', z'): Rotation transformation:
13
Rotation Matrix:
14
Composite Transformations A sequence of transformations: M 1, M 2,..., M n can be calculated as P' = M P where M is obtained by matrix concatenation: M = M n M n-1 ... M 2 M 1
15
OpenGL maintains three transformation matrices: Modelview Matrix, Projection Matrix and Texture Matrix OpenGL Transformation Matrices Transformation matrices in OpenGL are stored in column-major order, which is different from row-major order of standard C convention.
16
The effects of most transformation commands are accumulative. The matrix is post-multiplied to the current transformation matrix. Because of this, transformation specified last is actually applied first. A:Current transformation matrix before transformation command M: Matrix generated by transformation command B:Current Transformation matrix after transformation command B = A M A sequence of transformations M 1, M 2,..., M n should be specified as: Transformation M n ; Transformation M n-1 ;...... Transformation M 2 ; Transformation M 1 ; Draw primitive;
17
General Purpose Transformation Commands void glMatrixMode(GLenum mode) mode:GL_MODELVIEW, GL_PROJECTION or GL_TEXTURE void glLoadIdentity(void) Set current matrix to 4 by 4 identity matrix. void glLoadMatrixf (const GLfloat *m) Set current matrix to the values stored in array pointed by m. void glLoadMatrixd(const GLdouble *m) Specify current matrix mode. void glMultMatrixf (const GLfloat *m) Post-multiply the matrix pointed by m to the current matrix. void glMultMatrixd(const GLdouble *m)
18
Geometric Transformation Commands Translation void glTranslatef(GLfloat tx, GLfloat ty, GLfloat tz) void glTranslated(GLdouble tx, GLdouble ty, GLdouble tz) (tx, ty, tz): Translation vector Scaling void glScalef(GLfloat sx, GLfloat sy, GLfloat sz) void glScaled(GLdouble sx, GLdouble sy, GLdouble sz) (sx, sy, sz): Scaling factors Rotation void glRotatef(GLfloat , GLfloat x0, GLfloat y0, GLfloat z0) void glRotated(GLdouble , GLdouble x0, GLdouble y0, GLdouble z0) :Rotation angle (in degrees) (x0, y0, z0):Axis of rotation that passes through origin
19
Matrix Stack Manipulation For each transformation matrix, OpenGL maintains a matrix stack. The Modelview matrix stack has at least 32 entries. The Projection and Texture matrix stacks have at least 2 entries each. void glPushMatrix(void)Push current matrix into matrix stack. void glPopMatrix(void)Pop current matrix from matrix stack. The current matrix stack is determined by glMatrixMode(). Matrix stacks are useful for hierarchical modeling.
20
Normalize mouse position 1 y w h (x, y) 1 11 11 (x n, y n ) x Arcball (Trackball) Rotation
21
Map normalized mouse position to unit sphere (arc ball) 1 x y 1 11 11 (x n, y n ) x y (x s, y s, z s ) z Arc ball when r < 1when r > 1
22
Obtain rotation quaternion x y Arc ball P0P0 P1P1 n P 0 Start position on unit sphere P 1 End position on unit sphere Rotation quaternion:
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.