Panda3D
hermiteCurve.h
1 // Filename: hermiteCurve.h
2 // Created by: drose (27Feb98)
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 HERMITECURVE_H
16 #define HERMITECURVE_H
17 
18 #include "piecewiseCurve.h"
19 #include "cubicCurveseg.h"
20 
21 
22 BEGIN_PUBLISH //[
23 // Hermite curve continuity types.
24 #define HC_CUT 1
25 // The curve is disconnected at this point. All points between
26 // this and the following CV are not part of the curve.
27 
28 #define HC_FREE 2
29 // Tangents are unconstrained. The curve is continuous, but its first
30 // derivative is not. This is G0 geometric continuity.
31 
32 #define HC_G1 3
33 // Tangents are constrained to be collinear. The curve's derivative
34 // is not continuous in parametric space, but its geometric slope is.
35 // The distinction is mainly relevant in the context of animation
36 // along the curve--when crossing the join point, direction of motion
37 // will change continuously, but the speed of motion may change
38 // suddenly. This is G1 geometric continuity.
39 
40 #define HC_SMOOTH 4
41 // Tangents are constrained to be identical. The curve and its first
42 // derivative are continuous in parametric space. When animating
43 // motion across the join point, speed and direction of motion will
44 // change continuously. This is C1 parametric continuity.
45 END_PUBLISH //]
46 
47 ////////////////////////////////////////////////////////////////////
48 // Class : HermiteCurveCV
49 // Description : A single CV of a Hermite curve. Hermite curve CV's
50 // include an in and out tangent, as well as a position.
51 ////////////////////////////////////////////////////////////////////
52 class EXPCL_PANDA_PARAMETRICS HermiteCurveCV {
53 public:
56  ~HermiteCurveCV();
57 
58  void set_point(const LVecBase3 &point) { _p = point; }
59  void set_in(const LVecBase3 &in);
60  void set_out(const LVecBase3 &out);
61  void set_type(int type);
62  void set_name(const string &name);
63 
64  void format_egg(ostream &out, int indent, int num_dimensions,
65  bool show_in, bool show_out,
66  PN_stdfloat scale_in, PN_stdfloat scale_out) const;
67 
68  void write_datagram(BamWriter *manager, Datagram &me) const;
69  void fillin(DatagramIterator &scan, BamReader *manager);
70 
71  LVecBase3 _p, _in, _out;
72  int _type;
73  string _name;
74 };
75 
76 ////////////////////////////////////////////////////////////////////
77 // Class : HermiteCurve
78 // Description : A parametric curve defined by a sequence of control
79 // vertices, each with an in and out tangent.
80 //
81 // This class is actually implemented as a
82 // PiecewiseCurve made up of several CubicCurvesegs,
83 // each of which is created using the hermite_basis()
84 // method. The HermiteCurve class itself keeps its own
85 // list of the CV's that are used to define the curve
86 // (since the CubicCurveseg class doesn't retain these).
87 ////////////////////////////////////////////////////////////////////
88 class EXPCL_PANDA_PARAMETRICS HermiteCurve : public PiecewiseCurve {
89 PUBLISHED:
90  HermiteCurve();
91  HermiteCurve(const ParametricCurve &pc);
92  virtual ~HermiteCurve();
93 
94  int get_num_cvs() const;
95 
96  int insert_cv(PN_stdfloat t);
97  int append_cv(int type, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
98  inline int append_cv(int type, const LVecBase3 &v) {
99  return append_cv(type, v[0], v[1], v[2]);
100  }
101 
102  bool remove_cv(int n);
103  void remove_all_cvs();
104 
105  bool set_cv_type(int n, int type);
106  bool set_cv_point(int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
107  inline bool set_cv_point(int n, const LVecBase3 &v) {
108  return set_cv_point(n, v[0], v[1], v[2]);
109  }
110  bool set_cv_in(int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
111  inline bool set_cv_in(int n, const LVecBase3 &v) {
112  return set_cv_in(n, v[0], v[1], v[2]);
113  }
114  bool set_cv_out(int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
115  inline bool set_cv_out(int n, const LVecBase3 &v) {
116  return set_cv_out(n, v[0], v[1], v[2]);
117  }
118  bool set_cv_tstart(int n, PN_stdfloat tstart);
119  bool set_cv_name(int n, const char *name);
120 
121 
122  int get_cv_type(int n) const;
123  const LVecBase3 &get_cv_point(int n) const;
124  void get_cv_point(int n, LVecBase3 &v) const;
125  const LVecBase3 &get_cv_in(int n) const;
126  void get_cv_in(int n, LVecBase3 &v) const;
127  const LVecBase3 &get_cv_out(int n) const;
128  void get_cv_out(int n, LVecBase3 &v) const;
129  PN_stdfloat get_cv_tstart(int n) const;
130  string get_cv_name(int n) const;
131 
132  virtual void output(ostream &out) const;
133  void write_cv(ostream &out, int n) const;
134 
135 public:
136 
137  CubicCurveseg *get_curveseg(int ti) {
139  }
140 
141  virtual bool
142  rebuild_curveseg(int rtype0, PN_stdfloat t0, const LVecBase4 &v0,
143  int rtype1, PN_stdfloat t1, const LVecBase4 &v1,
144  int rtype2, PN_stdfloat t2, const LVecBase4 &v2,
145  int rtype3, PN_stdfloat t3, const LVecBase4 &v3);
146 
147 protected:
148  virtual bool format_egg(ostream &out, const string &name,
149  const string &curve_type, int indent_level) const;
150 
151  void invalidate_cv(int n, bool redo_all);
152  int find_cv(PN_stdfloat t);
153  void recompute_basis();
154 
155  pvector<HermiteCurveCV> _points;
156 
157 // TypedWritable stuff
158 public:
159  static void register_with_read_factory();
160 
161 protected:
162  static TypedWritable *make_HermiteCurve(const FactoryParams &params);
163  virtual void write_datagram(BamWriter *manager, Datagram &me);
164  void fillin(DatagramIterator &scan, BamReader *manager);
165 
166 public:
167  static TypeHandle get_class_type() {
168  return _type_handle;
169  }
170  static void init_type() {
171  register_type(_type_handle, "HermiteCurve");
172  }
173  virtual TypeHandle get_type() const {
174  return get_class_type();
175  }
176  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
177 
178 private:
179  static TypeHandle _type_handle;
180 };
181 
182 #endif
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
ParametricCurve * get_curveseg(int ti)
Returns the curve segment corresponding to the given index.
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
static void register_with_read_factory()
Tells the BamReader how to create objects of type PandaNode.
Definition: pandaNode.cxx:4153
A parametric curve defined by a sequence of control vertices, each with an in and out tangent...
Definition: hermiteCurve.h:88
A CubicCurveseg is any curve that can be completely described by four 4-valued basis vectors...
Definition: cubicCurveseg.h:58
A PiecewiseCurve is a curve made up of several curve segments, connected in a head-to-tail fashion...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
A single CV of a Hermite curve.
Definition: hermiteCurve.h:52
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
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...