CSCI 342 Fall 2014
Computer Graphics
Archived Class
Charles Cusack
Computer Science
Hope College
Main
Schedule
Grading
Gradebook
Homework

Policies
Advice
College
    Policies

Notes
Programs
Tutorials

CSCI 125
CSCI 255
Others

Admin

All Homework

Homework 1

The class will break up into two groups. One group will prepare a presentation that describes/compares the various monitor technologies (e.g. CRT, LCD, LED, and Plasma), and the other group will do the same for input devices, probably focusing on touch screens (e.g. passive and active touch screens, the use of fingers and/or pens, etc.).

The presentations should give a good bit of detail about the technologies behind the various options (being as technical as possible) and discuss the advantages and disadvantages of each. You should prepare PowerPoint slides or some other visual aides for your presentation. You may include short video(s) produced by others if you wish, but make sure you understand the content fully.

I have a few old tablet PCs in my office that have been disassembled. If you wish to take one to explore the technology used in them, please ask.

The main goal of this assignment is to allow us, as a class, to learn more about the various technologies, not to give you more work to do. Thus, if you are able to find good slides and/or videos that do a good job of presenting the material, you are welcome to use them.

Grades will be based on how clearly you present the topics, as judged by your classmates and me.

Homework 2

The purpose of this assignment is to help familiarize yourself with programming in C#.

For this assignment, you need to create a simple calculator that looks/functions similarly to this one: SimpleCalculator.exe. (When you download and run this, you will probably get a warning message if you are using Windows 8. You will need to Click More Information followed by Run anyway to run it.)

Don't over-complicate this assignment—I wrote the program in just about 45 minutes.

Here are a few hints:

  • You might want to know about the Convert and TableLayoutPanel classes.
  • My solution contains only two class fields. One is a double, and the other is an int (although I could have used an enumeration instead).
  • Besides declaring two fields, the rest of my code is in 14 event handler methods. The majority of them are one line long. One is slightly more complicated since it contains a switch statement. The rest are really simple.
  • Most importantly, start early, especially if you are new to C# and/or Visual Studio. You will need to figure out how to change properties of GUI elements, add events, etc. and although nothing in this assignment is at all difficult once you know how, you may need to experiment a little to figure how to do a few things. (It's like driving a car. Once you know how, it's really easy. But it wasn't so easy before you know what all of the controls did.)

You should create a project called SimpleCalculator in the CSCI342 Solution you have already created. If you don't remember how to do this, see the Adding a new project to the solution section on the last page of the Getting a Computer Graphics Project Started handout. Make sure you commit your changes to SVN before the deadline.

To receive full credit your calculator must look as good (or better) than the sample provided, and it should function properly. I will briefly look at your code just to make sure you didn't do anything really bizarre, inefficient, etc. In other words, I will simply be looking for clean, clear, and concise code.

If you have time, you are encouraged to go beyond the assignment for the purpose of becoming more familiar with C#. In other words, if you can think of ways of adding different GUI elements, using different events, etc., do so. But make sure that the basic features are implemented correctly first! In particular, if you can figure out how to get the keyboard keys (e.g. 0-9, +, -, etc.) to work, you will learn some useful stuff. But I will forewarn you—handling keys can sometimes be tricky.

Homework 3

Solve a variation of Problem 2.3.5 from book. Name your project DiamondChessboard. Start by creating a single diamond. Then create an 8x8 Chessboard-like pattern with diamonds. Since the chessboard isn't isn't lined up with either the vertical or horizontal axis, you may have to do a little thinking about how to get the 8x8 board to draw properly.

Modify the function that draws the diamond so that it takes a color. Then draw the diamonds filled (rather than just the lines) in two different colors.

Make sure your project is named DiamondChessboard and that you commit it to SVN by the deadline.

Homework 4

Create a project called MyFirstDrawing in your solution. In it, create an interesting drawing of your choice. Make sure you use dots, lines, polylines, rectangles, etc. In other words, use everything that was discussed in chapters 2 and 3. You may certainly go beyond that material if you wish.

Your code should have at least one instance of a function that draws an object that is called several times to draw the object in different locations/sizes.

You may find the OpenGL 2.1 Documentation to be helpful. But remember that you need to make slight adjustments to the calls since we are using Tao as a go-between.

The main point of the assignment is to give you an opportunity to explore the simple sorts of drawing you can accomplish in OpenGL.

Make sure you commit your code to SVN before the deadline.

Homework 5

Create a new project called Homework5 in your solution. Implement one of the following case studies: 3.4, 3.5, or 3.6; or implement case study 3.1 as specified below. Make sure you read carefully and fully implement what is asked.

As usual, make sure you commit your code to SVN before the deadline.

Chaos (based on Case Study 3.1)

Your job is to write an OpenGL program that shows the "orbit" of the point 0.1 when the function f(x) = 4*x*(1-x) is iterated. The orbit initially consists of two points: (0.1, 0) and (0.1, f(0.1)).

