Polycode
|
A Bezier curve. More...
Public Member Functions | |
BezierCurve () | |
Default constructor. | |
BezierPoint * | getControlPoint (unsigned int index) |
Returns a control point by index. | |
unsigned int | getNumControlPoints () |
Returns the total number of control points in the curve. | |
void | addControlPoint (Number p1x, Number p1y, Number p1z, Number p2x, Number p2y, Number p2z, Number p3x, Number p3y, Number p3z) |
void | addControlPoint3dWithHandles (Number p1x, Number p1y, Number p1z, Number p2x, Number p2y, Number p2z, Number p3x, Number p3y, Number p3z) |
Adds a new control point to the curve after the last point. | |
void | addControlPoint3d (Number x, Number y, Number z) |
Adds a new control point to the curve with handles in the same place as the middle points. | |
void | addControlPoint2dWithHandles (Number p1x, Number p1y, Number p2x, Number p2y, Number p3x, Number p3y) |
Adds a new control point to the curve after the last point using 2d coordinates. | |
void | addControlPoint2d (Number x, Number y) |
Adds a new control point to the curve with handles in the same place as the middle points using 2d coordinates.The Z value of the coordinates is set to 0. | |
Number | getHeightAt (Number a) |
Returns the height of the curve at a specified point on the curve. | |
Vector3 | getPointAt (Number a) |
Returns the 3d point of the curve at a specified point on the curve. | |
Vector3 | getPointBetween (Number a, BezierPoint *bp1, BezierPoint *bp2) |
Returns the 3d point of the curve at a specified point between two points. | |
void | rebuildBuffers () |
Rebuilds the height cache buffers for 2d height curves. |
A Bezier curve.
This class can be used to draw smooth curves or move things smoothly on curves. It's also used internally for skeletal animation. The curves are 3-dimensional, but convenience methods are added for 2d curves and there is a caching mechanism for 2d height data to speed up bezier curve usage in animation.
A bezier curve consists of control points, each having 3 points: one middle point and two 'handles'. The middle point is the actual position of the control point and the two side points serve as vectors defining how the curve curves towards the next control points.
void BezierCurve::addControlPoint | ( | Number | p1x, |
Number | p1y, | ||
Number | p1z, | ||
Number | p2x, | ||
Number | p2y, | ||
Number | p2z, | ||
Number | p3x, | ||
Number | p3y, | ||
Number | p3z | ||
) |
void BezierCurve::addControlPoint2d | ( | Number | x, |
Number | y | ||
) |
Adds a new control point to the curve with handles in the same place as the middle points using 2d coordinates.The Z value of the coordinates is set to 0.
x | X position of the point and both handles. |
y | Y position of the point and both handles. |
void BezierCurve::addControlPoint2dWithHandles | ( | Number | p1x, |
Number | p1y, | ||
Number | p2x, | ||
Number | p2y, | ||
Number | p3x, | ||
Number | p3y | ||
) |
Adds a new control point to the curve after the last point using 2d coordinates.
The Z value of the coordinates is set to 0.
p1x | X position of the first handle point. |
p1y | Y position of the first handle point. |
p2x | X position of the middle point. |
p2y | Y position of the middle point. |
p3x | X position of the second handle point. |
p3y | Y position of the second handle point. |
void BezierCurve::addControlPoint3d | ( | Number | x, |
Number | y, | ||
Number | z | ||
) |
Adds a new control point to the curve with handles in the same place as the middle points.
x | X position of the point and both handles. |
y | Y position of the point and both handles. |
z | Z position of the point and both handles. |
void BezierCurve::addControlPoint3dWithHandles | ( | Number | p1x, |
Number | p1y, | ||
Number | p1z, | ||
Number | p2x, | ||
Number | p2y, | ||
Number | p2z, | ||
Number | p3x, | ||
Number | p3y, | ||
Number | p3z | ||
) |
Adds a new control point to the curve after the last point.
p1x | X position of the first handle point. |
p1y | Y position of the first handle point. |
p1z | Z position of the first handle point. |
p2x | X position of the middle point. |
p2y | Y position of the middle point. |
p2z | Z position of the middle point. |
p3x | X position of the second handle point. |
p3y | Y position of the second handle point. |
p3z | Z position of the second handle point. |
BezierPoint * BezierCurve::getControlPoint | ( | unsigned int | index | ) |
Returns a control point by index.
index | Index of the control point to return. |
Number BezierCurve::getHeightAt | ( | Number | a | ) |
Returns the height of the curve at a specified point on the curve.
Heights are cached into a buffer with a finite cache precision to speed up the curve usage in animation. If you need to quickly get 2D height out of a curve and you don't care about total precision, use this method.
a | Normalized (0-1) position along the curve. |
unsigned int BezierCurve::getNumControlPoints | ( | ) |
Returns the total number of control points in the curve.
Vector3 BezierCurve::getPointAt | ( | Number | a | ) |
Returns the 3d point of the curve at a specified point on the curve.
a | Normalized (0-1) position along the curve. |
Vector3 BezierCurve::getPointBetween | ( | Number | a, |
BezierPoint * | bp1, | ||
BezierPoint * | bp2 | ||
) |
Returns the 3d point of the curve at a specified point between two points.
a | Normalized (0-1) position between two points |