Panda3D
piecewiseCurve.h
1 // Filename: piecewiseCurve.h
2 // Created by: drose (04Mar01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PIECEWISECURVE_H
16 #define PIECEWISECURVE_H
17 
18 #include "pandabase.h"
19 
20 #include "parametricCurve.h"
21 #include "pointerTo.h"
22 
23 ////////////////////////////////////////////////////////////////////
24 // Class : PiecewiseCurve
25 // Description : A PiecewiseCurve is a curve made up of several curve
26 // segments, connected in a head-to-tail fashion. The
27 // length of each curve segment in parametric space is
28 // definable.
29 ////////////////////////////////////////////////////////////////////
30 class EXPCL_PANDA_PARAMETRICS PiecewiseCurve : public ParametricCurve {
31 PUBLISHED:
33  ~PiecewiseCurve();
34 
35 public:
36  // These functions are all inherited from ParametricCurve, and need
37  // not be re-published.
38  virtual bool is_valid() const;
39  virtual PN_stdfloat get_max_t() const;
40 
41  virtual bool get_point(PN_stdfloat t, LVecBase3 &point) const;
42  virtual bool get_tangent(PN_stdfloat t, LVecBase3 &tangent) const;
43  virtual bool get_pt(PN_stdfloat t, LVecBase3 &point, LVecBase3 &tangent) const;
44  virtual bool get_2ndtangent(PN_stdfloat t, LVecBase3 &tangent2) const;
45 
46  virtual bool adjust_point(PN_stdfloat t, PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz);
47  virtual bool adjust_tangent(PN_stdfloat t, PN_stdfloat tx, PN_stdfloat ty, PN_stdfloat tz);
48  virtual bool adjust_pt(PN_stdfloat t,
49  PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz,
50  PN_stdfloat tx, PN_stdfloat ty, PN_stdfloat tz);
51 
52 public:
53  int get_num_segs() const;
54 
55  ParametricCurve *get_curveseg(int ti);
56  bool insert_curveseg(int ti, ParametricCurve *seg, PN_stdfloat tlength);
57 
58  bool remove_curveseg(int ti);
59  void remove_all_curvesegs();
60 
61  PN_stdfloat get_tlength(int ti) const;
62  PN_stdfloat get_tstart(int ti) const;
63  PN_stdfloat get_tend(int ti) const;
64  bool set_tlength(int ti, PN_stdfloat tlength);
65 
66  void make_nurbs(int order, int num_cvs,
67  const PN_stdfloat knots[], const LVecBase4 cvs[]);
68 
69  virtual bool get_bezier_segs(BezierSegs &bz_segs) const;
70 
71  virtual bool
72  rebuild_curveseg(int rtype0, PN_stdfloat t0, const LVecBase4 &v0,
73  int rtype1, PN_stdfloat t1, const LVecBase4 &v1,
74  int rtype2, PN_stdfloat t2, const LVecBase4 &v2,
75  int rtype3, PN_stdfloat t3, const LVecBase4 &v3);
76 
77 protected:
78  bool find_curve(const ParametricCurve *&curve, PN_stdfloat &t) const;
79  PN_stdfloat current_seg_range(PN_stdfloat t) const;
80 
81  class Curveseg {
82  public:
83  Curveseg() {}
84  Curveseg(ParametricCurve *c, PN_stdfloat t) : _curve(c), _tend(t) {}
85 
86  PT(ParametricCurve) _curve;
87  PN_stdfloat _tend;
88  };
89 
90  pvector<Curveseg> _segs;
91  int _last_ti;
92 
93 
94 // TypedWritable stuff
95 protected:
96  virtual void write_datagram(BamWriter *manager, Datagram &me);
97  void fillin(DatagramIterator &scan, BamReader *manager);
98  virtual int complete_pointers(TypedWritable **plist,
99  BamReader *manager);
100 
101 public:
102  static TypeHandle get_class_type() {
103  return _type_handle;
104  }
105  static void init_type() {
106  ParametricCurve::init_type();
107  register_type(_type_handle, "PiecewiseCurve",
108  ParametricCurve::get_class_type());
109  }
110  virtual TypeHandle get_type() const {
111  return get_class_type();
112  }
113  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
114 
115 private:
116  static TypeHandle _type_handle;
117 };
118 
119 
120 #endif
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
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, but keeps the same tangent value at that point.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
A virtual base class for parametric curves.
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is our own Panda specialization on the default STL list.
Definition: plist.h:38
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
virtual bool is_valid() const
Returns true if the curve is defined.
A PiecewiseCurve is a curve made up of several curve segments, connected in a head-to-tail fashion...
virtual PN_stdfloat get_max_t() const
Returns the upper bound of t for the entire curve.
virtual bool get_bezier_segs(BezierSegs &) const
Fills up the indicated vector with a list of BezierSeg structs that describe the curve.
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...
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...
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43