The paint handler for your OpenGL control should perform the following tasks:

  1. Plot the function f(x) in black over the domain 0<=x<=1. Note that the range of the function over this interval is 0<=f(x)<=1. There should always be a 10 pixel border between the window and the viewport on all sides. Choose a viewport to draw within the Open GL control so that as much of the control as possible is used to draw, while keeping the viewport square (to match the world boundaries). The viewport should always be centered within the Open GL control.
  2. Draw a blue rectangle around the viewport. Note that to avoid numerical inaccuracies, you may need to subtract just a tiny bit from the viewport boundary coordinates.
  3. Draw the line y=x in a light gray color
  4. Draw the entire orbit in black

Each time a key is pressed, two new points are added to the orbit. The new points to add to the orbit are determined as follows: Let last be the y coordinate of the last point in the current orbit Add the point (last, last) to the orbit Add the point (last, f(last)) to the orbit

You may want to make use of the PolylineCollection class that we developed in class to keep track of the orbit points.

When your program works, experiment with changing the value of 4 in the formula for f(x) with other values to see if you can get a different sort of pattern. Submit your solution with your chosen constant.

There is an example solution in torque3/course/342/solutions named Chaos2.exe.

Homework 6

Finish the Mantle Clock program.

Make sure your project is submitted to SVN by the deadline.

Homework 7

Do the following practice exercises from the book

  1. 4.2.1 a and b (pg 140)
  2. 4.3.5 (pg 146)
  3. 4.3.6 (pg 146)
  4. 4.3.9 (pg 148)
  5. 4.3.11 (pg 148)
  6. 4.3.12 (pg 149)

Homework 8

Implement the unimplemented methods from the mygraphicslib project in Point2D, Point3D, Vector2 and Vector3. You will notice that some methods are implemented in each class. This should help you figure out how to implement the others (although you will have to apply what you learned from the textbook to implement a few of them).

The unimplemented ones are obvious: They all just have the single line:

throw new NotImplementedException();

