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