|
CS 428 - Fall 2007 Homework 1: Graphing in OpenGL
Due electronically: Wednesday, September 19, 11:59 pm |
|
Description
Graphing functions is one of the simplest things you can do with OpenGL. To make it a little more interesting, you will create an animated graph of a parametric function. More specifically, you will plot this function (as a series of tiny line segments) over a sliding window of its domain.
At a particular moment in time, t (in seconds), graph the following parametric curve:
This function produces a Lissajous curve. Since the domain depends on t, viewing the above over time produces an animated graph. Depending on a and b, the domain may only include part of the curve. In this case, the graph moves. However, in other cases the domain captures the entire curve, and the display would not appear to change. One potential method that would make the graph appear animated in this case would be to reduce the width of the domain. But instead of making the interval smaller, we will shade the graph so that it's "leading point" is white (corresponding to the domain point t+π and the "trailing point" is black (corresponding to the domain point t), with a uniform decrease in intensity in between.
When viewed as an animation, the "leading point" is simply the frontmost point on the curve as time proceeds, and the "trailing point" is the rearmost point; the graph will chase its tail.
An example image of such a graph is displayed above.
Objective
This short homework will help you get started with using OpenGL (in Java), and understanding some of its basic operations, such as drawing lines and setting colors.
Program
You will be provided with skeleton code for this program. You only need to complete the DrawGraph.draw() method (this involves adding about 10-15 lines of code). Right now, the program draws nothing. The value of t (the current time) is already provided for you in draw() in the variable time. Also, draw() is called at regular time intervals to produce an animation.
Use the class variables a, b, and delta, which correspond to the parameters in the formula above, when computing the x and y coordinates of a point on the curve. You can change the values of these parameters with command-line arguments: [-a #] [-b #] [-delta #].
The (x,y) window coordinates for this window range from -1 to 1, with (0,0) being the center of the window. (This coordinate system is actually specified in the projection() method, which you will learn about soon).
The skeleton code for this project can be found on the cereal machines
in the directory:
~decarlo/428/hw1
First, you need to set up your account to use JOGL.
To copy the homework files to a directory called hw1 in your own directory, type:
cp -r ~decarlo/428/hw1 .
Then, go into the directory:
cd hw1
And compile the program:
javac Graph.java
or just use the Makefile as:
make
To run the program:
java Graph
Initially, the window is blank. You'll be editing DrawGraph.java for this assignment.
Extra credit (required for graduate students)
The graph should only be drawn colorized when the user specifies "-fancy" on the command line. In other words, if they ran the command:
java Graph -fancyYou can tell if the user specified this, as the fancy class variable in DrawGraph reflects this fact.
Make sure that if "-fancy" is not specified, then the program runs the normal way (no colors - only shades of grey).
You don't need to come up with a scheme that produces an image exactly like the one here, however. You will be given more extra credit, the more interesting looking your solution is (don't let your solution get too complicated, though). The details of whatever scheme you choose is up to you (be sure to explain what your method is, in a nearby comment in your code).
You will be handing in the file DrawGraph.java. If you changed any of the other files (most likely you didn't), please hand them in too.
Here are the instructions on how to hand in this file.
Suggestions and Tips