mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
*** empty log message ***
This commit is contained in:
parent
d20f9783cf
commit
8d939150d7
@ -301,7 +301,7 @@ NUMERIC ([+-]?(([0-9]+[.]?)|([0-9]*[.][0-9]+))([eE][+-]?[0-9]+)?)
|
|||||||
yyless(1);
|
yyless(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[ \t] {
|
[ \t\r] {
|
||||||
// Eat whitespace.
|
// Eat whitespace.
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
@ -689,7 +689,7 @@ NUMERIC ([+-]?(([0-9]+[.]?)|([0-9]*[.][0-9]+))([eE][+-]?[0-9]+)?)
|
|||||||
return STRING;
|
return STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
[^ \t\n{}"]+ {
|
[^ \t\n\r{}"]+ {
|
||||||
// Unquoted string.
|
// Unquoted string.
|
||||||
accept();
|
accept();
|
||||||
eggyylval._string = yytext;
|
eggyylval._string = yytext;
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
putil
|
putil
|
||||||
|
|
||||||
#define SOURCES \
|
#define SOURCES \
|
||||||
compose_matrix.I compose_matrix.cxx compose_matrix.h \
|
cmath.I cmath.h compose_matrix.I compose_matrix.cxx compose_matrix.h \
|
||||||
config_linmath.cxx config_linmath.h coordinateSystem.cxx \
|
config_linmath.cxx config_linmath.h coordinateSystem.cxx \
|
||||||
coordinateSystem.h deg_2_rad.h \
|
coordinateSystem.h deg_2_rad.h \
|
||||||
ioPtaDatagramLinMath.I ioPtaDatagramLinMath.cxx \
|
ioPtaDatagramLinMath.I ioPtaDatagramLinMath.cxx \
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#ifndef CMATH_H
|
#ifndef CMATH_H
|
||||||
#define CMATH_H
|
#define CMATH_H
|
||||||
|
|
||||||
|
#include <pandabase.h>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
// This file declares a number of C++-style overloading wrappers
|
// This file declares a number of C++-style overloading wrappers
|
||||||
|
@ -25,6 +25,10 @@ ConfigureFn(config_parametrics) {
|
|||||||
HermiteCurve::init_type();
|
HermiteCurve::init_type();
|
||||||
NurbsCurve::init_type();
|
NurbsCurve::init_type();
|
||||||
NurbsCurveDrawer::init_type();
|
NurbsCurveDrawer::init_type();
|
||||||
|
|
||||||
|
CubicCurveseg::register_with_read_factory();
|
||||||
|
HermiteCurve::register_with_read_factory();
|
||||||
|
NurbsCurve::register_with_read_factory();
|
||||||
}
|
}
|
||||||
|
|
||||||
const DSearchPath &
|
const DSearchPath &
|
||||||
|
@ -22,6 +22,10 @@
|
|||||||
#include "nurbsCurve.h"
|
#include "nurbsCurve.h"
|
||||||
#include "curveDrawer.h"
|
#include "curveDrawer.h"
|
||||||
|
|
||||||
|
#include <datagram.h>
|
||||||
|
#include <datagramIterator.h>
|
||||||
|
#include <bamWriter.h>
|
||||||
|
#include <bamReader.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Statics
|
// Statics
|
||||||
@ -595,13 +599,32 @@ r_calc_length(double t1, double t2, const LPoint3f &p1, const LPoint3f &p2,
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: ParametricCurve::write_datagram
|
// Function: ParametricCurve::write_datagram
|
||||||
// Access: Public
|
// Access: Protected, Virtual
|
||||||
// Description: Function to write the important information in
|
// Description: Function to write the important information in
|
||||||
// the particular object to a Datagram
|
// the particular object to a Datagram
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void ParametricCurve::
|
void ParametricCurve::
|
||||||
write_datagram(BamWriter *, Datagram &) {
|
write_datagram(BamWriter *manager, Datagram &me) {
|
||||||
// TODO: write the write_datagram.
|
NamedNode::write_datagram(manager, me);
|
||||||
|
|
||||||
|
me.add_int8(_curve_type);
|
||||||
|
me.add_int8(_num_dimensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: ParametricCurve::fillin
|
||||||
|
// Access: Protected
|
||||||
|
// Description: Function that reads out of the datagram (or asks
|
||||||
|
// manager to read) all of the data that is needed to
|
||||||
|
// re-create this object and stores it in the appropiate
|
||||||
|
// place
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void ParametricCurve::
|
||||||
|
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||||
|
NamedNode::fillin(scan, manager);
|
||||||
|
|
||||||
|
_curve_type = scan.get_int8();
|
||||||
|
_num_dimensions = scan.get_int8();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1150,6 +1173,72 @@ current_seg_range(double t) const {
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PiecewiseCurve::write_datagram
|
||||||
|
// Access: Protected, Virtual
|
||||||
|
// Description: Function to write the important information in
|
||||||
|
// the particular object to a Datagram
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void PiecewiseCurve::
|
||||||
|
write_datagram(BamWriter *manager, Datagram &me) {
|
||||||
|
ParametricCurve::write_datagram(manager, me);
|
||||||
|
|
||||||
|
me.add_uint32(_segs.size());
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < _segs.size(); i++) {
|
||||||
|
const Curveseg &seg = _segs[i];
|
||||||
|
manager->write_pointer(me, seg._curve);
|
||||||
|
me.add_float64(seg._tend);
|
||||||
|
}
|
||||||
|
|
||||||
|
_last_ti = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PiecewiseCurve::fillin
|
||||||
|
// Access: Protected
|
||||||
|
// Description: Function that reads out of the datagram (or asks
|
||||||
|
// manager to read) all of the data that is needed to
|
||||||
|
// re-create this object and stores it in the appropiate
|
||||||
|
// place
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void PiecewiseCurve::
|
||||||
|
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||||
|
ParametricCurve::fillin(scan, manager);
|
||||||
|
|
||||||
|
size_t num_segs = scan.get_uint32();
|
||||||
|
_segs.reserve(num_segs);
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < num_segs; i++) {
|
||||||
|
Curveseg seg;
|
||||||
|
manager->read_pointer(scan, this);
|
||||||
|
seg._curve = (ParametricCurve *)NULL;
|
||||||
|
seg._tend = scan.get_float64();
|
||||||
|
_segs.push_back(seg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PiecewiseCurve::complete_pointers
|
||||||
|
// Access: Protected, Virtual
|
||||||
|
// Description: Takes in a vector of pointes to TypedWriteable
|
||||||
|
// objects that correspond to all the requests for
|
||||||
|
// pointers that this object made to BamReader.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
int PiecewiseCurve::
|
||||||
|
complete_pointers(vector_typedWriteable &plist, BamReader *manager) {
|
||||||
|
int used = ParametricCurve::complete_pointers(plist, manager);
|
||||||
|
|
||||||
|
nassertr(used + _segs.size() <= plist.size(), used);
|
||||||
|
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < _segs.size(); i++) {
|
||||||
|
DCAST_INTO_R(_segs[i]._curve, plist[used + i], used);
|
||||||
|
}
|
||||||
|
|
||||||
|
return used + _segs.size();
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: CubicCurveseg::Constructor
|
// Function: CubicCurveseg::Constructor
|
||||||
// Access: Public
|
// Access: Public
|
||||||
@ -1678,3 +1767,68 @@ compute_seg(int rtype0, double t0, const LVecBase4f &v0,
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: CubicCurveseg::register_with_factory
|
||||||
|
// Access: Public, Static
|
||||||
|
// Description: Initializes the factory for reading these things from
|
||||||
|
// Bam files.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void CubicCurveseg::
|
||||||
|
register_with_read_factory() {
|
||||||
|
BamReader::get_factory()->register_factory(get_class_type(), make_CubicCurveseg);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: CubicCurveseg::make_CubicCurveseg
|
||||||
|
// Access: Protected
|
||||||
|
// Description: Factory method to generate an object of this type.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
TypedWriteable *CubicCurveseg::
|
||||||
|
make_CubicCurveseg(const FactoryParams ¶ms) {
|
||||||
|
CubicCurveseg *me = new CubicCurveseg;
|
||||||
|
BamReader *manager;
|
||||||
|
Datagram packet;
|
||||||
|
|
||||||
|
parse_params(params, manager, packet);
|
||||||
|
DatagramIterator scan(packet);
|
||||||
|
|
||||||
|
me->fillin(scan, manager);
|
||||||
|
return me;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: CubicCurveseg::write_datagram
|
||||||
|
// Access: Protected, Virtual
|
||||||
|
// Description: Function to write the important information in
|
||||||
|
// the particular object to a Datagram
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void CubicCurveseg::
|
||||||
|
write_datagram(BamWriter *manager, Datagram &me) {
|
||||||
|
ParametricCurve::write_datagram(manager, me);
|
||||||
|
|
||||||
|
Bx.write_datagram(me);
|
||||||
|
By.write_datagram(me);
|
||||||
|
Bz.write_datagram(me);
|
||||||
|
Bw.write_datagram(me);
|
||||||
|
me.add_bool(rational);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: CubicCurveseg::fillin
|
||||||
|
// Access: Protected
|
||||||
|
// Description: Function that reads out of the datagram (or asks
|
||||||
|
// manager to read) all of the data that is needed to
|
||||||
|
// re-create this object and stores it in the appropiate
|
||||||
|
// place
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void CubicCurveseg::
|
||||||
|
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||||
|
ParametricCurve::fillin(scan, manager);
|
||||||
|
|
||||||
|
Bx.read_datagram(scan);
|
||||||
|
By.read_datagram(scan);
|
||||||
|
Bz.read_datagram(scan);
|
||||||
|
Bw.read_datagram(scan);
|
||||||
|
rational = scan.get_bool();
|
||||||
|
}
|
||||||
|
@ -119,8 +119,6 @@ public:
|
|||||||
};
|
};
|
||||||
typedef vector<BezierSeg> BezierSegs;
|
typedef vector<BezierSeg> BezierSegs;
|
||||||
|
|
||||||
virtual void write_datagram(BamWriter *, Datagram &);
|
|
||||||
|
|
||||||
virtual bool GetBezierSegs(BezierSegs &) const {
|
virtual bool GetBezierSegs(BezierSegs &) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -145,6 +143,10 @@ protected:
|
|||||||
int _curve_type;
|
int _curve_type;
|
||||||
int _num_dimensions;
|
int _num_dimensions;
|
||||||
|
|
||||||
|
// TypedWriteable stuff
|
||||||
|
protected:
|
||||||
|
virtual void write_datagram(BamWriter *manager, Datagram &me);
|
||||||
|
void fillin(DatagramIterator &scan, BamReader *manager);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static TypeHandle get_class_type() {
|
static TypeHandle get_class_type() {
|
||||||
@ -227,10 +229,6 @@ protected:
|
|||||||
Curveseg() {}
|
Curveseg() {}
|
||||||
Curveseg(ParametricCurve *c, double t) : _curve(c), _tend(t) {}
|
Curveseg(ParametricCurve *c, double t) : _curve(c), _tend(t) {}
|
||||||
|
|
||||||
int descend_pfb(void *handle);
|
|
||||||
int store_pfb(void *handle);
|
|
||||||
int load_pfb(void *handle);
|
|
||||||
|
|
||||||
ParametricCurve *_curve;
|
ParametricCurve *_curve;
|
||||||
double _tend;
|
double _tend;
|
||||||
};
|
};
|
||||||
@ -239,6 +237,13 @@ protected:
|
|||||||
int _last_ti;
|
int _last_ti;
|
||||||
|
|
||||||
|
|
||||||
|
// TypedWriteable stuff
|
||||||
|
protected:
|
||||||
|
virtual void write_datagram(BamWriter *manager, Datagram &me);
|
||||||
|
void fillin(DatagramIterator &scan, BamReader *manager);
|
||||||
|
virtual int complete_pointers(vector_typedWriteable &plist,
|
||||||
|
BamReader *manager);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static TypeHandle get_class_type() {
|
static TypeHandle get_class_type() {
|
||||||
return _type_handle;
|
return _type_handle;
|
||||||
@ -342,6 +347,16 @@ public:
|
|||||||
LVecBase4f Bx, By, Bz, Bw;
|
LVecBase4f Bx, By, Bz, Bw;
|
||||||
bool rational;
|
bool rational;
|
||||||
|
|
||||||
|
|
||||||
|
// TypedWriteable stuff
|
||||||
|
public:
|
||||||
|
static void register_with_read_factory();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static TypedWriteable *make_CubicCurveseg(const FactoryParams ¶ms);
|
||||||
|
virtual void write_datagram(BamWriter *manager, Datagram &me);
|
||||||
|
void fillin(DatagramIterator &scan, BamReader *manager);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static TypeHandle get_class_type() {
|
static TypeHandle get_class_type() {
|
||||||
return _type_handle;
|
return _type_handle;
|
||||||
|
@ -21,6 +21,12 @@
|
|||||||
#include "config_parametrics.h"
|
#include "config_parametrics.h"
|
||||||
#include "luse.h"
|
#include "luse.h"
|
||||||
|
|
||||||
|
#include <indent.h>
|
||||||
|
#include <datagram.h>
|
||||||
|
#include <datagramIterator.h>
|
||||||
|
#include <bamWriter.h>
|
||||||
|
#include <bamReader.h>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -33,28 +39,15 @@ static const LVecBase3f zero = LVecBase3f(0.0, 0.0, 0.0);
|
|||||||
// used from time to time as an initializer.
|
// used from time to time as an initializer.
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: Indent
|
|
||||||
// Description: This function duplicates a similar function declared
|
|
||||||
// in eggBasics.C. It prints a specified number of
|
|
||||||
// spaces to indent each line of output.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
static ostream &
|
|
||||||
Indent(ostream &out, int indent) {
|
|
||||||
for (int i=0; i<indent; i++) {
|
|
||||||
out << ' ';
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: show_vec3
|
// Function: show_vec3
|
||||||
// Description: This function writes a LVecBase3f, with a specified
|
// Description: This function writes a LVecBase3f, with a specified
|
||||||
// number of significant dimensions.
|
// number of significant dimensions.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
static ostream &
|
static ostream &
|
||||||
show_vec3(ostream &out, int indent, const LVecBase3f &v, int num_dimensions) {
|
show_vec3(ostream &out, int indent_level, const LVecBase3f &v,
|
||||||
Indent(out, indent) << v[0];
|
int num_dimensions) {
|
||||||
|
indent(out, indent_level) << v[0];
|
||||||
for (int i = 1; i<num_dimensions; i++) {
|
for (int i = 1; i<num_dimensions; i++) {
|
||||||
out << " " << v[i];
|
out << " " << v[i];
|
||||||
}
|
}
|
||||||
@ -68,7 +61,6 @@ show_vec3(ostream &out, int indent, const LVecBase3f &v, int num_dimensions) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
HermiteCurveCV::
|
HermiteCurveCV::
|
||||||
HermiteCurveCV() {
|
HermiteCurveCV() {
|
||||||
_name = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -80,13 +72,8 @@ HermiteCurveCV() {
|
|||||||
HermiteCurveCV::
|
HermiteCurveCV::
|
||||||
HermiteCurveCV(const HermiteCurveCV &c) :
|
HermiteCurveCV(const HermiteCurveCV &c) :
|
||||||
_p(c._p), _in(c._in), _out(c._out),
|
_p(c._p), _in(c._in), _out(c._out),
|
||||||
_type(c._type) {
|
_type(c._type), _name(c._name)
|
||||||
if (c._name==NULL) {
|
{
|
||||||
_name = NULL;
|
|
||||||
} else {
|
|
||||||
_name = new char[strlen(c._name)+1];
|
|
||||||
strcpy(_name, c._name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -97,9 +84,6 @@ HermiteCurveCV(const HermiteCurveCV &c) :
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
HermiteCurveCV::
|
HermiteCurveCV::
|
||||||
~HermiteCurveCV() {
|
~HermiteCurveCV() {
|
||||||
if (_name != NULL) {
|
|
||||||
delete [] _name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -192,39 +176,31 @@ set_type(int type) {
|
|||||||
// Description: Sets the name associated with the CV.
|
// Description: Sets the name associated with the CV.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void HermiteCurveCV::
|
void HermiteCurveCV::
|
||||||
set_name(const char *name) {
|
set_name(const string &name) {
|
||||||
if (_name != NULL) {
|
_name = name;
|
||||||
delete [] _name;
|
|
||||||
_name = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name != NULL) {
|
|
||||||
_name = new char[strlen(name)+1];
|
|
||||||
strcpy(_name, name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: HermiteCurveCV::Output
|
// Function: HermiteCurveCV::format_egg
|
||||||
// Access: Public
|
// Access: Public
|
||||||
// Description: Formats the CV for output to an egg file.
|
// Description: Formats the CV for output to an egg file.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void HermiteCurveCV::
|
void HermiteCurveCV::
|
||||||
Output(ostream &out, int indent, int num_dimensions,
|
format_egg(ostream &out, int indent_level, int num_dimensions,
|
||||||
bool show_in, bool show_out,
|
bool show_in, bool show_out,
|
||||||
double scale_in, double scale_out) const {
|
double scale_in, double scale_out) const {
|
||||||
if (show_in) {
|
if (show_in) {
|
||||||
Indent(out, indent) << "<Vertex> {\n";
|
indent(out, indent_level) << "<Vertex> {\n";
|
||||||
show_vec3(out, indent+2, _p - scale_in * _in / 3.0,
|
show_vec3(out, indent_level + 2, _p - scale_in * _in / 3.0,
|
||||||
num_dimensions) << "\n";
|
num_dimensions) << "\n";
|
||||||
Indent(out, indent) << "}\n";
|
indent(out, indent_level) << "}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
Indent(out, indent) << "<Vertex> {\n";
|
indent(out, indent_level) << "<Vertex> {\n";
|
||||||
show_vec3(out, indent+2, _p, num_dimensions) << "\n";
|
show_vec3(out, indent_level + 2, _p, num_dimensions) << "\n";
|
||||||
|
|
||||||
Indent(out, indent+2) << "<Char*> continuity-type { ";
|
indent(out, indent_level+2) << "<Scalar> continuity-type { ";
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
case HC_CUT:
|
case HC_CUT:
|
||||||
out << "Cut";
|
out << "Cut";
|
||||||
@ -244,16 +220,49 @@ Output(ostream &out, int indent, int num_dimensions,
|
|||||||
};
|
};
|
||||||
out << " }\n";
|
out << " }\n";
|
||||||
|
|
||||||
Indent(out, indent) << "}\n";
|
indent(out, indent_level) << "}\n";
|
||||||
|
|
||||||
if (show_out) {
|
if (show_out) {
|
||||||
Indent(out, indent) << "<Vertex> {\n";
|
indent(out, indent_level) << "<Vertex> {\n";
|
||||||
show_vec3(out, indent+2, _p + scale_out * _out / 3.0,
|
show_vec3(out, indent_level + 2, _p + scale_out * _out / 3.0,
|
||||||
num_dimensions) << "\n";
|
num_dimensions) << "\n";
|
||||||
Indent(out, indent) << "}\n";
|
indent(out, indent_level) << "}\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: HermiteCurveCV::write_datagram
|
||||||
|
// Access: Public
|
||||||
|
// Description: Function to write the important information in
|
||||||
|
// the particular object to a Datagram
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void HermiteCurveCV::
|
||||||
|
write_datagram(BamWriter *, Datagram &me) const {
|
||||||
|
_p.write_datagram(me);
|
||||||
|
_in.write_datagram(me);
|
||||||
|
_out.write_datagram(me);
|
||||||
|
me.add_int8(_type);
|
||||||
|
me.add_string(_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: HermiteCurveCV::fillin
|
||||||
|
// Access: Public
|
||||||
|
// Description: Function that reads out of the datagram (or asks
|
||||||
|
// manager to read) all of the data that is needed to
|
||||||
|
// re-create this object and stores it in the appropiate
|
||||||
|
// place
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void HermiteCurveCV::
|
||||||
|
fillin(DatagramIterator &scan, BamReader *) {
|
||||||
|
_p.read_datagram(scan);
|
||||||
|
_in.read_datagram(scan);
|
||||||
|
_out.read_datagram(scan);
|
||||||
|
|
||||||
|
_type = scan.get_int8();
|
||||||
|
_name = scan.get_string();
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: HermiteCurve::Constructor
|
// Function: HermiteCurve::Constructor
|
||||||
// Access: Public, Scheme
|
// Access: Public, Scheme
|
||||||
@ -634,10 +643,10 @@ get_cv_tstart(int n) const {
|
|||||||
// Access: Public, Scheme
|
// Access: Public, Scheme
|
||||||
// Description: Returns the name of the given CV, or NULL.
|
// Description: Returns the name of the given CV, or NULL.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
const char *HermiteCurve::
|
string HermiteCurve::
|
||||||
get_cv_name(int n) const {
|
get_cv_name(int n) const {
|
||||||
if (n < 0 || n >= (int)_points.size()) {
|
if (n < 0 || n >= (int)_points.size()) {
|
||||||
return NULL;
|
return string();
|
||||||
}
|
}
|
||||||
|
|
||||||
return _points[n]._name;
|
return _points[n]._name;
|
||||||
@ -645,47 +654,44 @@ get_cv_name(int n) const {
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: HermiteCurve::Print
|
// Function: HermiteCurve::output
|
||||||
// Access: Public, Scheme
|
// Access: Public, Virtual
|
||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void HermiteCurve::
|
void HermiteCurve::
|
||||||
Print() const {
|
output(ostream &out) const {
|
||||||
ostream& out = parametrics_cat->info();
|
PiecewiseCurve::output(out);
|
||||||
|
|
||||||
|
out << " (";
|
||||||
switch (get_curve_type()) {
|
switch (get_curve_type()) {
|
||||||
case PCT_T:
|
case PCT_T:
|
||||||
out << "Time-warping ";
|
out << "in T, ";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PCT_XYZ:
|
case PCT_XYZ:
|
||||||
out << "XYZ ";
|
out << "in XYZ, ";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PCT_HPR:
|
case PCT_HPR:
|
||||||
out << "HPR ";
|
out << "in HPR, ";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
out
|
out << get_num_cvs() << " CV's)";
|
||||||
<< "HermiteCurve, " << get_num_cvs() << " CV's. t ranges from 0 to "
|
|
||||||
<< get_max_t()
|
|
||||||
<< endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: HermiteCurve::print_cv
|
// Function: HermiteCurve::write_cv
|
||||||
// Access: Public, Scheme
|
// Access: Public, Scheme
|
||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void HermiteCurve::
|
void HermiteCurve::
|
||||||
print_cv(int n) const {
|
write_cv(ostream &out, int n) const {
|
||||||
ostream& out = parametrics_cat->info();
|
|
||||||
out << "CV";
|
out << "CV";
|
||||||
if (get_cv_name(n)!=NULL) {
|
if (!get_cv_name(n).empty()) {
|
||||||
out << " " << get_cv_name(n);
|
out << " " << get_cv_name(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -715,7 +721,7 @@ print_cv(int n) const {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
out << "\n" << endl;
|
out << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -745,7 +751,7 @@ write_egg(const char *filename) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool HermiteCurve::
|
bool HermiteCurve::
|
||||||
write_egg(ostream &out, const char *basename) {
|
write_egg(ostream &out, const char *basename) {
|
||||||
if (get_name().empty()) {
|
if (!has_name()) {
|
||||||
// If we don't have a name, come up with one.
|
// If we don't have a name, come up with one.
|
||||||
int len = strlen(basename);
|
int len = strlen(basename);
|
||||||
if (len>4 && strcmp(basename+len-4, ".egg")==0) {
|
if (len>4 && strcmp(basename+len-4, ".egg")==0) {
|
||||||
@ -774,7 +780,7 @@ write_egg(ostream &out, const char *basename) {
|
|||||||
set_name(name);
|
set_name(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Output(out);
|
format_egg(out);
|
||||||
|
|
||||||
if (out) {
|
if (out) {
|
||||||
return true;
|
return true;
|
||||||
@ -802,30 +808,30 @@ rebuild_curveseg(int, double, const LVecBase4f &,
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: HermiteCurve::Output
|
// Function: HermiteCurve::format_egg
|
||||||
// Access: Public
|
// Access: Public
|
||||||
// Description: Formats the Hermite curve for output to an Egg file.
|
// Description: Formats the Hermite curve for output to an Egg file.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void HermiteCurve::
|
void HermiteCurve::
|
||||||
Output(ostream &out, int indent) const {
|
format_egg(ostream &out, int indent_level) const {
|
||||||
Indent(out, indent)
|
indent(out, indent_level)
|
||||||
<< "<VertexPool> " << get_name() << ".pool {\n";
|
<< "<VertexPool> " << get_name() << ".pool {\n";
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < (int)_points.size(); i++) {
|
for (i = 0; i < (int)_points.size(); i++) {
|
||||||
bool show_in = (i != 0);
|
bool show_in = (i != 0);
|
||||||
bool show_out = (i != (int)_points.size()-1);
|
bool show_out = (i != (int)_points.size()-1);
|
||||||
_points[i].Output(out, indent+2, _num_dimensions,
|
_points[i].format_egg(out, indent_level + 2, _num_dimensions,
|
||||||
show_in, show_out,
|
show_in, show_out,
|
||||||
show_in ? get_tlength(i-1) : 0.0,
|
show_in ? get_tlength(i-1) : 0.0,
|
||||||
show_out ? get_tlength(i) : 0.0);
|
show_out ? get_tlength(i) : 0.0);
|
||||||
}
|
}
|
||||||
Indent(out, indent) << "}\n";
|
indent(out, indent_level) << "}\n";
|
||||||
|
|
||||||
Indent(out, indent) << "<BezierCurve> " << get_name() << " {\n";
|
indent(out, indent_level) << "<BezierCurve> " << get_name() << " {\n";
|
||||||
|
|
||||||
if (_curve_type!=PCT_NONE) {
|
if (_curve_type!=PCT_NONE) {
|
||||||
Indent(out, indent+2) << "<Char*> type { ";
|
indent(out, indent_level+2) << "<Scalar> type { ";
|
||||||
switch (_curve_type) {
|
switch (_curve_type) {
|
||||||
case PCT_XYZ:
|
case PCT_XYZ:
|
||||||
out << "XYZ";
|
out << "XYZ";
|
||||||
@ -842,32 +848,32 @@ Output(ostream &out, int indent) const {
|
|||||||
out << " }\n";
|
out << " }\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
Indent(out, indent+2) << "<TLengths> {";
|
indent(out, indent_level+2) << "<TLengths> {";
|
||||||
if (_points.size() > 1) {
|
if (_points.size() > 1) {
|
||||||
for (i = 0; i < (int)_segs.size(); i++) {
|
for (i = 0; i < (int)_segs.size(); i++) {
|
||||||
if (i%10 == 1) {
|
if (i%10 == 1) {
|
||||||
out << "\n";
|
out << "\n";
|
||||||
Indent(out, indent+3);
|
indent(out, indent_level+3);
|
||||||
}
|
}
|
||||||
out << " " << get_tlength(i);
|
out << " " << get_tlength(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out << "\n";
|
out << "\n";
|
||||||
Indent(out, indent+2) << "}\n";
|
indent(out, indent_level+2) << "}\n";
|
||||||
|
|
||||||
Indent(out, indent+2) << "<VertexRef> {";
|
indent(out, indent_level+2) << "<VertexRef> {";
|
||||||
for (i = 1; i <= (int)_points.size() * 3 - 2; i++) {
|
for (i = 1; i <= (int)_points.size() * 3 - 2; i++) {
|
||||||
if (i%10 == 1) {
|
if (i%10 == 1) {
|
||||||
out << "\n";
|
out << "\n";
|
||||||
Indent(out, indent+3);
|
indent(out, indent_level+3);
|
||||||
}
|
}
|
||||||
out << " " << i;
|
out << " " << i;
|
||||||
}
|
}
|
||||||
out << "\n";
|
out << "\n";
|
||||||
Indent(out, indent+4) << "<Ref> { " << get_name() << ".pool }\n";
|
indent(out, indent_level+4) << "<Ref> { " << get_name() << ".pool }\n";
|
||||||
Indent(out, indent+2) << "}\n";
|
indent(out, indent_level+2) << "}\n";
|
||||||
|
|
||||||
Indent(out, indent) << "}\n";
|
indent(out, indent_level) << "}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -978,3 +984,71 @@ recompute_basis() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: HermiteCurve::register_with_factory
|
||||||
|
// Access: Public, Static
|
||||||
|
// Description: Initializes the factory for reading these things from
|
||||||
|
// Bam files.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void HermiteCurve::
|
||||||
|
register_with_read_factory() {
|
||||||
|
BamReader::get_factory()->register_factory(get_class_type(), make_HermiteCurve);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: HermiteCurve::make_HermiteCurve
|
||||||
|
// Access: Protected
|
||||||
|
// Description: Factory method to generate an object of this type.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
TypedWriteable *HermiteCurve::
|
||||||
|
make_HermiteCurve(const FactoryParams ¶ms) {
|
||||||
|
HermiteCurve *me = new HermiteCurve;
|
||||||
|
BamReader *manager;
|
||||||
|
Datagram packet;
|
||||||
|
|
||||||
|
parse_params(params, manager, packet);
|
||||||
|
DatagramIterator scan(packet);
|
||||||
|
|
||||||
|
me->fillin(scan, manager);
|
||||||
|
return me;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: HermiteCurve::write_datagram
|
||||||
|
// Access: Protected, Virtual
|
||||||
|
// Description: Function to write the important information in
|
||||||
|
// the particular object to a Datagram
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void HermiteCurve::
|
||||||
|
write_datagram(BamWriter *manager, Datagram &me) {
|
||||||
|
PiecewiseCurve::write_datagram(manager, me);
|
||||||
|
|
||||||
|
me.add_uint32(_points.size());
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < _points.size(); i++) {
|
||||||
|
_points[i].write_datagram(manager, me);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: HermiteCurve::fillin
|
||||||
|
// Access: Protected
|
||||||
|
// Description: Function that reads out of the datagram (or asks
|
||||||
|
// manager to read) all of the data that is needed to
|
||||||
|
// re-create this object and stores it in the appropiate
|
||||||
|
// place
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void HermiteCurve::
|
||||||
|
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||||
|
PiecewiseCurve::fillin(scan, manager);
|
||||||
|
|
||||||
|
size_t num_points = scan.get_uint32();
|
||||||
|
_points.reserve(num_points);
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < num_points; i++) {
|
||||||
|
HermiteCurveCV cv;
|
||||||
|
cv.fillin(scan, manager);
|
||||||
|
_points.push_back(cv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -68,15 +68,18 @@ public:
|
|||||||
void set_in(const LVecBase3f &in);
|
void set_in(const LVecBase3f &in);
|
||||||
void set_out(const LVecBase3f &out);
|
void set_out(const LVecBase3f &out);
|
||||||
void set_type(int type);
|
void set_type(int type);
|
||||||
void set_name(const char *name);
|
void set_name(const string &name);
|
||||||
|
|
||||||
void Output(ostream &out, int indent, int num_dimensions,
|
void format_egg(ostream &out, int indent, int num_dimensions,
|
||||||
bool show_in, bool show_out,
|
bool show_in, bool show_out,
|
||||||
double scale_in, double scale_out) const;
|
double scale_in, double scale_out) const;
|
||||||
|
|
||||||
|
void write_datagram(BamWriter *manager, Datagram &me) const;
|
||||||
|
void fillin(DatagramIterator &scan, BamReader *manager);
|
||||||
|
|
||||||
LVecBase3f _p, _in, _out;
|
LVecBase3f _p, _in, _out;
|
||||||
int _type;
|
int _type;
|
||||||
char *_name;
|
string _name;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -133,10 +136,10 @@ PUBLISHED:
|
|||||||
const LVecBase3f &get_cv_out(int n) const;
|
const LVecBase3f &get_cv_out(int n) const;
|
||||||
void get_cv_out(int n, LVecBase3f &v) const;
|
void get_cv_out(int n, LVecBase3f &v) const;
|
||||||
double get_cv_tstart(int n) const;
|
double get_cv_tstart(int n) const;
|
||||||
const char *get_cv_name(int n) const;
|
string get_cv_name(int n) const;
|
||||||
|
|
||||||
void Print() const;
|
virtual void output(ostream &out) const;
|
||||||
void print_cv(int n) const;
|
void write_cv(ostream &out, int n) const;
|
||||||
|
|
||||||
bool write_egg(const char *filename);
|
bool write_egg(const char *filename);
|
||||||
bool write_egg(ostream &out, const char *basename);
|
bool write_egg(ostream &out, const char *basename);
|
||||||
@ -153,7 +156,7 @@ public:
|
|||||||
int rtype2, double t2, const LVecBase4f &v2,
|
int rtype2, double t2, const LVecBase4f &v2,
|
||||||
int rtype3, double t3, const LVecBase4f &v3);
|
int rtype3, double t3, const LVecBase4f &v3);
|
||||||
|
|
||||||
void Output(ostream &out, int indent=0) const;
|
void format_egg(ostream &out, int indent=0) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -163,6 +166,15 @@ protected:
|
|||||||
|
|
||||||
vector<HermiteCurveCV> _points;
|
vector<HermiteCurveCV> _points;
|
||||||
|
|
||||||
|
// TypedWriteable stuff
|
||||||
|
public:
|
||||||
|
static void register_with_read_factory();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static TypedWriteable *make_HermiteCurve(const FactoryParams ¶ms);
|
||||||
|
virtual void write_datagram(BamWriter *manager, Datagram &me);
|
||||||
|
void fillin(DatagramIterator &scan, BamReader *manager);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static TypeHandle get_class_type() {
|
static TypeHandle get_class_type() {
|
||||||
return _type_handle;
|
return _type_handle;
|
||||||
|
@ -16,6 +16,10 @@
|
|||||||
#include "config_parametrics.h"
|
#include "config_parametrics.h"
|
||||||
|
|
||||||
#include <indent.h>
|
#include <indent.h>
|
||||||
|
#include <datagram.h>
|
||||||
|
#include <datagramIterator.h>
|
||||||
|
#include <bamWriter.h>
|
||||||
|
#include <bamReader.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Statics
|
// Statics
|
||||||
@ -154,7 +158,7 @@ insert_cv(double t) {
|
|||||||
t = 0.0;
|
t = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int k = FindCV(t);
|
int k = find_cv(t);
|
||||||
if (k < 0) {
|
if (k < 0) {
|
||||||
return append_cv(_cvs.back()._p);
|
return append_cv(_cvs.back()._p);
|
||||||
}
|
}
|
||||||
@ -169,8 +173,8 @@ insert_cv(double t) {
|
|||||||
int i;
|
int i;
|
||||||
for (i = 0; i < _order-1; i++) {
|
for (i = 0; i < _order-1; i++) {
|
||||||
int nk = i + k - (_order-1);
|
int nk = i + k - (_order-1);
|
||||||
double ti = GetKnot(nk);
|
double ti = get_knot(nk);
|
||||||
double d = GetKnot(nk + _order-1) - ti;
|
double d = get_knot(nk + _order-1) - ti;
|
||||||
if (d == 0.0) {
|
if (d == 0.0) {
|
||||||
new_cvs[i] = _cvs[nk-1]._p;
|
new_cvs[i] = _cvs[nk-1]._p;
|
||||||
} else {
|
} else {
|
||||||
@ -331,17 +335,6 @@ set_knot(int n, double t) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: NurbsCurve::get_knot
|
|
||||||
// Access: Public, Scheme
|
|
||||||
// Description: Returns the value of the indicated knot. There are
|
|
||||||
// get_num_cvs()+_order-1 knot values.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
double NurbsCurve::
|
|
||||||
get_knot(int n) const {
|
|
||||||
return GetKnot(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: NurbsCurve::write
|
// Function: NurbsCurve::write
|
||||||
// Access: Public, Scheme
|
// Access: Public, Scheme
|
||||||
@ -383,7 +376,7 @@ write(ostream &out, int indent_level) const {
|
|||||||
indent(out, indent_level)
|
indent(out, indent_level)
|
||||||
<< "Knots: ";
|
<< "Knots: ";
|
||||||
for (i = 0; i < (int)_cvs.size()+_order; i++) {
|
for (i = 0; i < (int)_cvs.size()+_order; i++) {
|
||||||
out << " " << GetKnot(i);
|
out << " " << get_knot(i);
|
||||||
}
|
}
|
||||||
out << "\n";
|
out << "\n";
|
||||||
}
|
}
|
||||||
@ -424,7 +417,7 @@ recompute() {
|
|||||||
|
|
||||||
if ((int)_cvs.size() > _order-1) {
|
if ((int)_cvs.size() > _order-1) {
|
||||||
for (int cv = 0; cv < (int)_cvs.size()-(_order-1); cv++) {
|
for (int cv = 0; cv < (int)_cvs.size()-(_order-1); cv++) {
|
||||||
if (GetKnot(cv+_order-1) < GetKnot(cv+_order)) {
|
if (get_knot(cv+_order-1) < get_knot(cv+_order)) {
|
||||||
// There are _order consecutive CV's that define each segment,
|
// There are _order consecutive CV's that define each segment,
|
||||||
// beginning at cv. Collect the CV's and knot values that define
|
// beginning at cv. Collect the CV's and knot values that define
|
||||||
// this segment.
|
// this segment.
|
||||||
@ -433,7 +426,7 @@ recompute() {
|
|||||||
cvs[c] = _cvs[c+cv]._p;
|
cvs[c] = _cvs[c+cv]._p;
|
||||||
}
|
}
|
||||||
for (c = 0; c < _order+_order; c++) {
|
for (c = 0; c < _order+_order; c++) {
|
||||||
knots[c] = GetKnot(c+cv);
|
knots[c] = get_knot(c+cv);
|
||||||
}
|
}
|
||||||
|
|
||||||
insert_curveseg(_segs.size(), new CubicCurveseg(_order, knots, cvs),
|
insert_curveseg(_segs.size(), new CubicCurveseg(_order, knots, cvs),
|
||||||
@ -511,7 +504,7 @@ adjust_pt(double t,
|
|||||||
|
|
||||||
int cv = 0;
|
int cv = 0;
|
||||||
for (cv = 0; cv < _cvs.size()-(_order-1); cv++) {
|
for (cv = 0; cv < _cvs.size()-(_order-1); cv++) {
|
||||||
if (GetKnot(cv+_order-1) < GetKnot(cv+_order)) {
|
if (get_knot(cv+_order-1) < get_knot(cv+_order)) {
|
||||||
if (seg == _last_ti) {
|
if (seg == _last_ti) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -528,7 +521,7 @@ adjust_pt(double t,
|
|||||||
cvs[c] = (c < _order) ? _cvs[c+cv]._p : LVecBase4f(0.0, 0.0, 0.0, 0.0);
|
cvs[c] = (c < _order) ? _cvs[c+cv]._p : LVecBase4f(0.0, 0.0, 0.0, 0.0);
|
||||||
}
|
}
|
||||||
for (c = 0; c < _order+_order; c++) {
|
for (c = 0; c < _order+_order; c++) {
|
||||||
knots[c] = GetKnot(c+cv);
|
knots[c] = get_knot(c+cv);
|
||||||
}
|
}
|
||||||
|
|
||||||
dnassert(_order>=1 && _order<=4);
|
dnassert(_order>=1 && _order<=4);
|
||||||
@ -620,7 +613,7 @@ rebuild_curveseg(int rtype0, double t0, const LVecBase4f &v0,
|
|||||||
|
|
||||||
int cv = 0;
|
int cv = 0;
|
||||||
for (cv = 0; cv < (int)_cvs.size()-(_order-1); cv++) {
|
for (cv = 0; cv < (int)_cvs.size()-(_order-1); cv++) {
|
||||||
if (GetKnot(cv+_order-1) < GetKnot(cv+_order)) {
|
if (get_knot(cv+_order-1) < get_knot(cv+_order)) {
|
||||||
if (seg == _last_ti) {
|
if (seg == _last_ti) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -647,7 +640,7 @@ rebuild_curveseg(int rtype0, double t0, const LVecBase4f &v0,
|
|||||||
|
|
||||||
// But we always need the knot vector to determine the basis matrix.
|
// But we always need the knot vector to determine the basis matrix.
|
||||||
for (c = 0; c < _order+_order; c++) {
|
for (c = 0; c < _order+_order; c++) {
|
||||||
knots[c] = GetKnot(c+cv);
|
knots[c] = get_knot(c+cv);
|
||||||
}
|
}
|
||||||
|
|
||||||
LMatrix4f B;
|
LMatrix4f B;
|
||||||
@ -876,7 +869,7 @@ format_egg(ostream &out, CoordinateSystem cs, int indent_level) const {
|
|||||||
out << "\n";
|
out << "\n";
|
||||||
indent(out, indent_level+4);
|
indent(out, indent_level+4);
|
||||||
}
|
}
|
||||||
out << GetKnot(k) << " ";
|
out << get_knot(k) << " ";
|
||||||
}
|
}
|
||||||
out << "\n";
|
out << "\n";
|
||||||
indent(out, indent_level+2) << "}\n";
|
indent(out, indent_level+2) << "}\n";
|
||||||
@ -898,13 +891,13 @@ format_egg(ostream &out, CoordinateSystem cs, int indent_level) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: NurbsCurve::FindCV
|
// Function: NurbsCurve::find_cv
|
||||||
// Access: Protected
|
// Access: Protected
|
||||||
// Description: Finds the first knot whose value is >= t, or -1 if t
|
// Description: Finds the first knot whose value is >= t, or -1 if t
|
||||||
// is beyond the end of the curve.
|
// is beyond the end of the curve.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
int NurbsCurve::
|
int NurbsCurve::
|
||||||
FindCV(double t) {
|
find_cv(double t) {
|
||||||
int i;
|
int i;
|
||||||
for (i = _order-1; i < (int)_cvs.size(); i++) {
|
for (i = _order-1; i < (int)_cvs.size(); i++) {
|
||||||
if (_cvs[i]._t >= t) {
|
if (_cvs[i]._t >= t) {
|
||||||
@ -914,3 +907,79 @@ FindCV(double t) {
|
|||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: NurbsCurve::register_with_factory
|
||||||
|
// Access: Public, Static
|
||||||
|
// Description: Initializes the factory for reading these things from
|
||||||
|
// Bam files.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void NurbsCurve::
|
||||||
|
register_with_read_factory() {
|
||||||
|
BamReader::get_factory()->register_factory(get_class_type(), make_NurbsCurve);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: NurbsCurve::make_NurbsCurve
|
||||||
|
// Access: Protected
|
||||||
|
// Description: Factory method to generate an object of this type.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
TypedWriteable *NurbsCurve::
|
||||||
|
make_NurbsCurve(const FactoryParams ¶ms) {
|
||||||
|
NurbsCurve *me = new NurbsCurve;
|
||||||
|
BamReader *manager;
|
||||||
|
Datagram packet;
|
||||||
|
|
||||||
|
parse_params(params, manager, packet);
|
||||||
|
DatagramIterator scan(packet);
|
||||||
|
|
||||||
|
me->fillin(scan, manager);
|
||||||
|
return me;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: NurbsCurve::write_datagram
|
||||||
|
// Access: Protected, Virtual
|
||||||
|
// Description: Function to write the important information in
|
||||||
|
// the particular object to a Datagram
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void NurbsCurve::
|
||||||
|
write_datagram(BamWriter *manager, Datagram &me) {
|
||||||
|
PiecewiseCurve::write_datagram(manager, me);
|
||||||
|
|
||||||
|
me.add_int8(_order);
|
||||||
|
|
||||||
|
me.add_uint32(_cvs.size());
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < _cvs.size(); i++) {
|
||||||
|
const CV &cv = _cvs[i];
|
||||||
|
cv._p.write_datagram(me);
|
||||||
|
me.add_float64(cv._t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: NurbsCurve::fillin
|
||||||
|
// Access: Protected
|
||||||
|
// Description: Function that reads out of the datagram (or asks
|
||||||
|
// manager to read) all of the data that is needed to
|
||||||
|
// re-create this object and stores it in the appropiate
|
||||||
|
// place
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void NurbsCurve::
|
||||||
|
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||||
|
PiecewiseCurve::fillin(scan, manager);
|
||||||
|
|
||||||
|
_order = scan.get_int8();
|
||||||
|
|
||||||
|
size_t num_cvs = scan.get_uint32();
|
||||||
|
|
||||||
|
_cvs.reserve(num_cvs);
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < num_cvs; i++) {
|
||||||
|
CV cv;
|
||||||
|
cv._p.read_datagram(scan);
|
||||||
|
cv._t = scan.get_float64();
|
||||||
|
_cvs.push_back(cv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -67,7 +67,7 @@ PUBLISHED:
|
|||||||
return append_cv(LVecBase4f(v[0], v[1], v[2], 1.0));
|
return append_cv(LVecBase4f(v[0], v[1], v[2], 1.0));
|
||||||
}
|
}
|
||||||
inline int append_cv(const LVecBase4f &v) {
|
inline int append_cv(const LVecBase4f &v) {
|
||||||
_cvs.push_back(CV(v, GetKnot(_cvs.size())+1.0));
|
_cvs.push_back(CV(v, get_knot(_cvs.size())+1.0));
|
||||||
return _cvs.size()-1;
|
return _cvs.size()-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,15 @@ PUBLISHED:
|
|||||||
float get_cv_weight(int n) const;
|
float get_cv_weight(int n) const;
|
||||||
|
|
||||||
bool set_knot(int n, double t);
|
bool set_knot(int n, double t);
|
||||||
double get_knot(int n) const;
|
double get_knot(int n) const {
|
||||||
|
if (n < _order || _cvs.empty()) {
|
||||||
|
return 0.0;
|
||||||
|
} else if (n-1 >= (int)_cvs.size()) {
|
||||||
|
return _cvs.back()._t;
|
||||||
|
} else {
|
||||||
|
return _cvs[n-1]._t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual void write(ostream &out, int indent_level = 0) const;
|
virtual void write(ostream &out, int indent_level = 0) const;
|
||||||
void write_cv(ostream &out, int n) const;
|
void write_cv(ostream &out, int n) const;
|
||||||
@ -113,21 +121,10 @@ public:
|
|||||||
return (CubicCurveseg *)PiecewiseCurve::get_curveseg(ti);
|
return (CubicCurveseg *)PiecewiseCurve::get_curveseg(ti);
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
|
||||||
GetKnot(int n) const {
|
|
||||||
if (n < _order || _cvs.empty()) {
|
|
||||||
return 0.0;
|
|
||||||
} else if (n-1 >= (int)_cvs.size()) {
|
|
||||||
return _cvs.back()._t;
|
|
||||||
} else {
|
|
||||||
return _cvs[n-1]._t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void format_egg(ostream &out, CoordinateSystem cs, int indent_level) const;
|
void format_egg(ostream &out, CoordinateSystem cs, int indent_level) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int FindCV(double t);
|
int find_cv(double t);
|
||||||
|
|
||||||
int _order;
|
int _order;
|
||||||
|
|
||||||
@ -142,6 +139,15 @@ protected:
|
|||||||
vector<CV> _cvs;
|
vector<CV> _cvs;
|
||||||
|
|
||||||
|
|
||||||
|
// TypedWriteable stuff
|
||||||
|
public:
|
||||||
|
static void register_with_read_factory();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static TypedWriteable *make_NurbsCurve(const FactoryParams ¶ms);
|
||||||
|
virtual void write_datagram(BamWriter *manager, Datagram &me);
|
||||||
|
void fillin(DatagramIterator &scan, BamReader *manager);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static TypeHandle get_class_type() {
|
static TypeHandle get_class_type() {
|
||||||
return _type_handle;
|
return _type_handle;
|
||||||
|
@ -125,11 +125,11 @@ draw() {
|
|||||||
double lt = -1.0;
|
double lt = -1.0;
|
||||||
int ki = -1;
|
int ki = -1;
|
||||||
for (i = 0; i < _num_cvs; i++) {
|
for (i = 0; i < _num_cvs; i++) {
|
||||||
double t = nurbs->GetKnot(i);
|
double t = nurbs->get_knot(i);
|
||||||
if (t != lt) {
|
if (t != lt) {
|
||||||
lt = t;
|
lt = t;
|
||||||
LVecBase3f knot_pos, knot_tan;
|
LVecBase3f knot_pos, knot_tan;
|
||||||
nurbs->get_pt(nurbs->GetKnot(i), knot_pos, knot_tan);
|
nurbs->get_pt(nurbs->get_knot(i), knot_pos, knot_tan);
|
||||||
_knots.move_to(_mapper(knot_pos, knot_tan, t));
|
_knots.move_to(_mapper(knot_pos, knot_tan, t));
|
||||||
ki++;
|
ki++;
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ draw() {
|
|||||||
_num_cvs = nurbs->get_num_cvs();
|
_num_cvs = nurbs->get_num_cvs();
|
||||||
for (i = 0; i < _num_cvs; i++) {
|
for (i = 0; i < _num_cvs; i++) {
|
||||||
_cvs.move_to(_mapper(nurbs->get_cv_point(i), LVecBase3f(0.0, 0.0, 0.0),
|
_cvs.move_to(_mapper(nurbs->get_cv_point(i), LVecBase3f(0.0, 0.0, 0.0),
|
||||||
nurbs->GetKnot(i+1)));
|
nurbs->get_knot(i+1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
_cvs.create(_geom_node, _frame_accurate);
|
_cvs.create(_geom_node, _frame_accurate);
|
||||||
@ -153,7 +153,7 @@ draw() {
|
|||||||
_num_cvs = nurbs->get_num_cvs();
|
_num_cvs = nurbs->get_num_cvs();
|
||||||
for (i = 0; i < _num_cvs; i++) {
|
for (i = 0; i < _num_cvs; i++) {
|
||||||
_hull.draw_to(_mapper(nurbs->get_cv_point(i), LVecBase3f(0.0, 0.0, 0.0),
|
_hull.draw_to(_mapper(nurbs->get_cv_point(i), LVecBase3f(0.0, 0.0, 0.0),
|
||||||
nurbs->GetKnot(i+1)));
|
nurbs->get_knot(i+1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
_hull.create(_geom_node, _frame_accurate);
|
_hull.create(_geom_node, _frame_accurate);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user