CSCI 1320 - Assignment #10



This is the final assignment of the semester. There is no real theme to what you have to do for it. It will just exercise a fair bit of what you have learned in this class and hopefully be interesting to program. While this assignment is listed as due on the last day of classes, if you choose to you can turn it in as late as the 15th and get full credit.

To turn in this assignment just send the code in an e-mail to mlewis@cs.trinity.edu. You can do this with the command "mail mlewis@cs.trinity.edu < assn9.c" if assn9.c is the name of your source file.

Speed Test Problem:

If you did the earlier speed test code then you might find this interesting. Keep the code you had before for comparison, but now also write quick sort or merge sort and run the same tests with them. Once again, you will do it with both ints and with the large structures as well as with 100, 1000, 10000, and 100000 elements in your arrays. For a full description refer back to assignment #9. For this one though I'm going to require that you plot up the data for at least one of the slow sorts and one of the fast sorts. You can do this quite easily with Excel. Then, for fun, add a trendline and see what can give you the best fit. You are unlikely to find n*log(n), but you should see that n*n is a very poor fit.

Graphics Problem:

This is the assignment I've been waiting for with the graphics path. In this assignment you will use your lighting calculations and your raster to help you make a ray tracer. In order to do this, there is at least one other significant function that you have to write. That function is one that tests if a ray in 3-space intersects with a triangle. For fun (and extra credit) you might also write functions that work with spheres because they will look cool. The only problem with doing this is that there is a decent bit of math involved. I'm going to try to explain the method you should use and pick one that largely utilizes the functions you have already written.

The general method goes like this. For each point in your raster you will "send out a ray" and see what, if anything it runs into. The closest thing it runs into is what you would see. From the point where it hits you will send out rays towards each light source. If there is something between the light source and the point then it is in shadow and that light doesn't illuminate that part of the surface so the pixel doesn't get any light from that point. You check all the lights that way and add up the ones that aren't blocked. The way you add it up is similar to what you did in assignment #7/8, but now the point you are using isn't one of the corners, but where your original ray hit the surface.

Because the method of finding intersections is best expressed with vector notation, I'm giving you a PDF file that describes that method. I recommend that you write a function that takes as input the ray data as two points, a start point and another point on the ray and the geometry data. It will return the point on the closest surface intersected, the normal at that point, and the color of that surface. You will also want a function that specifically tells you if a given ray intersects one particular triangle (or sphere), the point where it does, and maybe the normal (though you can find that in the callig function). You might find it helpful to have a triangle structure that stores not only the three points and color, but also the normal vector just to speed things up a bit.

Your program should take one command line argument, the name of the geometry file, and should write a file called raster.txt that has the image. The raster format is the same as before and should be viewable with the Java program you were given with assignment #7/8. For the geometry file, you can take either format, but if your program is executed without a file name it should say what format is expected. If you make your program handle sphere, the number of spheres and data for them should follow the triangles in the format where you give numbers of each. In the other format, lines that begin with an S will be spheres. If you don't handle spheres then just ignore those parts of the input or read them and throw it away.

Keep in mind that you can use a larger raster if you want to make nicer images and certainly try to view your raster with my viewer before turning it in. Your output doesn't have to match mine exactly, but it should look similar. You will be passing around some fairly large amounts of data. Consider using structures to keep track of some of those things.

For more extra credit (and a really cool effect) try to add reflection in. If you only have "perfect" reflection, then when your first ray hits a reflective surface, you find the new ray it would be reflected to, and display whatever that would draw. Basically, you will be doing the rendering recursively. You can think about how you might do other things like making surfaces partially transparent or partially reflective as well. You could also add ambient light though I wouldn't worry about diffuse reflection because that can be a bit too much of a pain. Information

For help with the executable, just type the executable name and no arguments. My executable does a number of other things that can help you, such as giving you some nice functionality for building geometries. I highly recommend that if you pick this option you download that file and play with it some before beginning and use it to help you make better inputs. Most of the options for building your geometries are straight forward. My tool asks for alpha values and reflectivities for just about everyting. You can ignore these if you don't do that. If you want to do that, I store the values in the top byte of the packed rgb so you should talk to me about how to get those out for your rendering. Three of the options are things you might not understand. Option 4 constructs a very simple fractal "terrain". It does this by doing midpoint displacements on a triangle. You have to give it the bounding triangle and an original offset. The offset should be a fairly small faction of the edge length. You also tell it how many levels to go down. Don't go higher than 5. The sheet option lets you enter four points and a surface is drawn with straight edges for those point. You tell it how many subregions to break it into and if you want it to be checkered. If it is checkered you will give it two colors for the checkering. Lastly, there is an option to add a "cylinder". This is actually a prism that approximates one. You pick the center spots for the top and bottom faces and one point on the top rim then tell it how many points to use around the rims. Using 4 would give you a cube type of shape.

Also, I have put up a new JAR file with a RasterViewer that will let you save the images you make as JPG or PNG files so you can do more with them. The use is the same as for assignment #7/8.

geometry file : raster file : executable : geometry file 2 : geometry file 3

Grade Book:

For this you will extend what you have done in the previous assignments in a few ways. First, you will add the ability to have multiple sections so you will want a section structure that holds an array of students. Second, you will make a menu option so that the user can add a section and another so they can select which section to be working with. Third, the save and load features need to save and load all the sections. You can do this by writing the number of sections first, followed by each section and each section can be written exactly the way you were writing one section for the previous assignments. A user needs to create a section before doing anything else. Sections should be named with strings. How you store the sections is up to you. A linked list might be ideal, but you can assume that there won't be more than 10 sections so a fixed array will also work.

Your new menu should look like this.

  1. Add section
  2. Select section
  3. Add student name
  4. Enter a grade for everyone in the current section for an assignment, quiz, test, or class participation
  5. Enter a single grade for one student
  6. Prints grades and average for one student
  7. Print section average and standard deviation for any grade
  8. Write gradebook to a file
  9. Read gradebook from a file
  10. Print whole class (like in assignment #9)
  11. Sort section by student name
  12. Sort section bt student average
  13. Quit

input file : output file : executable