Due Date: Friday, 24 August 2007 before 11.59pm.
Marks: 10% of your total mark for this unit.
This assignment is designed to give you some experience in using OpenGL. Although OpenGL is inherently 3D, this assignment will only require you to output 2D primitives for graphical output. You must code your solution in the C or C++ programming languages using OpenGL. This can be done using the Linux PCs.
The superformula is a simple mathematical equation capable of drawing a wide variety of natural shapes. It is a generalisation of the equation for a superelipse. It is given by the following equation:
ni and m are real numbers >= 0, a and b are real numbers > 0. The equation is specified in polar coordinates, returning a radius, r, at a given angle. See the paper in the link above for more details. The shapes shown below are all generated using the superformula. Different shapes are obtained by changing the values of n1, n2, n3, a, b and m.
You can generate superformula in OpenGL by approximating the continuous formula with a series of points to form a closed polygon or line segment.
For this assignment you are required to write a program that generates the superformula in a variety of forms using OpenGL. Interaction with the program will be done via keyboard and mouse commands outlined below. Your program should display three viewports in one window (see diagram below). The first viewport is the main view which contains the main rendering of previously edited superformulas along with the current superformula being edited. The second viewport shows keyboard commands and status, using OpenGL text. The third viewport shows the current superformula primitive being edited. It should be possible to resize the window. Ensure that your program maintains correct aspect ratios if the window is resized.
The basic idea is that individual superformulas are edited in the edit view.
Here the user may adjust parameters using keyboard and mouse commands. The
current superformula being edited appears in both the main view and the edit
view. Once the user is satisfied with the shape, colour and form of the current
superformula being edited, they then press the E
key, which "freezes"
the current parameters and transformations. This superformula object is kept
in the main window, but as new superformula object appears in the edit and
main views and can now be edited. This way it is possible to build a complex
shapes, composed of any number of superformula objects, which are all displayed
in the main view.
The text view should show:
AnimateMode
, FillState
and RotateMode
Your program should support the following keyboard commands:
Command | Action | |
1 |
toggle the editing of the value of n1 in the superformula | when
editing the superformula the mouse movement changes the value of the
parameters currently toggled on (unless animate mode [w] is set – see
below). Use sensible limits for each of the values. It should be possible
to edit multiple parameters simultaneously. |
2 |
toggle the editing of the value of n2 in the superformula | |
3 |
toggle the editing of the value of n3 in the superformula | |
a |
toggle the editing of the value of a in the superformula | |
b |
toggle the editing of the value of b in the superformula | |
m |
toggle the editing of the value of m in the superformula | |
+/- |
increase/decrease the range of theta when generating the superformula object | |
w |
toggle AnimateMode . When AnimateMode is active
all currently edited parameters are animated using a sin function.
The amplitude and velocity of the function should be set to reasonable
values to allow the user to see all possibilities for the parameter. |
|
up arrow |
translate the current superformula object in the +y axis (updates in main viewport only) | |
down arrow |
translate the current superformula object in the -y axis (updates in main viewport only) | |
right arrow |
translate the current superformula object in the +x axis (updates in main viewport only) | |
left arrow |
translate the current superformula object in the -x axis (updates in main viewport only) | |
s/S |
uniform scale down/up the current superformula object (updates in the main viewport only) | |
r/R |
rotate the current superformula object by +10/-10 degrees (updates the main viewport only) | |
z/Z |
zoom out/in the main viewport | |
f |
toggle the value for FillState . The current superformula
object is displayed either hollow or filled. If FillState is
set, then the current polygons are drawn filled, otherwise only the boundary
is drawn. |
|
c |
change the colour of the current superformula object. Allow the program to cycle through a number of different colours. | |
E |
End the editing of the current superformula primitive and start editing a new superformula. The old superformula remains in the main viewport, but its attributes can no longer edited. | |
W |
Toggle the value for RotateMode . If RotateMode is
true then each superformula in the main view should rotate about its own
centroid with a constant angular velocity. |
|
C |
Clear all superformula objects from the main viewport except for the current superformula being edited. | |
q |
quit the program. |
Use sensible values for the default translation amount, the default scale increase and decrease factors, rotational velocity, etc. (they should be the same for each direction). The program needs to update the viewports immediately in response to any changes.
You need to submit your program for assessment in electronic form using the
submit
program. See the submit page for details on how to submit assignments.
You should submit a directory which contains the following:
.c
, .cpp
and .h
files — see
the declaration that must be included
with all source files)Makefile
with the correct targetsREADME
file that describes how to run the program
(including any command line options) and a brief description of how you coded
your solution (no more than 1 A4 page
of text).Do not submit any other files. Submissions that fail to make or compile will not achieve a passing mark, nor will a program that does not run.
The following criteria will be used when assessing your submission: