Home | People | Curriculum | Projects | Resources | Media

Wednesday, September 31

Mouse & Keyboard Interaction, and 3D Transformations, with OpenGL

This project extends work from the previous lab assignment, and should not be started until the previous one is completed successfully. In fact, many of the labs build on each other, so proper programming organization and documentation are essential throughout the course. You may want to return to the previous lab and reorganize it so it is simpler to extend.

Design and implement a C++ program using OpenGL calls to permit the user to point to a position in the drawing window and click to draw a shape using the same scheme as before:

• left button down (click) -- draw a square (or a cube)
• right button down (ctrl-click) -- draw a triangle (or a pyramid)

Your program should also maintain a list of the shapes drawn in the current "universe." Each entry in the list needs to contain enough information to redraw its corresponding shape at the "proper position and size."

The program should again accept mouse input keyboard input and the mouse input concurrently. Some of the keystrokes have been reassigned in this lab for 3D transformations. The following keyboard characters should be used, with the associated actions:

• r: shift right 25 pixels (or use right arrow)
• l: shift left 25 pixels (or use left arrow)
• u: shift up 25 pixels (or use up arrow)
• d: shift down 25 pixels (or use down arrow)
• f: shift forward 25 pixels
• b: shift backward 25 pixels
• e: expand (double in size)
• s: shrink (halve in size)
• x: clockwise rotation of 45 degrees about the x-axis (x-roll)
• y: clockwise rotation of 45 degrees about the y-axis (y-roll)
• z: clockwise rotation of 45 degrees about the z-axis (z-roll)
• h: shear using a preset that you can determine (your choice)
• q: quit execution (`exit(0)`)

Please include text instructions for drawing and transformations in the standard text window (i.e., use `cout ` ...)

Obtaining and submitting labs have also been revised. The lab is completed as follows:

1. Copy the `main.cpp` file from the previous lab to save it as `lab1.cpp`, then copy again into `login.2.cc`, where `login` is your user login name (e.g., `jdougher.2.cc`)
2. Edit `login.2.cc` to accomplish the goals stated above for this lab (i.e., Lab 2)
3. Make, run, and test the completed program.
4. Document your code appropriately (especially including your name in the source).
5. Submit your work into the cs212 drop box on `moe.cs.haverford.edu` (still to be established)
Grade Candy: only attempt after completing the requirements
• Add a keystroke `'p'` to toggle the projection between parallel (orthogonal) and perspective (this will be part of a subsequent assignment) [+5]
• Add a keystroke `'n'` to undo the last shape added to the universe [+5]
• Use the mouse middle-button to delete a set of shapes from the universe prior to transformation. Be sure to define clearly how the mouse is used to identify a shape in the universe, and beware of a point that may lie withing two or more shapes concurrently [+20]
• Design and implement your own transformation functions (e.g., `myTranslate(...), myRotate(...), myScale(...)`) that load and multiply the OpenGL modelview matrix approriately, and call these functions with the appropriate keystroke [+5 per transformation]; XOR ...
• Design and implement your own transformation functions (e.g., `myTranslate(...), myRotate(...), myScale(...)`) from scratch using the `vector` and `matrix` classes, and call these functions with the appropriate keystroke [+10 per transformation]

Links for CS212 -- Other CS212 Assignments: 0 1 2 3 4 5 6 7

 Page maintained by John Dougherty, David Wonnacott, and Rachel Heaton. Computer Science Department, Haverford College.