Panda3D
|
A PiecewiseCurve is a curve made up of several curve segments, connected in a head-to-tail fashion. More...
#include "piecewiseCurve.h"
Classes | |
class | Curveseg |
Public Member Functions | |
virtual bool | adjust_point (float t, float px, float py, float pz) |
Recomputes the curve such that it passes through the point (px, py, pz) at time t, but keeps the same tangent value at that point. | |
virtual bool | adjust_pt (float t, float px, float py, float pz, float tx, float ty, float tz) |
Recomputes the curve such that it passes through the point (px, py, pz) with the tangent (tx, ty, tz). | |
virtual bool | adjust_tangent (float t, float tx, float ty, float tz) |
Recomputes the curve such that it has the tangent (tx, ty, tz) at time t, but keeps the same position at the point. | |
virtual TypeHandle | force_init_type () |
virtual bool | get_2ndtangent (float t, LVecBase3f &tangent2) const |
Returns the tangent of the first derivative of the curve at the point t. | |
virtual bool | get_bezier_segs (BezierSegs &bz_segs) const |
Fills up the indicated vector with a list of BezierSeg structs that describe the curve. | |
ParametricCurve * | get_curveseg (int ti) |
Returns the curve segment corresponding to the given index. | |
virtual float | get_max_t () const |
Returns the upper bound of t for the entire curve. | |
int | get_num_segs () const |
Returns the number of curve segments that make up the Piecewise curve. | |
virtual bool | get_point (float t, LVecBase3f &point) const |
Returns the point of the curve at a given parametric point t. | |
virtual bool | get_pt (float t, LVecBase3f &point, LVecBase3f &tangent) const |
Simultaneously returns the point and tangent of the curve at a given parametric point t. | |
virtual bool | get_tangent (float t, LVecBase3f &tangent) const |
Returns the tangent of the curve at a given parametric point t. | |
float | get_tend (int ti) const |
Returns the parametric end of the given segment of the curve. | |
float | get_tlength (int ti) const |
Returns the parametric length of the given segment of the curve. | |
float | get_tstart (int ti) const |
Returns the parametric start of the given segment of the curve. | |
virtual TypeHandle | get_type () const |
bool | insert_curveseg (int ti, ParametricCurve *seg, float tlength) |
Inserts a new curve segment at the indicated index. | |
virtual bool | is_valid () const |
Returns true if the curve is defined. | |
void | make_nurbs (int order, int num_cvs, const float knots[], const LVecBase4f cvs[]) |
Defines the curve as a general NURBS curve. | |
virtual bool | rebuild_curveseg (int rtype0, float t0, const LVecBase4f &v0, int rtype1, float t1, const LVecBase4f &v1, int rtype2, float t2, const LVecBase4f &v2, int rtype3, float t3, const LVecBase4f &v3) |
Rebuilds the current curve segment (as selected by the most recent call to find_curve()) according to the specified properties (see CubicCurveseg::compute_seg). | |
void | remove_all_curvesegs () |
Removes all curve segments from the curve. | |
bool | remove_curveseg (int ti) |
Removes the given curve segment from the curve and frees it. | |
bool | set_tlength (int ti, float tlength) |
Sets the parametric length of the given segment of the curve. | |
Static Public Member Functions | |
static TypeHandle | get_class_type () |
static void | init_type () |
Protected Member Functions | |
virtual int | complete_pointers (TypedWritable **plist, BamReader *manager) |
Takes in a vector of pointes to TypedWritable objects that correspond to all the requests for pointers that this object made to BamReader. | |
float | current_seg_range (float t) const |
Returns a number in the range [0,1], representing the conversion of t into the current segment's coordinate system (the segment last returned by find_curve). | |
void | fillin (DatagramIterator &scan, BamReader *manager) |
Function that reads out of the datagram (or asks manager to read) all of the data that is needed to re-create this object and stores it in the appropiate place. | |
bool | find_curve (const ParametricCurve *&curve, float &t) const |
Finds the curve corresponding to the given value of t. | |
virtual void | write_datagram (BamWriter *manager, Datagram &me) |
Function to write the important information in the particular object to a Datagram. | |
Protected Attributes | |
int | _last_ti |
pvector< Curveseg > | _segs |
A PiecewiseCurve is a curve made up of several curve segments, connected in a head-to-tail fashion.
The length of each curve segment in parametric space is definable.
Definition at line 30 of file piecewiseCurve.h.
bool PiecewiseCurve::adjust_point | ( | float | t, |
float | px, | ||
float | py, | ||
float | pz | ||
) | [virtual] |
Recomputes the curve such that it passes through the point (px, py, pz) at time t, but keeps the same tangent value at that point.
Reimplemented from ParametricCurve.
Definition at line 132 of file piecewiseCurve.cxx.
References find_curve(), and rebuild_curveseg().
bool PiecewiseCurve::adjust_pt | ( | float | t, |
float | px, | ||
float | py, | ||
float | pz, | ||
float | tx, | ||
float | ty, | ||
float | tz | ||
) | [virtual] |
Recomputes the curve such that it passes through the point (px, py, pz) with the tangent (tx, ty, tz).
Reimplemented from ParametricCurve.
Definition at line 187 of file piecewiseCurve.cxx.
References find_curve(), and rebuild_curveseg().
bool PiecewiseCurve::adjust_tangent | ( | float | t, |
float | tx, | ||
float | ty, | ||
float | tz | ||
) | [virtual] |
Recomputes the curve such that it has the tangent (tx, ty, tz) at time t, but keeps the same position at the point.
Reimplemented from ParametricCurve.
Definition at line 163 of file piecewiseCurve.cxx.
References find_curve(), and rebuild_curveseg().
int PiecewiseCurve::complete_pointers | ( | TypedWritable ** | plist, |
BamReader * | manager | ||
) | [protected, virtual] |
Takes in a vector of pointes to TypedWritable objects that correspond to all the requests for pointers that this object made to BamReader.
Reimplemented from TypedWritable.
Definition at line 626 of file piecewiseCurve.cxx.
float PiecewiseCurve::current_seg_range | ( | float | t | ) | const [protected] |
Returns a number in the range [0,1], representing the conversion of t into the current segment's coordinate system (the segment last returned by find_curve).
This operation is already performed automatically on the t passed into find_seg; this function is useful only to adjust a different value into the same range.
It is an error to call this function if find_curve() has not yet been called, or if find_curve() returned false from its previous call.
Definition at line 558 of file piecewiseCurve.cxx.
void PiecewiseCurve::fillin | ( | DatagramIterator & | scan, |
BamReader * | manager | ||
) | [protected, virtual] |
Function that reads out of the datagram (or asks manager to read) all of the data that is needed to re-create this object and stores it in the appropiate place.
Reimplemented from ParametricCurve.
Reimplemented in HermiteCurve, and NurbsCurve.
Definition at line 603 of file piecewiseCurve.cxx.
References DatagramIterator::get_float64(), DatagramIterator::get_uint32(), and BamReader::read_pointer().
Referenced by RopeNode::fillin(), and HermiteCurve::fillin().
bool PiecewiseCurve::find_curve | ( | const ParametricCurve *& | curve, |
float & | t | ||
) | const [protected] |
Finds the curve corresponding to the given value of t.
If t is inside the curve's defined range, sets curve to the appropriate segment, translates t to [0,1] to index into the segment's coordinate system, and returns true. If t is outside the curve's defined range, sets curve to the nearest segment and t to the nearest point on this segment, and returns false.
Definition at line 463 of file piecewiseCurve.cxx.
Referenced by adjust_point(), adjust_pt(), adjust_tangent(), get_2ndtangent(), get_point(), get_pt(), and get_tangent().
bool PiecewiseCurve::get_2ndtangent | ( | float | t, |
LVecBase3f & | tangent2 | ||
) | const [virtual] |
Returns the tangent of the first derivative of the curve at the point t.
Implements ParametricCurve.
Definition at line 116 of file piecewiseCurve.cxx.
References find_curve().
bool PiecewiseCurve::get_bezier_segs | ( | BezierSegs & | bz_segs | ) | const [virtual] |
Fills up the indicated vector with a list of BezierSeg structs that describe the curve.
This assumes the curve is a PiecewiseCurve of CubicCurvesegs. Returns true if successful, false otherwise.
Reimplemented from ParametricCurve.
Definition at line 417 of file piecewiseCurve.cxx.
ParametricCurve * PiecewiseCurve::get_curveseg | ( | int | ti | ) |
Returns the curve segment corresponding to the given index.
Reimplemented in HermiteCurve, and NurbsCurve.
Definition at line 240 of file piecewiseCurve.cxx.
float PiecewiseCurve::get_max_t | ( | ) | const [virtual] |
Returns the upper bound of t for the entire curve.
The curve is defined in the range 0.0f <= t <= get_max_t().
Reimplemented from ParametricCurve.
Definition at line 67 of file piecewiseCurve.cxx.
Referenced by insert_curveseg().
int PiecewiseCurve::get_num_segs | ( | ) | const |
Returns the number of curve segments that make up the Piecewise curve.
Definition at line 229 of file piecewiseCurve.cxx.
Referenced by make_nurbs().
bool PiecewiseCurve::get_point | ( | float | t, |
LVecBase3f & | point | ||
) | const [virtual] |
Returns the point of the curve at a given parametric point t.
Returns true if t is in the valid range 0.0f <= t <= get_max_t(); if t is outside this range, sets point to the value of the curve at the beginning or end (whichever is nearer) and returns false.
Implements ParametricCurve.
Definition at line 82 of file piecewiseCurve.cxx.
References find_curve().
bool PiecewiseCurve::get_pt | ( | float | t, |
LVecBase3f & | point, | ||
LVecBase3f & | tangent | ||
) | const [virtual] |
Simultaneously returns the point and tangent of the curve at a given parametric point t.
Implements ParametricCurve.
Definition at line 213 of file piecewiseCurve.cxx.
References find_curve().
bool PiecewiseCurve::get_tangent | ( | float | t, |
LVecBase3f & | tangent | ||
) | const [virtual] |
Returns the tangent of the curve at a given parametric point t.
Implements ParametricCurve.
Definition at line 100 of file piecewiseCurve.cxx.
References find_curve().
float PiecewiseCurve::get_tend | ( | int | ti | ) | const |
Returns the parametric end of the given segment of the curve.
Definition at line 350 of file piecewiseCurve.cxx.
float PiecewiseCurve::get_tlength | ( | int | ti | ) | const |
Returns the parametric length of the given segment of the curve.
Definition at line 326 of file piecewiseCurve.cxx.
Referenced by remove_curveseg(), and set_tlength().
float PiecewiseCurve::get_tstart | ( | int | ti | ) | const |
Returns the parametric start of the given segment of the curve.
Definition at line 338 of file piecewiseCurve.cxx.
bool PiecewiseCurve::insert_curveseg | ( | int | ti, |
ParametricCurve * | seg, | ||
float | tlength | ||
) |
Inserts a new curve segment at the indicated index.
The curve segment must have been allocated via new; it will be freed using delete when it is removed or the PiecewiseCurve destructs.
If the curve segment is not inserted at the end, its tlength is subtracted from that of the following segment, so that the overall length of the curve is not changed.
Definition at line 260 of file piecewiseCurve.cxx.
References get_max_t().
Referenced by make_nurbs(), and NurbsCurve::recompute().
bool PiecewiseCurve::is_valid | ( | ) | const [virtual] |
Returns true if the curve is defined.
In the case of a PiecewiseCurve, this means we have at least one segment.
Reimplemented from ParametricCurve.
Definition at line 55 of file piecewiseCurve.cxx.
void PiecewiseCurve::make_nurbs | ( | int | order, |
int | num_cvs, | ||
const float | knots[], | ||
const LVecBase4f | cvs[] | ||
) |
Defines the curve as a general NURBS curve.
The order is the degree plus one and must be 1, 2, 3, or 4; cvs is an array of num_cvs points each with a homogeneous coordinate; knots is an array of num_cvs+order knot values.
This creates the individual curve segments and sets up the basis matrices, but does not store the CV's or knot values so the curve shape is not later modifiable.
Definition at line 391 of file piecewiseCurve.cxx.
References get_num_segs(), insert_curveseg(), and remove_all_curvesegs().
bool PiecewiseCurve::rebuild_curveseg | ( | int | rtype0, |
float | t0, | ||
const LVecBase4f & | v0, | ||
int | rtype1, | ||
float | t1, | ||
const LVecBase4f & | v1, | ||
int | rtype2, | ||
float | t2, | ||
const LVecBase4f & | v2, | ||
int | rtype3, | ||
float | t3, | ||
const LVecBase4f & | v3 | ||
) | [virtual] |
Rebuilds the current curve segment (as selected by the most recent call to find_curve()) according to the specified properties (see CubicCurveseg::compute_seg).
Returns true if possible, false if something goes horribly wrong.
Reimplemented in HermiteCurve, and NurbsCurve.
Definition at line 442 of file piecewiseCurve.cxx.
Referenced by adjust_point(), adjust_pt(), and adjust_tangent().
void PiecewiseCurve::remove_all_curvesegs | ( | ) |
Removes all curve segments from the curve.
Definition at line 314 of file piecewiseCurve.cxx.
Referenced by make_nurbs().
bool PiecewiseCurve::remove_curveseg | ( | int | ti | ) |
Removes the given curve segment from the curve and frees it.
Returns true if the segment was defined, false otherwise.
Definition at line 289 of file piecewiseCurve.cxx.
References get_tlength().
bool PiecewiseCurve::set_tlength | ( | int | ti, |
float | tlength | ||
) |
Sets the parametric length of the given segment of the curve.
The length of the following segment is lengthened by the corresponding amount to keep the overall length of the curve the same.
Definition at line 365 of file piecewiseCurve.cxx.
References get_tlength().
Function to write the important information in the particular object to a Datagram.
Reimplemented from ParametricCurve.
Reimplemented in HermiteCurve, and NurbsCurve.
Definition at line 580 of file piecewiseCurve.cxx.
References Datagram::add_float64(), Datagram::add_uint32(), and BamWriter::write_pointer().
Referenced by RopeNode::write_datagram(), and HermiteCurve::write_datagram().