Ans
1
Ans. to Tut 3
Qn 1
a)
b) )0,0,20()0,0,20( 1 TTM =−= −←engineleftwing
)0,0,5()0,0,5( 1 TTM =−= −←leftwingbody
)40,10,0()40,10,0( 1 −=−= −← TTM rearwingbody
Observe that the right wing with engine can be obtained by physically reflecting
the left wing with engine, i.e. applying xRF to vertices in wing ( ) will give the
following object:
Note that the coordinate system is the original coordinate system of the left
wing, since the reflection is a physical reflection, and so
Body
wing rear wing
engine
Right wing
2
1)0,0,5( −← = TM rightwingbody = )0,0,5(−T
Hence we write the OpenGL program as follows:
/* draw both the left and the right wing, with engines */
void draw_wing ()
{
glPushMatrix ( );
wing ();
glTranslatef (20,0,0);
engine ();
glPopMatrix ( );
}
/* draw the airplane */
void airplane (void)
{
glMatrixMode (GL_MODELVIEW); // set current matrix to identity
glLoadIdentity ( );
// draw body
body ();
glPushMatrix (); // store the current matrix
// draw left wing with engine
glTranslatef (5,0,0); // leftwingbody←M
draw_wing ();
glPopMatrix (); // retrieve the original current matrix
// associated with body
glPushMatrix ();
// draw right wing with engine
glTranslatef (-5,0,0); // rightwingbody←M
// you can consider the next four lines as a function draw_right_wing
glPushMatrix ();
glScalef (-1,1,1); // draw the right wing
draw_wing ();
3
glPopMatrix ();
glPopMatrix (); // retrieve the original current matrix
// associated with body
glPushMatrix ();
// draw rear wing
glTranslatef (0,10,-40); // rearwingbody←M
rear_wing ();
}
Qn 2
a) void box (float length, width, height)
{
glPushMatrix ( );
glScalef (length, width, height);
glTranslatef (0, 0.5, 0);
glutSolidCube (1);
glPopMatrix ( );
}
b) i) )90()0,65,15( ozuala −=← RTM (rule 2)
Alternatively,
)0,15,65()90()]90()0,15,65([ 1 −−=−= −← TRRTM
o
z
o
zuala (rule 1)
Note that both will give the same 44× composite transformation matrix.
You can verify this.
ii) )5.0,5.0,5.0()30()0,80,15( SRTM oztfua −=←
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) )5.0,5.0,5.0()30()0,80,15( SRTM ozbfua −=←
Note similar situation to ii).
void robotic_hand ( );
{
glMatrixMode (GL_MODELVIEW); // set current matrix to identity
glLoadIdentity ( );
glRotatef (30, 0, 0, 1); // the lower arm rotates
4
box (30, 80,50); // draw lower arm
glTranslatef (15, 65, 0); // uala←M
glRotatef (-90, 0, 0, 1);
box (30, 80, 50); // draw upper arm
glPushMatrix ( ); // store current matrix
glTranslatef (-15, 80, 0); // tfua←M
glRotatef (30, 0, 0, 1);
glScalef (0.5, 0.5, 0.5);
glRotatef (20, 0, 0, 1); // the top finger rotates
box (30, 80, 50);
glPopMatrix ( ); // restore current matrix
glTranslatef (15, 80, 0); // bfua←M
glRotatef (-30, 0, 0, 1);
glScalef (0.5, 0.5, 0.5)
box (30, 80, 50);
}
c) The underlined code above.