Ans. to Tut 3
Qn 1 a)
Body
wing rear wing
engine
b) Mleftwing←engine =T(−20,0,0)−1 =T(20,0,0) Mbody←leftwing = T(−5,0,0)−1 = T(5,0,0)
Mbody←rearwing=T(0,−10,40)−1 =T(0,10,−40)
Observe that the right wing with engine can be obtained by physically reflecting
the left wing with engine, i.e. applying RFx to vertices in wing ( ) will give the following object:
Right wing
Note that the coordinate system is the original coordinate system of the left wing, since the reflection is a physical reflection, and so
1
Mbody←rightwing =T(5,0,0)−1=T(−5,0,0)
Hence we write the OpenGL program as follows:
/* draw both the left and the right wing, with engines */ void draw_wing ()
{
}
/* draw the airplane */ void airplane (void)
{
glPushMatrix ( );
wing ();
glTranslatef (20,0,0); engine ();
glPopMatrix ( );
glMatrixMode (GL_MODELVIEW); // set current matrix to identity glLoadIdentity ( );
// draw body body ();
glPushMatrix ();
// draw left wing with engine glTranslatef (5,0,0);
draw_wing ();
glPopMatrix ();
glPushMatrix ();
// draw right wing with engine glTranslatef (-5,0,0);
// store the current matrix
// Mbody←leftwing
// retrieve the original current matrix
// associated with body
// Mbody←rightwing
// you can consider the next four lines as a function draw_right_wing
glPushMatrix ();
glScalef (-1,1,1); draw_wing ();
// draw the right wing
2
} Qn 2
glPopMatrix (); glPopMatrix (); glPushMatrix ();
// draw rear wing glTranslatef (0,10,-40);
rear_wing ();
// retrieve the original current matrix // associated with body
glPushMatrix ( );
glScalef (length, width, height); glTranslatef (0, 0.5, 0); glutSolidCube (1);
glPopMatrix ( );
Alternatively,
Mla←ua =[T(65,−15,0)Rz(90o)]−1 =Rz(−90o)T(−65,15,0)
(rule 2) (rule1)
Note that both will give the same 4 × 4 composite transformation matrix. You can verify this.
ii) Mua←tf = T(−15,80,0)Rz (30o )S(0.5,0.5,0.5)
Note that it is much simpler to work with coordinate system ua, treat ua as
an object and find the transformation from ua to tf, i.e. use method 2. iii) Mua←bf = T(15,80,0)Rz (−30o )S(0.5,0.5,0.5)
Note similar situation to ii).
void robotic_hand ( );
{
//
Mbody←rearwing
a)
b)
void box (float length, width, height)
{
}
i) Mla←ua = T(15,65,0)Rz (−90o )
glMatrixMode (GL_MODELVIEW); // set current matrix to identity glLoadIdentity ( );
glRotatef (30, 0, 0, 1); // the lower arm rotates
3
box (30, 80,50);
glTranslatef (15, 65, 0); glRotatef (-90, 0, 0, 1);
box (30, 80, 50); glPushMatrix ( );
glTranslatef (-15, 80, 0);
glRotatef (30, 0, 0, 1); glScalef (0.5, 0.5, 0.5);
glRotatef (20, 0, 0, 1);
box (30, 80, 50);
glPopMatrix ( );
glTranslatef (15, 80, 0);
glRotatef (-30, 0, 0, 1); glScalef (0.5, 0.5, 0.5)
box (30, 80, 50);
}
c) The underlined code above.
// draw lower arm // Mla←ua
// draw upper arm
// store current matrix
// Mua←tf
// the top finger rotates
// restore current matrix // Mua←bf
4