Make sure to think carefully about your implementations. Each method should be short and to the point (I don't think any of mine are more than 4 or 5 lines of code). Think carefully about what you do with the parameters passed into each method (i.e. should/can they be modified?).

Make sure you commit your code to SVN before the deadline.

Homework 9

Do the following practice exercises from the book

  1. 4.4.3 (pg 150)
  2. 4.4.7 c (pg 153)
  3. 4.4.8 b (pg 153)

Homework 10

Do the following practice exercises from the book. You may write an OpenGL program to assist you in either of the first two.

  1. 4.5.2 (pg 163)
  2. 4.5.4 (pg 163)
  3. 4.5.9 (pg 170)

Homework 11

Do the following practice exercises from the book

  1. 4.6.3 #2 (pg 171)
  2. 4.6.5 (pg 174)
  3. 4.7.2 (pg 176)

Homework 12

Complete the Drawing Charts Project Step 1. The sample files are solution executables are available here: WorkingSolutions.zip. In case you lose it, the details of the assignment are here: Drawing Charts Project

Make sure you commit your solution to SVN before the deadline.

Homework 13

Complete the Drawing Charts Project Step 2. The sample files are solution executables are available here: WorkingSolutions.zip. In case you lose it, the details of the assignment are here: Drawing Charts Project

Start early! There will be some tricky things for this part!

Make sure you commit your solution to SVN before the deadline.

Homework 14

Do the following practice exercises from the book

  1. 5.2.9a (page 208)
  2. 5.2.12 (page 209)

Homework 15

Complete the Drawing Charts Project Step 3. The sample files are solution executables are available here: WorkingSolutions.zip. In case you lose it, the details of the assignment are here: Drawing Charts Project

Start early! There will be more tricky things for this part!

Make sure you commit your solution to SVN before the deadline.

Homework 16

Implement Asteroids

Go to the course directory to 342/solutions/Asteroids.exe to see an example of a "B"-level solution to the assignment. Use A and D to turn left/right, W to go speed up, S to slow down, and space to fire.

You will notice that this solution has the following features:

  1. The ship can turn, move, and fire
  2. The asteroids spin around.
  3. The asteroids move.
  4. The asteroids disappear when hit by the laser (or photon beam or whatever it is).
  5. The ship is disabled temporarily if an asteroid hits it.
  6. When something hits any edge of the screen, it reappears on the opposite edge of the screen.
A solution that is well-implemented and does essentially all of these things will earn a grade of a "B". A project that falls short of the example project and/or that is poorly implemented may receive a lower grade.

To earn an "A", you need to add more features to the game. Possible features to add:

  1. Have large asteroids break into 3 smaller asteroids when they are hit. These three pieces should probably break off and travel in three different directions, perhaps 120 degrees apart. Small asteroids just disappear. Maybe the smaller ones are faster than the bigger ones.
  2. Have asteroids bounce off each other when they collide and/or break into pieces as if they were hit.
  3. Implement a shield for the ship so that when a certain key is pressed, asteroids bounce off. There should be a time limit (e.g. 1 second) that the shield can be active, and a cool down period (e.g. 10 seconds) during which the shield cannot be used.
  4. Implement alien ship(s) that fire your ship, either intelligently (although perhaps not perfectly) or randomly.
  5. Have the arena split into 4 quadrants. When the ship goes to the end of the screen instead of just wrapping around in the same quadrant, it wraps to the next quadrant (still jumping over to the other side of the screen, but it is now in a different quadrant). If it continues to the end of the screen again, it goes back to the first quadrant. In other words, the arena is a 2x2 grid that wraps around, with the ship being in one quadrant at a time. Instead of having the quadrants wrapping, you could have boundaries on the outside edges. Or you could have boundaries for the ship, but allow the asteroids to wrap around. In any case, you should include on the screen a "map" of the 4 quadrants in a smaller view so the player can see where they are and what is in all of the quadrants right now. In other words, draw a small version of the whole arena somewhere, and then draw just one quadrant in the main screen area. (If you use the appropriate concepts we have learned about, this shouldn't be too difficult.)
You may suggest your own features as well, but make sure you clear them with me to make sure they are significant enough (and related to the graphics part of the project enough) to merit an "A" grade.

Here are a few hints/tips:

  1. Don't just sit down and program. Think through all of the features you want and think about what classes and/or methods will help you to implement your solution, preferably in a step-by-step fashion. That is, get one feature to work at a time instead of trying to get it all work at the same time. A proper design will allow you to do this very easily.
  2. Think in particular about what methods you might want to add to existing classes (e.g. might you want to use PolyLine and/or PolylineCollection to store game elements? If so, what methods might be useful to add to those classes to facilitate various things.
  3. Should you have a class for game elements? What fields would it have?
  4. Where/how will you do collision detection? Do you need different algorithms for the laser hitting asteroids and the ship and/or other asteroids hitting asteroids?
  5. Since objects are moving and spinning, how will you store the locations and rotations? OpenGL will automatically translate and rotate for you if you store an offset and an angle for each object and apply the appropriate transformations. However, for collision detection you will need to re-compote the actual locations of vertices.

Homework 17

Make improvements to your Asteroids program. Of particular importance is that your collision detection is correct and as accurate and fast as possible. After that, the next most important thing would be to add the quadrant idea if you can and/or having asteroids split into smaller ones. Finally, making the graphics a little fancier would be nice, but isn't as important as some of the other aspects. Of course, some of you talked about having lives, scores, levels, etc. and other things that you think will enhance your project.

Grades will be based on both the final product and how you implemented it. This includes the correctness and efficiency of your collision detection and the details of how you implemented everything, including whether or not you made intelligent use of classes and methods.

It is important to note that a well-implemented simple solution that gets collision detection correct will be better than one with a lot of fancy features which don't really work. In other words, don't focus on adding lots of stuff all at once--add one thing at a time that works, then move on to the next thing.

Also remember to turn in a brief summary of your program that specifies

  1. What I need to know to play it.
  2. How and where (classes and methods) you did implement collision detection?
  3. Briefly describe your overall code design. Discuss what classes did you created, what the purpose of each is, what methods added to various existing classes from mygraphicslib to facilitate your computations (e.g. did you do collision detection in PolyLine and/or PolylineCollection? Do you have a class of game pieces that has a method to do this?).
  4. Evaluate your code design--what do you think you did well in terms of design, and what better choices could you have made?
  5. Tell me anything else that you think is relevant.
  6. What grade you think you should get on the assignment (both HW 16 and 17) and why (out of 20 points).

Homework 18

ExcavationMake: Part 1

Implement the first version of ExcavationMake. It should draw a world or reasonable size with cubes. You should be able to move around the world using the keyboard and mouse as follows:

  • W moves forward
  • S moves backwards
  • A strafes left
  • D strafes right
  • Z moves up (Y-axis)
  • X moves down (Y-axis)
  • Mouse changes pitch and yaw about the XZ plane
All movement should be relative to the original XYZ coordinate frame instead of the NUV coordinate frame. For instance, whether you are looking upwards or downwards, W should move you forward in the XZ-plane. You may use different controls than the above if you get prior approval from me. In particular, if you think of a better way of moving up and down, let me know.

You should not be able to walk past blocks, so you need to implement collision detection. In my solution there is no visible character, so I am doing collision detection with respect to the eye. You may do it that way or with a visible character.

In the final version you will also need to add the removal of blocks if they are clicked, improve the look of the blocks, and add other features as you are able. More details will be coming.

See torque/course/342/ExcavationMake for one or more working prototypes.

Homework 19

ExcavationMake: Part 2

Add block-clicking to your ExcavationMake project.

See torque/course/342/ExcavationMake for a working prototype. Also see the project RobotWithPicking project the SVN repository svn.hope.edu/CSCI/cusack/CSCI342/RobotWithPicking for an example of how to do object selecting.

Homework 20

Excavation Make: The Final Version

Add textures and do other cool things. Your main goal is to learn some new things. Your secondary goal is to impress me with your final project.