Overview

Have you ever played with Brio trains as a child? Look no further, you can now build any brio track you want with the Brio Train Builder! The Brio Train Builder allows you to create brio tracks and also watch an animated train ride your custom tracks

Features

The brio train builder program has many features:

  • Build any track you'd like
    • Can add a left turn, right turn, or straight track to the end of the track
    • Can delete the last placed track
    • Can clear your track to start from scratch
  • Watch a train follow your track
    • Can make train jump
    • Can follow train with the camera
    • Can change the speed of the train
  • Train is fully animated!
    • Uses squash and stretch to simulate running engine. The amount of squash and stretch depends on the speed
    • Shoots out smoke particles! The faster the train goes, the more smoke it emits.
    • Train leans depending on the track curvature. The amount of lean depends on the train speed.
    • Jump animation also uses squash and stretch to make for a more animated action.




Method

Train Following the Curve

The train uses arc length parameterization in order to follow the track correctly. Based on the speed, distance, and time, the train calculates the current track it is on. All of the tracks are the same length, making it easy to calculate the correct track. Once the track is selected, arc length parameterization is used to locate the distance along the current track. The equations are below.





As you can see, for left and right tracks, we need to offset the x position by the radius of the curvature in order to correctly place the train on the track.

Squash and Stretch

The train squashes and stretches as it moves. When squashing and stretching, it is key to preserve volume. To squash and stretch the train, a simple scale is used over time. The scale changes based on time, and increases and decreases with a sine function. The amount of scale and the speed of the change depends on the speed of the train. The y position is scaled by our scale value, and the x and z components are scaled by 1/sqrt(scale). This preserves the volume of the train object.

Particle System

The particle system emits particles from the train with a random upward and horizontal velocity. Symplectic Euler is used with a simple gravitational force to control the velocity and position of the particles over time.

The particles will also decay over time to simulate smoke. Once the particles have fully decayed, they are deleted from the particle system. To visualize the decay, it is used to compute the current color and alpha value of the particle. The more the particle decays, the more it whitens and becomes transparent.





Track Collision Detection

In order to prevent users from making tracks that make no sense, collision detection is implemented when building the track. This ensures that no track passes over another. All tracks are given object aligned bounding boxes. However, because the track is two dimensional and has no depth, these bounding boxes are really just rectangles around the x and z position of the track. Because we are dealing with 2 dimensional rectangles, it allows us to do simple collision detection of rectangles.

2D rectangular collision detection can be calculated by projecting the corners of a rectangle onto the planes that are created from the other rectangle's points. A visual can be seen below. If points overlap on all planes, then the two rectangles are colliding. If even one plane does not have overlapping points from the rectangles, there is no collision. As can be seen by the image below, the two tracks are not colliding.

Video and Controls

Controls for the program

  • 'G' - Toggle between building track and viewing train
  • 'N' - Toggle track types when building
  • SPACE - place a track when in build mode
  • 'D' - delete last placed track when in build mode
  • 'C' - clear track when in build mode
  • 'L' - load track
  • 'S' - save track
  • 'F' - increase speed of train
  • 'V' - decrease speed of train
  • 'I' - view lines and bounding boxes of tracks
  • 'B' - Follow the train on the track
  • SPACE - make train jump when in view mode

Resources

  • Windows 10 for all models including train, tracks, and windmill
  • Eigen