For this semester’s Computer Graphics course we’ve had a project where we create a virtual roller coaster scene in OpenGL with tracks represented by Catmull-Rom Splines.

spline

To generate the splines we are given a sequence of control points. We generate points along the spline using the following -

\[\begin{bmatrix} x & y & z \end{bmatrix} = \begin{bmatrix} u^3 & u^2 & u & 1 \end{bmatrix} \begin{bmatrix} -s & 2 - s & s - 2 & s \\ 2s & s - 3 & 3 - 2s & -s \\ -s & 0 & s & 0 \\ 0 & 1 & 0 & 0 \end{bmatrix} \begin{bmatrix} p_{i - 1} \\ p_{i} \\ p_{i + 1} \\ p_{i + 2} \\ \end{bmatrix}\]

Where the points \(p_{i - 1 ... i + 2}\) are four sequential control points, \(s\) describes the stiffness of the spline (in this project \(1/2\)), and \(u\) is the step distance along the spline (in this project \(0.01\)).

When the control points are read, I calculated and cached each of the points along the spline. I additionally cache the tangent, normal and binormal at each step to draw square rails with crossbars. The rails are GL_QUADS, and their normals are whichever is appropriate of the normal binormal or tangent to support GL_LIGHTING.

The roller coaster is floating in a skybox. Last weekend I saw Dune, so I threw some images from the film as textures of the box.

Here’s the result. It’s not particularly stunning but I think it illustrates the Catmull-Rom Splines well.