Shadows, animation and a small gui

In this assignment you will construct a GUI, do some animation and simulate some fake shadows.

You have a convex body in 3D. The surface may have been generated by commands such as ellipsoid and cylinder. The lab consists of writing a GUI that can be used to rotate the body. Start by looking at an mpeg-file showing what the animation may look like. Give the command  mplayer ~thomas/VIS/data/body.mpeg when logged in on the student system. If you have problems finding mplayer, the path is /chalmers/sw/sup/MPlayer-1.0pre7/bin/mplayer .
Here is a still image:

Shadows

The animation in Matlab is much smoother than what is shown in my mpeg-file. In fact, my Matlab-program produces an avi-file. Matlab cannot produce compressed avi-files under unix, so to keep the size down I have not used such a high frame rate when producing the file. Also, I have converted the avi-file to mpeg-format, using the mplayer-tools, like this (in one long line):

mencoder -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:predia=2:dia=2:vmax_b_frames=2:vb_strategy=1:precmp=2:cmp=2:subcmp=2:preme=2:qns=2 -o body.mpeg body.avi

The input file, body.avi, is 105 Mbyte and the output, body.mpeg, is 1.7 Mbyte, in my example.

The body should rotate around the centre of mass (or some other internal point that you have chosen). Using the gui one should be able to change the rotational axis. As you can see in the mpeg-file, the body casts shadows on the coordinate planes. The shadow on the x-y-plane should be constructed by projecting all the points, on the surface, orthogonally on the x-y-plane. This corresponds to having a very distant light source, placed on the z-axis, sending parallel rays on the body. The shadows on the x-z-plane and the y-z-plane are constructed similarly.

You may decide how to design the gui, but it should have the following functionality (at least):

There should be seven buttons named:
x
y
z
Quit
Start
Stop
Capture

There should be a menu called Figure having three choices: ellipsoid, cylinder and box.

When pressing Start, a figure-window should appear in which an ellipsoid is rotating around the x-axis. There should be shadows, which are updated when the body is rotating. Pressing one of x, y or z should (instantly) make the body (in its present position) rotate around the chosen axis. The button, corresponding, the chosen axis should be highlighted (change colour).  The name of the present axis should be shown in the figure window as well (see the mpeg-file).

Pressing the Stop-button should freeze the rotation.
Pressing the Quit-button should close any open windows, belonging to the assignment. This should work even if the user has closed a window in some other way. Other figure-windows (not belonging to the assignment) should be left alone.

Using the menu one should be able to choose another surface. The ellipsoid should be the default. When pressing Start again the new surface should start to rotate.

When pressing the Capture-button, the program should collect frames (at a reasonable frame rate; do not use up your disk quota). The button should be highlighted. Pressing Capture once again should reset the button's colour, and it should halt the collection of frames. The frames should be stored in an avi-file (if you like you can convert it to mpeg). To simplify the programming, you can use the same file name for storing the file. If you like, you can make a more fancy solution, where the user can choose the file name.

Hint: use the Matlab commands convhull and avifile. Another hint: to get fast animation you need to use the graphics hardware. So, in the window where you are animating set the figure property 'Renderer' to 'opengl'. On some systems (but not ours) it may also help to set 'Doublebuffer' to 'On' (it is default). Don't forget the technique I mentioned in the lecture either (update the data directly in the object rather than issuing new plot-commands).

Question Implement a gui according to the specification above. Your solution should not be too inefficient as we want a smooth animation.

Back