50 return !_segs.empty();
59 return _segs.empty() ? 0.0f : _segs.back()._tend;
72 bool result = find_curve(curve, t);
73 if (curve ==
nullptr){
77 return result | curve->get_point(t, point);
87 bool result = find_curve(curve, t);
90 return result | curve->get_tangent(t, tangent);
100 bool result = find_curve(curve, t);
103 return result | curve->get_2ndtangent(t, tangent2);
112 PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz) {
113 if (parametrics_cat.is_debug()) {
114 parametrics_cat.debug()
115 <<
"Adjusting point at " << t <<
" to " << px <<
" " << py <<
" " 120 bool result = find_curve(curve, t);
123 cerr <<
"No curve segment at t = " << t <<
"\n";
128 RT_POINT, t, LVecBase4(px, py, pz, 1.0f),
129 RT_TANGENT | RT_KEEP_ORIG, t, LVecBase4(),
130 RT_CV | RT_KEEP_ORIG, 0.0f, LVecBase4());
140 PN_stdfloat tx, PN_stdfloat ty, PN_stdfloat tz) {
142 bool result = find_curve(curve, t);
145 cerr <<
"No curve segment at t = " << t <<
"\n";
150 RT_POINT | RT_KEEP_ORIG, t, LVecBase4(),
151 RT_TANGENT, t, LVecBase4(tx, ty, tz, 0.0f),
152 RT_CV | RT_KEEP_ORIG, 0.0f, LVecBase4());
162 PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz,
163 PN_stdfloat tx, PN_stdfloat ty, PN_stdfloat tz) {
165 bool result = find_curve(curve, t);
168 cerr <<
"No curve segment at t = " << t <<
"\n";
173 RT_POINT, t, LVecBase4(px, py, pz, 1.0f),
174 RT_TANGENT, t, LVecBase4(tx, ty, tz, 0.0f),
175 RT_CV | RT_KEEP_ORIG, 0.0f, LVecBase4());
185 get_pt(PN_stdfloat t, LVecBase3 &point, LVecBase3 &tangent)
const {
187 bool result = find_curve(curve, t);
190 return result | curve->get_pt(t, point, tangent);
207 assert(ti >= 0 && ti < (
int)_segs.size());
208 return _segs[ti]._curve;
223 if (ti < 0 || ti > (
int)_segs.size()) {
227 if (ti == (
int)_segs.size()) {
228 _segs.push_back(Curveseg(seg,
get_max_t() + tlength));
231 _segs.insert(_segs.begin(),
232 Curveseg(seg, tlength));
235 _segs.insert(_segs.begin() + ti,
236 Curveseg(seg, _segs[ti-1]._tend + tlength));
249 if (ti < 0 || ti >= (
int)_segs.size()) {
254 _segs.erase(_segs.begin() + ti);
257 while (ti < (
int)_segs.size()) {
258 _segs[ti]._tend -= tlength;
271 _segs.erase(_segs.begin(), _segs.end());
280 assert(ti >= 0 && ti < (
int)_segs.size());
281 return (ti==0) ? _segs[ti]._tend : _segs[ti]._tend - _segs[ti-1]._tend;
289 assert(ti >= 0 && ti <= (
int)_segs.size());
290 return (ti==0) ? 0.0f : _segs[ti-1]._tend;
298 assert(ti >= 0 && ti < (
int)_segs.size());
299 return _segs[ti]._tend;
310 if (ti < 0 || ti >= (
int)_segs.size()) {
331 const PN_stdfloat knots[],
const LVecBase4 cvs[]) {
334 for (
int i=0; i<num_cvs - order + 1; i++) {
335 if (knots[i+order] > knots[i+order-1]) {
339 knots[i+order] - knots[i+order-1]);
353 bz_segs.erase(bz_segs.begin(), bz_segs.end());
356 for (i = 0; i < (int)_segs.size(); i++) {
357 if (!_segs[i]._curve->get_bezier_seg(seg)) {
360 seg._t = _segs[i]._tend;
361 bz_segs.push_back(seg);
375 int, PN_stdfloat,
const LVecBase4 &,
376 int, PN_stdfloat,
const LVecBase4 &,
377 int, PN_stdfloat,
const LVecBase4 &) {
378 cerr <<
"rebuild_curveseg not implemented for this curve type.\n";
389 bool PiecewiseCurve::
395 if (_last_ti>0 && _segs[_last_ti-1]._tend>=t) {
407 for (ti = _last_ti; ti < (int)_segs.size(); ti++) {
408 if (_segs[ti]._tend+0.00001f > t) {
413 if (ti < (
int)_segs.size()) {
416 t = (t - _segs[ti-1]._tend) / (_segs[ti]._tend - _segs[ti-1]._tend);
424 curve = _segs[0]._curve;
429 if (ti >= (
int)_segs.size() || !_segs[ti]._curve->is_valid()) {
430 assert(ti <= (
int)_segs.size());
436 if (ti > 0 && t < _segs[ti-1]._tend+0.0001f) {
441 if (ti >= (
int)_segs.size()) {
447 curve = _segs.back()._curve;
451 }
else if (!_segs[ti]._curve->is_valid()) {
452 curve = _segs[ti]._curve;
462 t *= _segs[ti]._curve->get_max_t();
463 curve = _segs[ti]._curve;
478 PN_stdfloat PiecewiseCurve::
479 current_seg_range(PN_stdfloat t)
const {
482 assert(ti < (
int)_segs.size());
486 t = (t - _segs[ti-1]._tend) / (_segs[ti]._tend - _segs[ti-1]._tend);
498 void PiecewiseCurve::
500 ParametricCurve::write_datagram(manager, me);
504 for (i = 0; i < _segs.size(); i++) {
505 const Curveseg &seg = _segs[i];
518 void PiecewiseCurve::
520 ParametricCurve::fillin(scan, manager);
523 _segs.reserve(num_segs);
525 for (i = 0; i < num_segs; i++) {
528 seg._curve =
nullptr;
530 _segs.push_back(seg);
543 for (i = 0; i < _segs.size(); i++) {
547 return used + _segs.size();
ParametricCurve * get_curveseg(int ti)
Returns the curve segment corresponding to the given index.
void remove_all_curvesegs()
Removes all curve segments from the curve.
void add_float64(PN_float64 value)
Adds a 64-bit floating-point number to the datagram.
PN_stdfloat get_tend(int ti) const
Returns the parametric end of the given segment of the curve.
virtual bool adjust_point(PN_stdfloat t, PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz)
Recomputes the curve such that it passes through the point (px, py, pz) at time t,...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
A virtual base class for parametric curves.
bool insert_curveseg(int ti, ParametricCurve *seg, PN_stdfloat tlength)
Inserts a new curve segment at the indicated index.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Base class for objects that can be written to and read from Bam files.
int get_num_segs() const
Returns the number of curve segments that make up the Piecewise curve.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool get_tangent(PN_stdfloat t, LVecBase3 &tangent) const
Returns the tangent of the curve at a given parametric point t.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
virtual bool adjust_tangent(PN_stdfloat t, PN_stdfloat tx, PN_stdfloat ty, PN_stdfloat tz)
Recomputes the curve such that it has the tangent (tx, ty, tz) at time t, but keeps the same position...
virtual bool get_pt(PN_stdfloat t, LVecBase3 &point, LVecBase3 &tangent) const
Simultaneously returns the point and tangent of the curve at a given parametric point t.
A CubicCurveseg is any curve that can be completely described by four 4-valued basis vectors,...
virtual PN_stdfloat get_max_t() const
Returns the upper bound of t for the entire curve.
PN_stdfloat get_tlength(int ti) const
Returns the parametric length of the given segment of the curve.
void add_uint32(uint32_t value)
Adds an unsigned 32-bit integer to the datagram.
This is our own Panda specialization on the default STL vector.
A PiecewiseCurve is a curve made up of several curve segments, connected in a head-to-tail fashion.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
uint32_t get_uint32()
Extracts an unsigned 32-bit integer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool adjust_pt(PN_stdfloat t, PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz, PN_stdfloat tx, PN_stdfloat ty, PN_stdfloat tz)
Recomputes the curve such that it passes through the point (px, py, pz) with the tangent (tx,...
bool set_tlength(int ti, PN_stdfloat tlength)
Sets the parametric length of the given segment of the curve.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PN_float64 get_float64()
Extracts a 64-bit floating-point number.
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
virtual bool get_bezier_segs(BezierSegs &bz_segs) const
Fills up the indicated vector with a list of BezierSeg structs that describe the curve.
A class to retrieve the individual data elements previously stored in a Datagram.
TypeHandle is the identifier used to differentiate C++ class types.
virtual bool get_2ndtangent(PN_stdfloat t, LVecBase3 &tangent2) const
Returns the tangent of the first derivative of the curve at the point t.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void make_nurbs(int order, int num_cvs, const PN_stdfloat knots[], const LVecBase4 cvs[])
Defines the curve as a general NURBS curve.
bool remove_curveseg(int ti)
Removes the given curve segment from the curve and frees it.
PN_stdfloat get_tstart(int ti) const
Returns the parametric start of the given segment of the curve.
virtual bool rebuild_curveseg(int rtype0, PN_stdfloat t0, const LVecBase4 &v0, int rtype1, PN_stdfloat t1, const LVecBase4 &v1, int rtype2, PN_stdfloat t2, const LVecBase4 &v2, int rtype3, PN_stdfloat t3, const LVecBase4 &v3)
Rebuilds the current curve segment (as selected by the most recent call to find_curve()) according to...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool get_point(PN_stdfloat t, LVecBase3 &point) const
Returns the point of the curve at a given parametric point t.
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
virtual bool is_valid() const
Returns true if the curve is defined.