Polycode
Polycode::BezierCurve Class Reference

A Bezier curve. More...

List of all members.

Public Member Functions

 BezierCurve ()
 Default constructor.
BezierPointgetControlPoint (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.

Detailed Description

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.


Member Function Documentation

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.

Parameters:
xX position of the point and both handles.
yY 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.

Parameters:
p1xX position of the first handle point.
p1yY position of the first handle point.
p2xX position of the middle point.
p2yY position of the middle point.
p3xX position of the second handle point.
p3yY 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.

Parameters:
xX position of the point and both handles.
yY position of the point and both handles.
zZ 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.

Parameters:
p1xX position of the first handle point.
p1yY position of the first handle point.
p1zZ position of the first handle point.
p2xX position of the middle point.
p2yY position of the middle point.
p2zZ position of the middle point.
p3xX position of the second handle point.
p3yY position of the second handle point.
p3zZ position of the second handle point.
BezierPoint * BezierCurve::getControlPoint ( unsigned int  index)

Returns a control point by index.

Parameters:
indexIndex of the control point to return.
Returns:
Control point at specified index.
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.

Parameters:
aNormalized (0-1) position along the curve.
Returns:
Height value at specified position.
unsigned int BezierCurve::getNumControlPoints ( )

Returns the total number of control points in the curve.

Returns:
Total number of control points.
Vector3 BezierCurve::getPointAt ( Number  a)

Returns the 3d point of the curve at a specified point on the curve.

Parameters:
aNormalized (0-1) position along the curve.
Returns:
3d point at specified position.
Vector3 BezierCurve::getPointBetween ( Number  a,
BezierPoint bp1,
BezierPoint bp2 
)

Returns the 3d point of the curve at a specified point between two points.

Parameters:
aNormalized (0-1) position between two points
Returns:
3d point at specified position.