The following script contains functions for calculating and making use of Bézier curves, which provide a convenient means for modeling smooth curves. These curves can be used to make smooth, non-linear gradients and transitions, for use in simple physics systems or just to make visual interface elements look prettier.
One example might be to create a realistic flight path for a ship in 3D, creating a natural looking trail in 2D, drawing smooth curves on dialogs, generating realistic random movement for units etc.
The first and last two points define the endpoints and the other control points are used to pule the line in different directions. So for instance using the control points (0,0,4), (0, 4, 3), (4, 4, 2), (4, 0, 1), (0, 0, 0) would create a downward, clockwise spiral which might be suitable for a plane with a damaged wing to fall out of the sky.
When the map is loaded it automatically generates bezier curves to demonstrate. The control points are marked by pineapples and the curve is marked out using apples. The camera then rotates around showing you the curve in 3D.
To use in your project just copy/paste the functions needed. Unless you are creating a map called "FRUIT IN SPACE" you will have to change the values to suit your needs. Once you have the control points you want pass the array to the bezier points function along with a value of how far along the curve you want the point for. 0 is equal to the starting point and 1 equals the end. These pictures are created using values evenly spaced between 0 and 1.
Here is a picture of a bezier curve using 5 randomized control points (the fourth is very close to the start so the pineapples overlap slightly)
It can be seen how the control points pull the curve towards themselves.
If the control points are random and restricted to a region then too many points just creates a jumble, but with slight modification here is an example of 14 points:
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Description
The following script contains functions for calculating and making use of Bézier curves, which provide a convenient means for modeling smooth curves. These curves can be used to make smooth, non-linear gradients and transitions, for use in simple physics systems or just to make visual interface elements look prettier.
One example might be to create a realistic flight path for a ship in 3D, creating a natural looking trail in 2D, drawing smooth curves on dialogs, generating realistic random movement for units etc.
The first and last two points define the endpoints and the other control points are used to pule the line in different directions. So for instance using the control points (0,0,4), (0, 4, 3), (4, 4, 2), (4, 0, 1), (0, 0, 0) would create a downward, clockwise spiral which might be suitable for a plane with a damaged wing to fall out of the sky.
download/installation
The code for bezier curves is contained in this file: bezier demonstration
When the map is loaded it automatically generates bezier curves to demonstrate. The control points are marked by pineapples and the curve is marked out using apples. The camera then rotates around showing you the curve in 3D.
To use in your project just copy/paste the functions needed. Unless you are creating a map called "FRUIT IN SPACE" you will have to change the values to suit your needs. Once you have the control points you want pass the array to the bezier points function along with a value of how far along the curve you want the point for. 0 is equal to the starting point and 1 equals the end. These pictures are created using values evenly spaced between 0 and 1.
Here is a picture of a bezier curve using 5 randomized control points (the fourth is very close to the start so the pineapples overlap slightly)
It can be seen how the control points pull the curve towards themselves.
If the control points are random and restricted to a region then too many points just creates a jumble, but with slight modification here is an example of 14 points: