32static const LVecBase3 zerovec_3 = LVecBase3(0.0f, 0.0f, 0.0f);
42show_vec3(ostream &out,
int indent_level,
const LVecBase3 &v,
44 indent(out, indent_level) << v[0];
45 for (
int i = 1; i<num_dimensions; i++) {
64 _p(c._p), _in(c._in), _out(c._out),
65 _type(c._type), _name(c._name)
83set_in(
const LVecBase3 &in) {
166format_egg(ostream &out,
int indent_level,
int num_dimensions,
167 bool show_in,
bool show_out,
168 PN_stdfloat scale_in, PN_stdfloat scale_out)
const {
170 indent(out, indent_level) <<
"<Vertex> {\n";
171 show_vec3(out, indent_level + 2, _p - scale_in * _in / 3.0,
172 num_dimensions) <<
"\n";
173 indent(out, indent_level) <<
"}\n";
176 indent(out, indent_level) <<
"<Vertex> {\n";
177 show_vec3(out, indent_level + 2, _p, num_dimensions) <<
"\n";
179 indent(out, indent_level+2) <<
"<Scalar> continuity-type { ";
199 indent(out, indent_level) <<
"}\n";
202 indent(out, indent_level) <<
"<Vertex> {\n";
203 show_vec3(out, indent_level + 2, _p + scale_out * _out / 3.0,
204 num_dimensions) <<
"\n";
205 indent(out, indent_level) <<
"}\n";
215 _p.write_datagram(me);
216 _in.write_datagram(me);
217 _out.write_datagram(me);
229 _p.read_datagram(scan);
230 _in.read_datagram(scan);
231 _out.read_datagram(scan);
250 parametrics_cat->warning()
251 <<
"Cannot make a Hermite from the indicated curve."
274 return _points.size();
292 int n =
append_cv(HC_SMOOTH, 0.0f, 0.0f, 0.0f);
297 t = std::min(std::max(t, (PN_stdfloat)0.0),
get_max_t());
304 cv._type = HC_SMOOTH;
306 cv._out = cv._in = tan * 0.5f;
308 _points.insert(_points.begin() + n + 1, cv);
325append_cv(
int type, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
328 cv.set_point(LVecBase3(x, y, z));
331 _points.push_back(cv);
332 if (_points.size()>1) {
341 return _points.size()-1;
351 if (n < 0 || n >= (
int)_points.size()) {
355 _points.erase(_points.begin() + n);
356 if (_segs.size()>0) {
371 _points.erase(_points.begin(), _points.end());
394 if (n < 0 || n >= (
int)_points.size()) {
398 bool changed_cut =
false;
400 if (type!=_points[n]._type) {
401 changed_cut = (type==HC_CUT || _points[n]._type==HC_CUT);
402 _points[n].set_type(type);
405 invalidate_cv(n, changed_cut);
414set_cv_point(
int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
415 if (n < 0 || n >= (
int)_points.size()) {
418 _points[n].set_point(LVecBase3(x, y, z));
419 invalidate_cv(n,
false);
428set_cv_in(
int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
429 if (n < 0 || n >= (
int)_points.size()) {
432 _points[n].set_in(LVecBase3(x, y, z));
433 invalidate_cv(n,
false);
442set_cv_out(
int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
443 if (n < 0 || n >= (
int)_points.size()) {
446 _points[n].set_out(LVecBase3(x, y, z));
447 invalidate_cv(n,
false);
457 if (n <= 0 || n >= (
int)_points.size()) {
474 if (n < 0 || n >= (
int)_points.size()) {
477 _points[n].set_name(name);
489 if (n < 0 || n >= (
int)_points.size()) {
493 return _points[n]._type;
502 if (n < 0 || n >= (
int)_points.size()) {
506 return _points[n]._p;
519 if (n < 0 || n >= (
int)_points.size() || _points[n-1]._type==HC_CUT) {
523 return _points[n]._in;
536 if (n < 0 || n >= (
int)_points.size() || _points[n]._type==HC_CUT) {
540 return _points[n]._out;
555 }
else if (n >= (
int)_points.size()) {
567 if (n < 0 || n >= (
int)_points.size()) {
571 return _points[n]._name;
579output(ostream &out)
const {
607write_cv(ostream &out,
int n)
const {
616 <<
"\ncontinuity type = ";
651 int, PN_stdfloat,
const LVecBase4 &,
652 int, PN_stdfloat,
const LVecBase4 &,
653 int, PN_stdfloat,
const LVecBase4 &) {
654 std::cerr <<
"rebuild_curveseg not implemented for this curve type.\n";
662format_egg(ostream &out,
const string &name,
const string &curve_type,
663 int indent_level)
const {
665 <<
"<VertexPool> " << name <<
".pool {\n";
668 for (i = 0; i < (int)_points.size(); i++) {
669 bool show_in = (i != 0);
670 bool show_out = (i != (int)_points.size()-1);
671 _points[i].format_egg(out, indent_level + 2, _num_dimensions,
676 indent(out, indent_level) <<
"}\n";
678 indent(out, indent_level) <<
"<BezierCurve> " << name <<
" {\n";
680 if (!curve_type.empty()) {
681 indent(out, indent_level+2)
682 <<
"<Scalar> type { " << curve_type <<
" }\n";
685 indent(out, indent_level+2) <<
"<TLengths> {";
686 if (_points.size() > 1) {
687 for (i = 0; i < (int)_segs.size(); i++) {
690 indent(out, indent_level+3);
696 indent(out, indent_level+2) <<
"}\n";
698 indent(out, indent_level+2) <<
"<VertexRef> {";
699 for (i = 1; i <= (int)_points.size() * 3 - 2; i++) {
702 indent(out, indent_level+3);
707 indent(out, indent_level+4) <<
"<Ref> { " << name <<
".pool }\n";
708 indent(out, indent_level+2) <<
"}\n";
710 indent(out, indent_level) <<
"}\n";
717wrap_hpr(
const LVecBase3 &hpr1, LVecBase3 &hpr2) {
718 for (
int i = 0; i < 3; i++) {
719 while ((hpr2[i] - hpr1[i]) > 180.0) {
723 while ((hpr2[i] - hpr1[i]) < -180.0) {
733invalidate_cv(
int n,
bool redo_all) {
735 if (n>0 && _points[n-1]._type!=HC_CUT) {
738 if (_curve_type == PCT_HPR) {
739 wrap_hpr(p1._p, p2._p);
745 if (n+1 < (
int)_points.size()) {
746 if (_points[n]._type==HC_CUT) {
748 seg._v[0] = seg._v[1] = seg._v[2] = seg._v[3] = _points[n]._p;
753 if (_curve_type == PCT_HPR) {
754 wrap_hpr(p1._p, p2._p);
776find_cv(PN_stdfloat t) {
780 for (n = 0; n < (int)_segs.size(); n++) {
781 if (_segs[n]._tend+0.00001 > t) {
798 for (n = 0; n < (int)_segs.size(); n++) {
799 if (_points[n]._type==HC_CUT) {
801 seg._v[0] = seg._v[1] = seg._v[2] = seg._v[3] = _points[n]._p;
806 if (_curve_type == PCT_HPR) {
807 wrap_hpr(p1._p, p2._p);
833 me->fillin(scan, manager);
843 PiecewiseCurve::write_datagram(manager, me);
847 for (i = 0; i < _points.size(); i++) {
848 _points[i].write_datagram(manager, me);
859 PiecewiseCurve::fillin(scan, manager);
862 _points.reserve(num_points);
864 for (i = 0; i < num_points; i++) {
867 _points.push_back(cv);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
A CubicCurveseg is any curve that can be completely described by four 4-valued basis vectors,...
void bezier_basis(const BezierSeg &seg)
Defines the curve segment as a Bezier.
void hermite_basis(const HermiteCurveCV &cv0, const HermiteCurveCV &cv1, PN_stdfloat tlength=1.0f)
Defines the curve segment as a Hermite.
A class to retrieve the individual data elements previously stored in a Datagram.
uint32_t get_uint32()
Extracts an unsigned 32-bit integer.
int8_t get_int8()
Extracts a signed 8-bit integer.
std::string get_string()
Extracts a variable-length string.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void add_uint32(uint32_t value)
Adds an unsigned 32-bit integer to the datagram.
void add_string(const std::string &str)
Adds a variable-length string to the datagram.
void add_int8(int8_t value)
Adds a signed 8-bit integer to the datagram.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
A single CV of a Hermite curve.
void write_datagram(BamWriter *manager, Datagram &me) const
Function to write the important information in the particular object to a Datagram.
void set_in(const LVecBase3 &in)
Sets the CV's in tangent.
void set_type(int type)
Sets the continuity type of the CV.
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.
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...
void set_out(const LVecBase3 &out)
Sets the CV's out tangent.
void set_name(const std::string &name)
Sets the name associated with the CV.
A parametric curve defined by a sequence of control vertices, each with an in and out tangent.
int append_cv(int type, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Adds a new CV to the end of the curve.
PN_stdfloat get_cv_tstart(int n) const
Returns the starting point in parametric space of the given CV.
bool set_cv_out(int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Changes the given CV's out tangent.
bool set_cv_tstart(int n, PN_stdfloat tstart)
Changes the given CV's parametric starting time.
const LVecBase3 & get_cv_point(int n) const
Returns the position of the given CV.
bool set_cv_name(int n, const char *name)
Changes the name associated with a particular CV.
int insert_cv(PN_stdfloat t)
Inserts a new CV at the given parametric point along the curve.
const LVecBase3 & get_cv_out(int n) const
Returns the out tangent of the given CV.
bool set_cv_point(int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Changes the given CV's position.
int get_num_cvs() const
Returns the number of CV's in the curve.
std::string get_cv_name(int n) const
Returns the name of the given CV, or NULL.
bool set_cv_in(int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Changes the given CV's in tangent.
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...
void remove_all_cvs()
Removes all CV's from the curve.
bool remove_cv(int n)
Removes the given CV from the curve.
static void register_with_read_factory()
Initializes the factory for reading these things from Bam files.
bool set_cv_type(int n, int type)
Changes the given CV's continuity type.
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...
const LVecBase3 & get_cv_in(int n) const
Returns the in tangent of the given CV.
void output(std::ostream &out) const
Outputs the Namable.
A virtual base class for parametric curves.
int get_curve_type() const
Returns the flag indicating the use to which the curve is intended to be put.
virtual bool convert_to_hermite(HermiteCurve *hc) const
Stores an equivalent curve representation in the indicated Hermite curve, if possible.
void remove_all_curvesegs()
Removes all curve segments from the curve.
bool insert_curveseg(int ti, ParametricCurve *seg, PN_stdfloat tlength)
Inserts a new curve segment at the indicated index.
virtual bool is_valid() const
Returns true if the curve is defined.
PN_stdfloat get_tlength(int ti) const
Returns the parametric length of the given segment of the curve.
bool set_tlength(int ti, PN_stdfloat tlength)
Sets the parametric length of the given segment of the curve.
virtual PN_stdfloat get_max_t() const
Returns the upper bound of t for the entire 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 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.
TypeHandle is the identifier used to differentiate C++ class types.
Base class for objects that can be written to and read from Bam files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.