The opossum is a very sophisticated animal. It doesn't even get up until 5 or 6 pm. Concept 1.15 The Magic Box ========================== Idea: ===== Click anywhere on the rendering screen with your left mouse button. The box starts rotating, it opens at the top, and colorful balls magically fly out of it. The right mouse button stops the animation. Drawing the Box and Top (Code shown in green) ================================================== o First rotate the box on table by spin degrees. o Draw the five faces of the box (except the top) using a call to GL_QUADS (Chapter 3). Notice, we store the vertices in an array and pass it's address to glVertex() command. o Drawing the top is a bit more complicated. Each of the four flaps at the top undergo a rotation of 180 degrees. Instead of using rotation here, we explicitly specify the vertices at each new location of the flaps. The flaps are rendered as triangles. o The top rear triangle gets rendered as follows. Its three vertices are the center of the top, and the two edge vertices. Its the center or apex of this triangle which undergoes a change of position as the flap open. o Using basic trigonometry we specify this vertex to be (0.0, Y, Z) where Y is given as 1 + sin(angle) and Z is -1 + cos(angle). Initially angle is zero. Hence this vertex is given as (0.0, 1, 0). When the flap is vertical the angle is 90 degrees and hence the vertex is (0.0, 2, -1). When fully open the angle is 180 degrees. Now the vertex is (0.0, 1, -2). This is how the top is drawn. The other three flaps of the box are drawn in a similar fashion. Drawing The Balls (Code shown in blue): ======================================= o The sphere is drawn by translating it as required in the X, and Y directions before rendering it. o The spinDisplay(void) function controls and updates various rotation, translation parameters. Understand the code with regards to what has been discussed in this section.