Computer Graphics
Develop a simple interactive two-dimensional spaceship deck plan editor using OpenGL and GLUT. Your program will enable a user to create and save a deck plan of a hypothetical spaceship comprising the hull walls, shielding/insulation/reinforcement (SIR) areas, walkable areas, interior walls, hull windows and interior doors. The deck could contain some simple pieces of furniture, hardware (power plant, shield generator, computer, etc.), and pods. Your program will allow the user to create the hull walls, SIR areas, walkable areas, interior walls, hull windows and interior doors; to place and size objects such as furniture and hardware on the deck; and to delete any object no longer wanted.
For simplicity a hull wall could consist of a thick straight line segment (instead of a curved line segment); thin straight line segments could be used for interior walls and hull windows. Shielding/insulation/reinforcement (SIR) areas could be suitably filled polygons; walkable areas of the deck could be polygons filled with an appropriate stipple pattern.
As a starting point for your work you could use the program contained in DeckPlan.zip. Compile, build and execute this program. Notice that it displays a screen window containing some aligned rectangles (that is, rectangles whose sides are aligned with the coordinate axes). The large rectangle on the left is the drawing region in which the deck plan could be created. On the right hand side appears a button containing a small square: this button allows the user to select a piece of furniture (represented by an aligned rectangle of fixed width and height to begin with) as the current object to be drawn. The following parts ask you to extend this program. A sketch which indicates roughly what your final program GUI, together with a simple hypothetical deck plan layout in its drawing region, might look is provided to you in DeckPlan.pdf. Your GUI does *not* have to be exactly the same as the one suggested in the diagram. In particular, your choice of colours could be different. Note that the upper diagram was obtained from the internet, and served as a kind of inspiration for the sketch below it.
Notice that the program is organised as three files. You could keep the same basic file (and class) structure throughout your extension work if you like. However it is up to you if you wish to add more files or otherwise change the structure of the program. (If you redesign it radically, it would be appreciated if you include some rationale in your Readme.html file.)
1. Draw a grid (equally spaced horizontal and vertical lines) for the drawing region. This will facilitate the creation of a deck plan.
2. Add a button which allows the user to create a hull wall (thick straight line) of desired length. Left mouse button press, drag and release could specify the endpoints. Add a button which allows the user similarly to create an interior wall or hull window (thin line) of desired length. No "rubber line" is requested yet.
3. Add a button which allows the user to create an SIR area (appropriately filled polygon). A succession of left mouse button clicks could specify the corners, with some "finish" action, such as a right mouse button click, indicating completion of the polygon. Add a button which allows the user similarly to create a walkable area (polygon filled with an appropriate stipple pattern).
4. For your furniture (light coloured rectangle with border) creation tool, now allow the user to enter the opposite corners of the desired rectangle using the mouse (with left button press, drag and release). Add a button which allows the user simlarly to create hardware (dark coloured rectangle with border) of desired size. No "rubber rectangle" is requested yet.
5. Add a button which allows the user to create an interior door (thick/thin straight line) of desired length. Left mouse button press, drag and release could specify the endpoints. Add a button which allows the user to create a pod (coloured circle).
6. Currently, drawn objects can extend beyond the drawing region. Arrange for drawn objects to be *clipped* against the drawing region.
Hint. Look at Example 3.2.5 on pages 101 and 102 of Hill and Kelley (or see pages 89 and 90 of the 2nd edition).
7. For the wall, furniture and hardware objects only, provide the user with feedback during the process of drawing an object by displaying a "rubber object" outline that changes shape as the user moves the mouse. Use the XOR logical operation, as described in Section 9.3.3 of Hill and Kelley 3rd edn (Section 10.3.3 of the 2nd edn) in which relevant theory is described and implementation details are outlined.
8. A sigificant disadvantage with the deck plan editor as it currently exists is that objects are drawn and then forgotten, so to speak. Consequently, if the screen window is partially covered by another window, and subsequently exposed by moving the other window away, then the objects which were drawn by the user disappear as the redraw event triggers a call to the display function.
Eliminate this problem by having your program build a model (list) of all the deck objects (walls, deck areas, furniture, etc.) drawn by the user.
A nice way to do this is to use a global vector of deck objects. Let's call our global vector DeckModel. The mouse function should draw and append to DeckModel each new deck object created. The display function should traverse DeckModel, drawing each object stored.
After doing this, move the call to glClear() and the command to fill the drawing region from init() to display(). (They really belongs in display().)
9. Add a button labelled "File". Clicking on this button should cause a pop-up File menu to appear. This menu should provide at least three options: Save (write to file), Open (read from file), Quit. In case Save is selected, the contents of DeckModel should be saved in (written to) the text file DeckPlan.txt. In case Open is selected, the contents of the text file DeckPlan.txt should be read intoDeckModel and displayed.
Details concerning the text file format you are requested to use are found below in a separate section.
10. Add two buttons for select and delete. Provide functionality for these buttons. Selection of an object could result in a simple selection box (rectangle, say) being drawn around the object.
11. Add a small row of 4 different colour buttons and provide the functionality for them.
12. One mark is awarded for an impressive professional looking user interface. One mark is awarded for good programming style.