The image on the previous post lacked fluidity between bezier constructs because the control points were placed randomly, so I attempted placing them at the centre of the two end points (giving a straight line), and nudging them out until the curves felt right.
I realised, if a line drawn from B1P2 to B2P1 passes through the intersection of points B1P3 and B2P0, my curves reached what I now referred to (highly scientifically) as "ultimate smoothness"...
Subsequently I saw this, which explains the phenomenon much better than I had done so in my head:
"It means that in order for our two Bézier curves to be smooth, the slope between P2 and P3 in the first curve must be the same as the slope between P0 and P1 in the second curve. In other words, they must be co-linear!" - Anon
...and here's the smooth track!
Tuesday, 21 January 2014
Sunday, 19 January 2014
World Representation
I decided early on that I wanted to use pure mathematical constructs for the track, the objects on it, collision, and physics. I didn't want to "hack" or fake it, and I wanted the game to feel organic and slick. I also had every intention of getting great gameplay on the target devices before adding graphics (the icing in my humble opinion).
Rather than start with a game design, I began to code up a library of vertex-based primitives such as points, circles, and lines, all of which inherit from a base Primitive object. While in most scenarios composition or non-OO principles would be preferable, in this explicit scenario, I want these objects to be interchangeable at a fundamental level, so I can construct the game world effortlessly.
I also decided to utilised bézier curves, as all mobile train-based games I've seen are grid-based, which I felt made them feel rather constrained.

- Wikipedia

- Wikipedia
Béziers are incredibly powerful parametric curves, first popularised in the 1960s by Pierre Bézier when he was designing Renault automobiles. They are easy for humans to define (many CAD applications like Photoshop and 3D Studio Max use them), and they are easy for computers to interpret (game engines use them for plotting camera routes for example).
Bézier curves are essentially a collection of two or more control points, which represent a line. This line can be curved through n-dimensional space with manipulation of control points between the start and end point.
A cubic bézier curve is commonly utilised for game development, as higher order curves become more difficult to compute. Curves of n points can be generalised, but it is generally less expensive to split a higher order curve into multiple cubic or quadratic curves.
Finding a point on the curve for t is the easy bit...
...but points are not uniformly distributed when the curve is stretched towards the middle control points.
To deal with this, I plotted a first pass, drew lines between each point, then walked the curve, dropping new points based on its length. Effectively this replaces the control points with a number of small lines, of equidistant length, but the original curve makes organic track design very straightforward, and easy to tweak.
I chose to represent trains as circles initially (textures will be added later) and then plot them along the lines programatically. Here's an example, with a test train in the bottom right hand corner...
Project Shunt
While studying artificial intelligence and graphics at university I was tasked with a problem which I had to solve by writing an artificial agent. It took the form of a train shunting puzzle, which required the utilisation of problem states and heuristics to find the optimal solution. An example of a shunting puzzle is available here.
Usually the requirements for a shunting problem are very simple, but achieving them can be anything between straightforward, and brain meltingly difficult, depending on many variables such as track complexity, the number of carriages, and the criteria affecting free movement of trains.
At the time I commented on how it could be more interesting to provide the problem as a game, than to attempt to solve it with a software algorithm. I have finally begun to work on this goal, over five years after I first decided it was a worthy undertaking. I will document my progress here.
I hope to release the final product some time this year, initially in the Google PlayStore, and shortly afterwards in the iOS App Store.
Subscribe to:
Posts (Atom)



