Theme: The algorithm for computing Bezier curve points
After disappointing first part of this tutorial series, we are continuing with something more advanced algorithm.
In this part we will implement the algorithm for computing Bezier curve points but we won't to explain it in details. Instead, I think it is commented quit well.
Besides that, there are many other tutorials about Bezier curves and the main goal of this tutorial is
not to learn theory of computer graphics but to get ball trajectory in 3D perspective.
So maybe it is the best for you to imagine this algorithm as a "black box" with control polygon points as an input snapshot and Bezier curve points as an output snapshot.
As usual, at the beginning of the program we must define some global variables:
After defining global variables we can use them in functions of Bezier curve algorithm and this is our "black box":
Before we start the engine for calculating and drawing Bezier curve we must initialize some parameters:
Finally, the main program loop is placed in onEnterFrame function.
In fact, there is implemented a final state machine with several different states defined by global variable gameMode:
For choosing starting and ending point of the control polygon please read the first part. Here is a result of implementing all this code:
As you see, we are slowly getting contours of the ball trajectory using Bezier curve algorithm.
In the next part we will add some features to display whole Bezier curve with its control polygon and calculated points.
We will also implement some simple interface for changing number of bezier points and polygon height.