Assignment 4: Fun with Splines

 CS 445/645 Introduction to Computer Graphics

Fall 2002

Due: 5:00 p.m. December 5th

Goal: To demonstrate B-spline modeling using FLTK/OpenGL.  The user will be able to use your program to design a  three-dimensional course and generate a rider's-eye view of the track.  To simplify the design process, the user defines a sequence of 3-D points that are used as control points for a spline.  The user must have complete control over the number of points in the sequence and the location of the points.
Changes: No need to implement zooming on orthographic cameras (11/26/02).
Details:

Building user interfaces is very difficult - especially intuitive ones.  You can get a master's degree at CMU or GaTech that specializes in user interface design.  With your interface and graphics skills, you can build interfaces that use feedback to facilitate the user's decisions.  For example, the targets of actions can be highlighted before the action is executed and graphical state should change to clearly indicate the action was performed.  In this assignment, the user will be laying down a series of points that define the path of the spline.  The user may wish to add new points to the beginning, middle, or end of the spline.  The user may wish to move or delete existing points.  How will permit the user to accomplish all these different tasks without confusion?  You could stipulate that different mouse buttons or key clicks control each function, but it may become difficult to remember what button controls what action.  You could force the user to be in a particular state, like add mode, delete mode, move mode.  But if the user is forced to click a button on the interface to switch between states the spline creation and editing process could become cumbersome.

I'm not going to tell you the best way to build this interface because it's fun to think about it yourself.  The major dilemma is that there aren't enough mouse buttons to let the user select between adding points, deleting points, moving points, and controlling the camera.  I'm specifying the functions your system must support, but it's up to you to design an interface that is intuitive.  For example, you could have the mouse exist in either of two states, spline editing mode and camera control mode.  But what if you want to iterate back and forth between moving points and then viewing from multiple angles?  It can be annoying to keep clicking extra buttons to switch between states.  You could overload certain mouse buttons and control their actions by keyboard presses.  Many options are possible.

  • Camera Control: Use FLTK to create an interface with four views of a three-dimensional space: side, front, top, and perspective views.  The side, top, and front views have orthographic cameras that can translate away from the origin, but their lookat point is fixed at the origin.  You must use some method (mouse button clicking/dragging, user interface widget, keyboard control) to permit the user to change the distance from the camera to the origin (to zoom).  The perspective window should have the freedom to rotate the three-dimensional scene using the trackball metaphor described in the Angel text.  I recommend using one of the mouse buttons to permit the user to click/drag while rotating the world.
     

  • Add Points: If the pointer is within n pixels of a control point in an orthographic window, decide if the point to be added would go before or after the control point, and alter the rendering color of the portion of the spline where new points will be created.  For example, a person may wish to add a point between the existing 9th and 10th points.  When placing the mouse pointer over the existing 9th point of the spline, your system must decide if a point between 8 and 9 will be added or 9 and 10 will be added (both should be possible depending on exactly where the mouse is placed).  As long as your system is consistent in its treatment of the problem and provides feedback, the user should be able to easily accomplish what she or he wishes.  That is, the user could put the pointer just to the nine-side of point ten or just to the ten-side of point nine.  As you play with your interface, you'll find there is no perfect answer, but it's fun to come up with a solution (adding to the beginning and end of the spline are additional special cases).  I want you to write up your thoughts about the interface in a write up.

    Upon depressing a mouse button in any of the orthographic windows, attach a new control point to the user’s mouse.  This point is added between two points (or inserted to the very beginning or ending) as determined by the algorithm you devised for the previous paragraph.  As the user drags the mouse, you must interactively render the uniform, nonrational B-spline that results from the current position of the user’s mouse.  When the user releases the left mouse button, deposit the control point in the correct sequence of points and in the final position.
     

  • Move Points: Your interface must provide a way for the user to identify and remove points from the sequence.  Feedback is a useful tool, so you want to render a point differently if it is the candidate for the move action.  If the user presses a mouse button, and a point is highlighted, that point's position will be under the user's control while the mouse is dragged.   (what do you do if the user is close, but not quite touching a control point?  Should the control point immediately snap to the user’s mouse or remain an offset distance from the mouse?)   The B-spline should be updated interactively as the user drags the mouse.  If the mouse is far from any points when the middle button is pressed, do nothing.  When the user releases the mouse button, deposit the control point in its new position.  Please consider alternative editing techniques and include your thoughts in the write up. 
     

  • Delete Points: The user must be able to interactively select points and delete them.  Again, use feedback to highlight the candidate point before any actions are taken.  After clicking and releasing, the selected point will be removed from the spline sequence.

In each of the four windows, use a recursive subdivision method to render the spline as a piecewise linear curve (at most 100 control points will be entered).  Naturally, in three of the windows, you will be rendering a 2-D spline, but in the perspective window you will render the full 3-D spline.  Many textbooks describe adaptive subdivision methods for Bezier splines (p. 509 in Angel).  You may want to convert your B-spline to a Bezier spline for subdivision.  

To bring your spline to life, you must provide a way to switch the perspective window into a first-person viewing window.  Instead of showing a perspective view of the world, the camera will be positioned on the spline, with a negative z-axis that is tangent to the spline (and an up vector defined by the world's y-axis).  The camera will then translate along the spline and generate a rider's-eye view of the spline.  Note that you want to translate a constant amount along the spline each time (which is not the same as incrementing your spline parameter by a constant amount) so you'll have to consider the arc length of the spline.

Add a save/load feature that permits splines to be saved and loaded from disk according to a spline format of your selection.

Extra Credit: There are some non-trivial issues related to creating a track that follows the spline.  How would you make sure the two rails of a track remain parallel to one another?  If you render the spline as a tube, or pipe, how do you remedy situations like hairpin corners where the tube intersects itself?  Can you put cars on the track and render an "over the shoulder" view of the cars as they move?  Can you render a Metroid-like sphere that falls through the pipe?  If you really are modeling a roller coaster, what about accurately computing the physics so the cars are affected by gravity and have momentum?

Turnin: Create a subdirectory named Assignment4.

Copy all source code to this directory.

Create a README that details 

  • Any extra credit you performed 
  • The compiler you used
  • Instructions for using your program
  • A description (not more than one page) of why your user interface is a good one.
Collaboration and Use of Web Materials:

An assignment similar to this has been assigned at Wisconsin and UVa.  Don't look at any submissions or skeleton code related to this assignment at those locations.  Again, if you find a solution to this exact problem, don't even look at it.

You can talk with one another about your program, but do not look at anyone’s code and do not show your code to anyone.

Late Days: You have a total of five late days to use during the semester.  Each late day you use will provide you with a 24 hour extension.