Download presentation
Presentation is loading. Please wait.
Published byAgus Indradjaja Modified over 6 years ago
1
Unit-5 Geometric Objects and Transformations-II
Course code: 10CS65 | Computer Graphics and Visualization Unit-5 Geometric Objects and Transformations-II Engineered for Tomorrow Prepared by :Asst. Prof. Sandhya Kumari Department : Computer Science and Engineering Date : dd.mm.yyyy
2
Geometric Objects and Transformations-II
Transformations in homogeneous coordinates Concatenation of transformations OpenGL transformation matrices Interfaces to three-dimensional applications Quaternions.
3
Transformation in Homogeneous Coordinates
Translation Scaling Inversion operations: T-1 = T ( -x , -y , -z ) S-1 = S ( 1/x , 1/ y , 1/ z )
4
Transformation in Homogeneous Coordinates
Rotation in x-y plane Rotation in y-z plane Rotation in z-x plane R-1 () = R ( - ) = RT ()
5
Transformations Concatenation
well known strategy q = C B A p interpretation q = C (B (A p) ) Transformation q = M p
6
Rotation About a Fixed Point
Rotation about the fixed point M = T(pf ) Rz( ) T(- pf )
7
Rotation About a Fixed Point
Rotation about the fixed point M = T(pf ) Rz( ) T(- pf )
8
Rotations in E3 Rxy Ryz Cube can be rotated about all x, y, z axis
In our case the transformation matrix is defined M = Rzx Ryz Rxy = Ry Rx Rz Rzx
9
Rotations in E3 Transformation is defined by the instance transformation M M = T R S (order is substantial!) Each occurrence of an object in the scene is an instance of the object’s prototype To obtain proper size, location, orientation – instance transformation to the prototype is to be applied
10
Rotations About an Arbitrary Axis
Given: points p1 , p2 and rotation angle objects to be rotated Define vectors u = p1 - p2 and v = u / |u| - normalized v = [ x , y , z ]T x2 + y2 + z2 = 1 – directional cosines cos( x ) = x , cos( y ) = y , cos( z ) = z cos2( x ) + cos2( y ) + cos2 ( z ) = 1 only two directions angles are independent !!
11
Rotations About an Arbitrary Axis
Transformation R = Rx(-x) Ry(-y) Rz() Ry(y) Rx(x)
12
Rotations About an Arbitrary Axis
Object is moved to the origin Rotation about x axis
13
Rotations About an Arbitrary Axis
Object is moved to the origin Rotation about y axis note the “-” position Complete transformation M = T(p0) Rx(-x) Ry(-y) Rz() Ry(y) Rx(x) T(- p0)
14
OpenGL Transformation Matrices
Three matrices as a part of the state in OpenGL Only Model-View will be used CMT – current transformation matrix – can be changed by OpenGL functions – 4 x 4 size Supported operations: translation, scaling & rotation – last two with the fixed point in the origin C I initialization C CT translation C CS scaling C CR rotation
15
OpenGL Transformation Matrices
Most systems allow to set directly or load or post-multiply the CMT with an arbitrary matrix M , scaling & rotation – last two with the fixed point in the origin C M loading C CM post-multiplication
16
OpenGL Transformation Matrices
OpenGL model-view (GL_MODELVIEW) and projection (GL_PROJECTION) matrices (actually their product) are applied to ALL primitives – we should consider them as one CMT matrix – can be manipulated individually using glMatrixMode function glLoadMatrixf(pointer_to_matrix); /* vector of 16 position – column first order */
17
OpenGL Transformation Matrices
glLoadIdentity ( ); /* loads identity matrix */ glRotatef(angle, vx, vy, vz); /* f – float used */ /* specifies general rotation angle in degrees, v – specifies the vector – fixed point P0 is the origin */ glTranslatef(dx, dy, dz); /* translation */ glScalef ( sx, sy, sz); /* scaling */
18
Rotation about a Fixed Point
glMatrixMode(GL_MODELVIEW); glLoadIdentity ( ); glTranslatef(4.0, 5.0, 6.0); glRotatef(45.0, 1.0, 2.0, 3.0); glTranslatef(-4.0, -5.0, -6.0); /* rotates objects about the vector (1.0, 2.0, 3.0) with the angle 45° */ NOTE: we need not to form the rotation matrices as shown recently – try to make it on your own
19
Transformation Order The sequence specified recently: C I, initialization C CT (4.0, 5.0, 6.0), translation C CR (45.0, 1.0, 2.0, 3.0), rotation C CT (-4.0, -5.0, -6.0), translation back in each step the CTM matrix is post-multiplied forming new CTM matrix C = T (4.0, 5.0, 6.0) R(45.0, 1.0, 2.0, 3.0) T (-4.0, -5.0, -6.0) Each vertex specified after the model-view matrix has been specified will be multiplied p’ = C p
20
Spinning of the Cube Three callback functions: glutDisplayFunc(display); glutIdleFunc(spincube); glutMouseFunc(mouse); void display(void); /* visibility made by HW – GL_DEPTH.... */ {glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity ( ); glRotatef(theta[0];1.0, 0.0, 0.0); glRotatef(theta[1];0.0, 1.0, 0.0); glRotatef(theta[2];0.0, 0.0, 1.0); colorcube ( ); glutSwapBuffers ( ); /* swaps the buffers – drawing to the display */ } /* theta vector – global variable */
21
Spinning of the Cube void spincube ( );
{ theta[axis] +=2.0; if (theta[axis] >360.0) theta[axis] -=360.0; glutPostRedisplay ( ); } void mouse (int btn, int state, int x, int y); { if (btn==GLUT_LEFT_BUTTON && state == GLUT_DOWN) axis=0; if (btn==GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) axis=1; if (btn==GLUT_RIGHT_BUTTON && state == GLUT_DOWN) axis=2; } void mykey(char key, int mouse x, int mouse y); { if (key==‘q’ | | key==‘Q’ ) exit ( ); } /* simple termination */
22
Loading, Pushing & Popping
glLoadMatrixf(myarray); /* 4 x 4 matrix of floats -column first order from a vector */ glMultMatrixf(myarray); /* multiplies the current matrix by user specified matrix */ Sequence example GLfloat myarray [16]; for ( i=0; i<3; i++) for ( j=0; j<3; j++) myarray[4*j+i] = m[i][j];
23
Loading, Pushing & Popping
Sometimes it is reasonable to return the transformations back after they have been applied to some objects. Instead of re-computation the stack mechanism can be utilized glPushMatrix ( ); /* local transformation specifications */ glTranslatef ( .....); /* DRAW OBJECTS HERE */ /* recover recent state */ glPopMatrix ( );
24
Quaternion’s A quaternion consists of Scalar part and vector part , Let a be the quaternion and is defined as a=(q0, q1, q2, q3) i.e., a = ( q0 , q) Where q=(q1, q2, q3) so, we can call Quaternion is an extension to complex numbers
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.