Panda3D

Loading...
Searching...
No Matches
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
21BEGIN_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.
44END_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:
52 HermiteCurveCV();
53 HermiteCurveCV(const HermiteCurveCV &c);
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 {
84PUBLISHED:
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) {
133 return (CubicCurveseg *)PiecewiseCurve::get_curveseg(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
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
CubicCurveseg
A CubicCurveseg is any curve that can be completely described by four 4-valued basis vectors,...
Definition cubicCurveseg.h:50
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition datagramIterator.h:30
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition factoryParams.h:36
HermiteCurveCV::write_datagram
void write_datagram(BamWriter *manager, Datagram &me) const
Function to write the important information in the particular object to a Datagram.
Definition hermiteCurve.cxx:214
HermiteCurveCV::set_in
void set_in(const LVecBase3 &in)
Sets the CV's in tangent.
Definition hermiteCurve.cxx:83
HermiteCurveCV::set_type
void set_type(int type)
Sets the continuity type of the CV.
Definition hermiteCurve.cxx:136
HermiteCurveCV::format_egg
void format_egg(std::ostream &out, int indent, int num_dimensions, bool show_in, bool show_out, PN_stdfloat scale_in, PN_stdfloat scale_out) const
Formats the CV for output to an egg file.
Definition hermiteCurve.cxx:166
HermiteCurveCV::fillin
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 r...
Definition hermiteCurve.cxx:228
HermiteCurveCV::set_out
void set_out(const LVecBase3 &out)
Sets the CV's out tangent.
Definition hermiteCurve.cxx:107
HermiteCurveCV::set_name
void set_name(const std::string &name)
Sets the name associated with the CV.
Definition hermiteCurve.cxx:157
HermiteCurve::append_cv
int append_cv(int type, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Adds a new CV to the end of the curve.
Definition hermiteCurve.cxx:325
HermiteCurve::get_cv_tstart
PN_stdfloat get_cv_tstart(int n) const
Returns the starting point in parametric space of the given CV.
Definition hermiteCurve.cxx:552
HermiteCurve::set_cv_out
bool set_cv_out(int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Changes the given CV's out tangent.
Definition hermiteCurve.cxx:442
HermiteCurve::set_cv_tstart
bool set_cv_tstart(int n, PN_stdfloat tstart)
Changes the given CV's parametric starting time.
Definition hermiteCurve.cxx:456
HermiteCurve::get_cv_point
const LVecBase3 & get_cv_point(int n) const
Returns the position of the given CV.
Definition hermiteCurve.cxx:501
HermiteCurve::set_cv_name
bool set_cv_name(int n, const char *name)
Changes the name associated with a particular CV.
Definition hermiteCurve.cxx:473
HermiteCurve::insert_cv
int insert_cv(PN_stdfloat t)
Inserts a new CV at the given parametric point along the curve.
Definition hermiteCurve.cxx:290
HermiteCurve::get_cv_out
const LVecBase3 & get_cv_out(int n) const
Returns the out tangent of the given CV.
Definition hermiteCurve.cxx:535
HermiteCurve::set_cv_point
bool set_cv_point(int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Changes the given CV's position.
Definition hermiteCurve.cxx:414
HermiteCurve::get_num_cvs
int get_num_cvs() const
Returns the number of CV's in the curve.
Definition hermiteCurve.cxx:273
HermiteCurve::get_cv_name
std::string get_cv_name(int n) const
Returns the name of the given CV, or NULL.
Definition hermiteCurve.cxx:566
HermiteCurve::set_cv_in
bool set_cv_in(int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Changes the given CV's in tangent.
Definition hermiteCurve.cxx:428
HermiteCurve::get_cv_type
int get_cv_type(int n) const
Returns the given CV's continuity type, HC_CUT, HC_FREE, HC_G1, or HC_SMOOTH, or 0 if there is no suc...
Definition hermiteCurve.cxx:488
HermiteCurve::remove_all_cvs
void remove_all_cvs()
Removes all CV's from the curve.
Definition hermiteCurve.cxx:370
HermiteCurve::remove_cv
bool remove_cv(int n)
Removes the given CV from the curve.
Definition hermiteCurve.cxx:350
HermiteCurve::register_with_read_factory
static void register_with_read_factory()
Initializes the factory for reading these things from Bam files.
Definition hermiteCurve.cxx:819
HermiteCurve::set_cv_type
bool set_cv_type(int n, int type)
Changes the given CV's continuity type.
Definition hermiteCurve.cxx:393
HermiteCurve::rebuild_curveseg
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...
Definition hermiteCurve.cxx:650
HermiteCurve::get_cv_in
const LVecBase3 & get_cv_in(int n) const
Returns the in tangent of the given CV.
Definition hermiteCurve.cxx:518
ParametricCurve::ParametricCurve
ParametricCurve()
This is a virtual base class.
Definition parametricCurve.cxx:34
PiecewiseCurve::get_curveseg
ParametricCurve * get_curveseg(int ti)
Returns the curve segment corresponding to the given index.
Definition piecewiseCurve.cxx:206
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition typedWritable.h:35
cubicCurveseg.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
indent
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
piecewiseCurve.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
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