Lab#2:  A Simple Dynamic Scene: Viewing Moving Objects from a Static Camera with Orthographic Projection

 

Goal: Create a dynamic version of your approximate circles in Lab#1 based on your understanding of double.cpp versus simple.cpp.

 

See this skeleton framework derived from double.cpp and read the explanations below and play with this sample final executable.

 

Step 1 (Understand the double buffers, the idle call-back function, and redisplay event): Run and study double.cpp very carefully to understand fully how it works, especially (i) how the mouse call-back function controls whether the square is spinning by using glutIdleFunc() to dynamically specify what should be the idle call-back function for an empty event queue, (ii) how the spinDisplay() function (when set to serve as the idle call-back function) update the global variable spin (as a very simple data structure for the modeling information of a single square object) to change the orientation of spin the square, and (ii) how the spinDisplay() function then call glutPostRedisplay() to enforce the display callback function to display the square. (Also see the online reference manual and shapes.exe in Nate Robin’s tutorial programs.)

 

Step 2 (Model planets and their orbits as circles): We want to have at least 4 circles, simulating at least 4 planets. Each planet has its own orbit (a circle of a fixed radius) and all the orbits have a common center (the sun). Each planet then evolves along the orbit. For simplicity, let’s locate the planet (as a circle) and its orbit (another circle) on the same plane with a fixed Z coordinate.  If you want for fun, you may allow the centers of different planets to have different Z coordinate values.

 

Step 3 (Data structures to hold the information of moving objects): For this purpose, you need to declare some global data structures that can hold the dynamic information of at least 4 circles corresponding to the 4 planets to draw, including for each circle C (i) the coordinates of the center of circle C (ii) the radius of the circle C, (iii) the coordinates of the fixed orbit center that C evolves around, (iv) the radius of C’s fixed orbit, and (v) the angle between the positive X Axis and the vector from the fixed orbit center to the current location of C’s center . In addition, the data structures may have extra optional attributes about rotation speed, colors, line width, stencil patterns, or point sizes, and so forth.

 

Step 4: Modify the display callback function to display the circles by calling the myFancyCircle function you implement in Lab#1 based on the geometric information of the circles and their attributes stored in the global data structures described in Step 3. Note that Do Not use anything like glPushMatrix and glRotatef in your display function you see in double.cpp. Just draw the circles based on their current geometric locations.

 

Step 5:  Modify the spinDisplay() function such that it will modify the geometric information of the circles in the global data structures to move the center of each circle along its orbit appropriately.

 

Step 6:  Keep the mouse function intact so that you can stop and resume the rotations along the orbits as you want.

 

Step 7:  Run your program to see whether your circles (planets) can move around their individual orbits smoothly.

 

Step 8: Submit all your source code files (.cpp and .h files) together with the self-evaluation report as a single zip file under Canvas.

 

 

/******************************************************************/

In addition to the graphics commands listed in the end of lab#1.

Spend time exploring the following functions.

 

glut functions: for registrating the call-back functions and posting a redisplay flag

 

 

glut functions: for setting up double display buffers and for swapping display buffers and