Skip to content

Cubic Bézier Curve Editor

Updated:  at  08:26 AM

Cubic Bézier curves defining a non-linear path between two points. In this post, we’ll explore how to create, edit, and use cubic Bézier curves in a game loop. Our goal is to model a simplified arcade-style vehicle physics that’s efficient to compute in real-time and easily editable.


The Maths

A cubic bézier curve is defined by four points:

Then a position along the line can be calculated by:


The Editor

To begin, I built a simple GUI for creating and editing cubic Bézier curves. These curves can model behavior such as acceleration or turning effectiveness based on velocity.

Acceleration

In this example, the vehicle’s acceleration rate peaks early, just after it starts moving, it then gradually decreases as it nears top speed. This simplified model avoids complex calculations suited to an arcade game rather than a simulation.

(0%, 55%)(100%, 0%)(33%, 100%)(62%, 0%)VelocityRate of Acceleration

Turning effectiveness

At high speeds, the turning radius should be large (less responsive), while at slower speeds it should be tighter. To simulate realistic behavior, turning effectiveness should be zero when there’s no forward momentum.

(0%, 0%)(100%, 24%)(10%, 0%)(6%, 100%)VelocityRate of Turning

The Optimisation

For a game loop rather than evaluating cubic bézier equations every frame, we can optimize performance by precomputing curve values into a lookup table (LUT). This allows for fast interpolation with minimal CPU cost during runtime.

Test Results

The LUT was on average x70 faster per loop. The downsides are an initial hit when creating the LUT and the values being returned between values in the look up table being potentially slight inaccurate.


The Demo

Using the editors above you can manipulate the physics model of this vehicle, then using the W, A, S and D keys to interact with it to see how it performs



Next Post
Model Vehicle Movement