559 Home
559 Calendar 559 Resources 559 Class Info Remove Frames

Project 2: Trains and Rollercoasters

Remember, this project specification is a work in progress. Be sure to check back often for updates!

Beware! Many of the things described have not been introduced in class. You might want to start on the parts that you know how to do, and add things as we learn about them. In particular, we will be discussing curves in class 11/9-11/14. Also, Programming assignment 4 should give you a running head start on this one.

Project due: Tuesday, November 21

Late projects will be accepted according to the (new) class late policy. Just because it is Thanksgiving week, the deadlines will not be pushed back. (so turn things in by Friday for this to be a "late" assignment (lose 1/2 letter grade for the first one), and after Friday things will be "very late" (1/2 letter grade per day). And remember, not turning in a project is worse than getting an F.

Overview

In this assignment, you must create a program that allows the user to create a train track and to animate a train that moves along the track. You must allow the user to place other objects into the world (so that there's scenery for the train). Finally, you should allow the user to create tracks that aren't just on the ground (to make a rollercoaster, not just a train).

The purposes of this assignment are to give you an experience writing an interactive 3D program, and exposure to working with curves. Therefore, for this assignment, getting basic 3D functionality (such as viewing and view control) and getting the curves right are essential to the grade. Getting the program to look nice is less important (it's a good added feature, but there will be another assignment that focuses on this later in the semester).

You are to write this program doing the drawing with the OpenGL graphics library under windows NT. (You may develop your program under other systems, but as with other assignments in this class, you will be required to demonstrate your code on the machines in the CS instructional labs). You may use whatever user interface tools you wish (we recommend FlTk, but GLUT would be an acceptible alternative).

Pep Talk, Ground Rules, and Grading

Because of the way that grading works, it is more important to get the basic parts of the assignment correct than to make fancier features. If you make a very simple train that moves correctly along the track, and give the user a very basic way to specify the track, you will be much better off than if you made very fancy scenery, but don't have a working train. The assignment should give you ideas as to what's most important.

Be sure to think and plan BEFORE you write any code. Having a general strategy about how to tackle this project is the key to doing it. It's too big to swallow whole.

Programming assignment 4 (and Mark's and my example code for it) are a good start to doing this assignment.

You are permitted to use the example code (remember to attribute code that you get from elsewhere), user interface toolkits, "general purpose" data structure libraries (like the STL), and OpenGL. If there is some other code that you would like to use, please ask first.

A basic version of this project is probably in the 1000 line range.

You can play with my example to get ideas as to what it should do.

Getting Started in 3D

For many of you, this will be the first time you've written a 3D program with OpenGL (or even period). With other projects, we first gave you homework that forced you to learn the basics of how to use the programming tools. Because of time constraints, we did not do that with this project.

Hopefully, all of the mathematics of 3D programming were explained in the discussions in class. The OpenGL book does a good job at explaining how these ideas are mapped to the specific code that you need to write.

I recommend that you try something simple to make sure that you have all of the pieces. For example, try writing a simple program that displays a simple 3D object (like a cube) hovering over a "floor." Use this program to try out the basic features that you need: setting up material properties and lighting, providing the user with control of the viewpoint, and moving objects around. To get started, look at the example programs.

Making the Track

You must allow the user to specify a train track that is a curve along the floor. You must draw the track along the ground, as well as drawing the ground as a flat plane.

The simplest thing would be to allow the user to place a series of points along the floor and to create an interpolating cubic spline (e.g. a cardinal spline) between the points. You should use a curve that is at least C(1) continuous. (If you're stuck, you can make the track out of straight segments, however, your train will look silly when it makes abrupt turns! )

You might want to give a more controllable curve (like a Bezier and allow the user to control the tangents). Or, you might want to make tracks that are C(2) continuous since they will lead to better train motions. The sample solution uses Cardinal splines as well as periodic, uniform, cubic B-Splines.

Specifying the track is actually a 2D problem. It is probably easier to create a 2D user interface than it is to create a 3D user interface. This is totally acceptable. The easiest user interface would force the user to type coordinate points in.

A non-interactive interface (e.g. requiring the user to type in the coordinates of the points) is clearly less desirable than one that allows the user to drag points around. However, it is more important to make sure you can make a train move around the track than to have a nice interface.

The track should be a loop, always.

User Interfaces in 3D

How to interactively control things in 3D is a very hard problem. Especially given that your only input device is a 2D pointer (the mouse). (well, there's the keyboard too).

The most basic user interface would force the user to type in all coordinates. While this is undesireable, it is probably better for you to implement this first, get the other parts of the assignment working (drawing the track and train), and then improve your interface as time permits.

Another strategy for the interface is to treat it as a 2D problem. Give the user a "top" view of the "world," and allow them to do things in 2D. This will be completely suffificient until you get to roller coasters.

The Train

You should make a train that can move along the track. The train needs to point in the correct direction. It is acceptable if the center of the train is on the track and pointing in the diretion of the tangent to the track. Technically, the front and back wheels of the train should be on the track (and they swivel with respect to the train). If you implement this level of detail, please say so in your documentation. It will look cool.

In order to correctly orient the train, you must define a coordinate system whose orientation moves along with the curve. The tangent to the curve only provides one direction. You must somehow come up with the other two directions to provide an entire coordinate frame. For a flat track, this isn't too difficult. (you know which way is up). However, when you have a roller coaster, things become more complicated. In fact, the sample solution is wrong in that it will break if the train does a loop.

The sample solution defines the coordinate frame as follows: (note: you might want to play with the sample solution to understand the effects of this)
  1. The tangent vector is used to define the forward (positive Z) direction.
  2. The "right" axis (positive X) is defined by the cross product of the world up vector (Y axis) and the forward vector.
  3. The local "up" axis is defined by the cross product of the first two.

A more advanced train would be made out of several cars that remain attached as the train moves around the track. In this case, each car must point in the correct direction. This is actually kindof tricky to implement, but is a good challenge for the mathematically inclined. (you need to figure out an arc-length parameterization for the curve).

The most basic train would be drawn as a rectangular box. Hopefully, you will choose to make something nicer looking.

Drawing your tracks as tracks (e.g. with parallel rails and planks going across) would be very cool, but is a challenging advanced feature (since you need to figure out how to make parallel curves and to make the cross pieces be evenly spaced).

Animation

You must allow the user to animate the train driving along the track.

Note: probably, your track will have different parameterizations as the train moves along it. A basic implementation would have the train moving with a constant velocity in parameter space. A more advanced implementation would give the user the option of having the train move with a constant velocity in its position. You can either implement this using the correct mathematics, or with the hack discussed in class. (I did the latter in my sample solution). If you implement constant velocity motion, you should allow the user to switch this on and off to emphasize the difference.

You must give the user the option of either viewing the "whole world" or viewing out the front of the train. If the user is looking out the front of the train, and the train is being animated, the user should see what it would look like to ride the train.

The World

You should allow the user to place objects other than the train tracks into your world. Placing colored cubes in the world is OK. Placing more complicated objects would make your project more interesting. The goal is to allow for some scenery to view as the train drives along.

Lighting

You should use lighting to make your world look nicer.

One desireable advanced feature would be to allow the user to position a light, and to use this light not only for object lighting but also to position hack shadows (as will be described in class).

Viewing

You must allow the user to switch between a view out the front of the train and a "birds-eye" view of the whole world. For the latter, you should give them some kind of control over their viewpoint, such as a virtual trackball or what was provided in the sample code (which is a broken virtual trackball).

You may also want to provide 2D (orthographic or plan) views of the world, such as a top view. These views are convenient for user interfaces.

Roller Coasters

A Roller Coaster is simply a train in which the track isn't flat. This is probably simple for you to do if you implemented your train correctly.

To make a good roller coaster (e.g. for a more advanced project):

You need to have a good way to determine which way is up for the rider of the roller coaster (e.g. you know 1 direction in the Frenet frame, so you need to pick a twist around the forward axis). You might give the user the ability to specify the twist along the track (as a parameter that gets interpolated), or simply compute it in some reasonable way.

Roller coasters do not go at constant velocities - they speed up and slow down. Simulating this (in a simple way) isn't that difficult, and would make for a good advanced feature. Remember that Kinetic Energy - Potential Energy should remain constant (or decrease based on friction). This lets you compure what the velocity should be based on how high the roller coaster is.

What it looks like

A basic assignment might just draw simple lines and boxes. I am hoping that you'll put some effort into making it look nicer, but creating more interesting objects in your world, using texture or other things to make your world more attractive, ...

The Sample Answer

I have built a sample solution that has some advanced features. The version that is currently is on the course web page is a pretty reasonable assignment. It has most of the basic features, and a little bit more.

However, it does let you see different curve types for the track, do the different kinds of viewing, and animate the "train" (including riding it). I implemented "constant velocity" using the tangent magnitude approximation described in class. You can move the light around, and see the hacked shadows move around.

When you drag a point, it moves parallel to the ground plane. If you hold down the control key, you drag the point perpendicular to the ground plane (up and down).

Note: this assignment fails some of the basic criteria (you can't make scenery), and does only very simple drawing. However, it should give you some ideas. And I may make it better since it's fun.

Last year, a very similar assignment was given out. I will try to make some more assignments available for you to play with. Many students made projects that were much cooler than my sample!

What you will turn in...

Into your handin directory, you will need to provide the complete source code, project files, and workspace files. You will need to provide a README.txt file explaining what each file you hand in is. You will need to provide a text file called "DOCUMENTATION.TXT" that can serve as a user manual for your program, describing which features you implemented, and how they are accessed.

We may ask you to answer questions about your project. If we do this, we'll provide them later.

 

Last modified:
(c) 2000 Michael Gleicher