Welcome guest, here you can read the whole selected article.

The website with source code tutorials for programming flash games.
If you are looking for a fun, you can also play my online games.

Home | Tutorials | Games | Others | About »  Sign Up | Log In  « 



Creating a ball trajectory to look like a moving ball in 3D perspective - Part 2

Posted on 19-Mar-2008, 09:16:13
All parts of this tutorial series: 1 2 3 4

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.

Complete source code you can download here!







No comments yet!



Please login if you wish to post your comments!

Games





Recent articles





Copyright 2009 © Ask For Game Task. All rights reserved.