*** empty log message ***
This commit is contained in:
parent
ace2c70654
commit
827ae6b464
|
|
@ -44,6 +44,23 @@ ParametricCurve() {
|
|||
_num_dimensions = 3;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ParametricCurve::Destructor
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
ParametricCurve::
|
||||
~ParametricCurve() {
|
||||
// We must disable each of the drawers that were registered to us,
|
||||
// so they don't try to access our pointers any more.
|
||||
DrawerList::iterator d;
|
||||
|
||||
for (d = _drawers.begin();
|
||||
d != _drawers.end();
|
||||
++d) {
|
||||
(*d)->disable(this);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ParametricCurve::is_valid
|
||||
|
|
@ -168,7 +185,7 @@ calc_length() const {
|
|||
float ParametricCurve::
|
||||
calc_length(double from, double to) const {
|
||||
double t1, t2;
|
||||
LVector3f p1, p2;
|
||||
LPoint3f p1, p2;
|
||||
|
||||
// Normally we expect from < to. If they came in backwards, reverse
|
||||
// them.
|
||||
|
|
@ -289,7 +306,7 @@ convert_to_hermite(HermiteCurve &hc) const {
|
|||
n = hc.append_cv(HC_SMOOTH, bz_segs[0]._v[0]);
|
||||
hc.set_cv_out(n, 3.0 * (bz_segs[0]._v[1] - bz_segs[0]._v[0]) / scale_out);
|
||||
|
||||
for (i = 0; i < bz_segs.size()-1; i++) {
|
||||
for (i = 0; i < (int)bz_segs.size()-1; i++) {
|
||||
scale_in = scale_out;
|
||||
scale_out = bz_segs[i+1]._t - bz_segs[i]._t;
|
||||
|
||||
|
|
@ -353,11 +370,11 @@ convert_to_nurbs(NurbsCurve &nc) const {
|
|||
nc.set_order(4);
|
||||
if (!bz_segs.empty()) {
|
||||
int i;
|
||||
for (i = 0; i<bz_segs.size(); i++) {
|
||||
for (i = 0; i < (int)bz_segs.size(); i++) {
|
||||
nc.append_cv(bz_segs[i]._v[0]);
|
||||
nc.append_cv(bz_segs[i]._v[1]);
|
||||
nc.append_cv(bz_segs[i]._v[2]);
|
||||
if (i == bz_segs.size()-1 ||
|
||||
if (i == (int)bz_segs.size()-1 ||
|
||||
!bz_segs[i]._v[3].almost_equal(bz_segs[i+1]._v[0], 0.0001)) {
|
||||
nc.append_cv(bz_segs[i]._v[3]);
|
||||
}
|
||||
|
|
@ -370,20 +387,21 @@ convert_to_nurbs(NurbsCurve &nc) const {
|
|||
nc.set_knot(2, 0.0);
|
||||
nc.set_knot(3, 0.0);
|
||||
|
||||
for (i = 0; i<bz_segs.size(); i++) {
|
||||
for (i = 0; i < (int)bz_segs.size(); i++) {
|
||||
t = bz_segs[i]._t;
|
||||
|
||||
nc.set_knot(ki, t);
|
||||
nc.set_knot(ki+1, t);
|
||||
nc.set_knot(ki+2, t);
|
||||
ki += 3;
|
||||
if (i == bz_segs.size()-1 ||
|
||||
if (i == (int)bz_segs.size()-1 ||
|
||||
!bz_segs[i]._v[3].almost_equal(bz_segs[i+1]._v[0], 0.0001)) {
|
||||
nc.set_knot(ki, t);
|
||||
ki++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nc.recompute();
|
||||
|
||||
return nc.is_valid();
|
||||
|
|
@ -403,7 +421,7 @@ ascii_draw() const {
|
|||
|
||||
float minx, minz, maxx, maxz;
|
||||
|
||||
LVector3f p;
|
||||
LVecBase3f p;
|
||||
get_point(0.0, p);
|
||||
minx = maxx = p[0];
|
||||
minz = maxz = p[2];
|
||||
|
|
@ -438,8 +456,8 @@ ascii_draw() const {
|
|||
|
||||
for (t = 0.0; t <= get_max_t(); t += 0.0625) {
|
||||
if (get_point(t, p)) {
|
||||
c = (p[0] - minx) * xscale;
|
||||
r = (p[2] - minz) * zscale;
|
||||
c = (int)((p[0] - minx) * xscale);
|
||||
r = (int)((p[2] - minz) * zscale);
|
||||
|
||||
if (r>=0 && r<rows && c>=0 && c<cols) {
|
||||
int digit = ((int)floor(t))%10;
|
||||
|
|
@ -492,24 +510,6 @@ unregister_drawer(ParametricCurveDrawer *drawer) {
|
|||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ParametricCurve::Destructor
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
ParametricCurve::
|
||||
~ParametricCurve() {
|
||||
// We must disable each of the drawers that were registered to us,
|
||||
// so they don't try to access our pointers any more.
|
||||
DrawerList::iterator d;
|
||||
|
||||
for (d = _drawers.begin();
|
||||
d != _drawers.end();
|
||||
++d) {
|
||||
(*d)->disable(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ParametricCurve::invalidate
|
||||
|
|
@ -558,7 +558,7 @@ invalidate_all() {
|
|||
// has the length seglength.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
float ParametricCurve::
|
||||
r_calc_length(double t1, double t2, const LVector3f &p1, const LVector3f &p2,
|
||||
r_calc_length(double t1, double t2, const LPoint3f &p1, const LPoint3f &p2,
|
||||
float seglength) const {
|
||||
static const float length_tolerance = 0.0000001;
|
||||
static const double t_tolerance = 0.000001;
|
||||
|
|
@ -569,7 +569,7 @@ r_calc_length(double t1, double t2, const LVector3f &p1, const LVector3f &p2,
|
|||
return 0.0;
|
||||
} else {
|
||||
double tmid;
|
||||
LVector3f pmid;
|
||||
LPoint3f pmid;
|
||||
float left, right;
|
||||
|
||||
// Calculate the point on the curve midway between the two
|
||||
|
|
@ -615,6 +615,16 @@ PiecewiseCurve() {
|
|||
_last_ti = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PiecewiseCurve::Destructor
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PiecewiseCurve::
|
||||
~PiecewiseCurve() {
|
||||
remove_all_curvesegs();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PiecewiseCurve::is_valid
|
||||
|
|
@ -651,7 +661,7 @@ get_max_t() const {
|
|||
// end (whichever is nearer) and returns false.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PiecewiseCurve::
|
||||
get_point(double t, LVector3f &point) const {
|
||||
get_point(double t, LVecBase3f &point) const {
|
||||
const ParametricCurve *curve;
|
||||
bool result = find_curve(curve, t);
|
||||
|
||||
|
|
@ -667,7 +677,7 @@ get_point(double t, LVector3f &point) const {
|
|||
// point t.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PiecewiseCurve::
|
||||
get_tangent(double t, LVector3f &tangent) const {
|
||||
get_tangent(double t, LVecBase3f &tangent) const {
|
||||
const ParametricCurve *curve;
|
||||
bool result = find_curve(curve, t);
|
||||
|
||||
|
|
@ -683,7 +693,7 @@ get_tangent(double t, LVector3f &tangent) const {
|
|||
// curve at the point t.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PiecewiseCurve::
|
||||
get_2ndtangent(double t, LVector3f &tangent2) const {
|
||||
get_2ndtangent(double t, LVecBase3f &tangent2) const {
|
||||
const ParametricCurve *curve;
|
||||
bool result = find_curve(curve, t);
|
||||
|
||||
|
|
@ -709,10 +719,10 @@ adjust_point(double t,
|
|||
return false;
|
||||
}
|
||||
|
||||
rebuild_curveseg(RT_CV | RT_KEEP_ORIG, 0.0, LVector4f(),
|
||||
RT_POINT, t, LVector4f(px, py, pz, 1.0),
|
||||
RT_TANGENT | RT_KEEP_ORIG, t, LVector4f(),
|
||||
RT_CV | RT_KEEP_ORIG, 0.0, LVector4f());
|
||||
rebuild_curveseg(RT_CV | RT_KEEP_ORIG, 0.0, LVecBase4f(),
|
||||
RT_POINT, t, LVecBase4f(px, py, pz, 1.0),
|
||||
RT_TANGENT | RT_KEEP_ORIG, t, LVecBase4f(),
|
||||
RT_CV | RT_KEEP_ORIG, 0.0, LVecBase4f());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -734,10 +744,10 @@ adjust_tangent(double t,
|
|||
return false;
|
||||
}
|
||||
|
||||
rebuild_curveseg(RT_CV | RT_KEEP_ORIG, 0.0, LVector4f(),
|
||||
RT_POINT | RT_KEEP_ORIG, t, LVector4f(),
|
||||
RT_TANGENT, t, LVector4f(tx, ty, tz, 0.0),
|
||||
RT_CV | RT_KEEP_ORIG, 0.0, LVector4f());
|
||||
rebuild_curveseg(RT_CV | RT_KEEP_ORIG, 0.0, LVecBase4f(),
|
||||
RT_POINT | RT_KEEP_ORIG, t, LVecBase4f(),
|
||||
RT_TANGENT, t, LVecBase4f(tx, ty, tz, 0.0),
|
||||
RT_CV | RT_KEEP_ORIG, 0.0, LVecBase4f());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -759,10 +769,10 @@ adjust_pt(double t,
|
|||
return false;
|
||||
}
|
||||
|
||||
rebuild_curveseg(RT_CV | RT_KEEP_ORIG, 0.0, LVector4f(),
|
||||
RT_POINT, t, LVector4f(px, py, pz, 1.0),
|
||||
RT_TANGENT, t, LVector4f(tx, ty, tz, 0.0),
|
||||
RT_CV | RT_KEEP_ORIG, 0.0, LVector4f());
|
||||
rebuild_curveseg(RT_CV | RT_KEEP_ORIG, 0.0, LVecBase4f(),
|
||||
RT_POINT, t, LVecBase4f(px, py, pz, 1.0),
|
||||
RT_TANGENT, t, LVecBase4f(tx, ty, tz, 0.0),
|
||||
RT_CV | RT_KEEP_ORIG, 0.0, LVecBase4f());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -774,7 +784,7 @@ adjust_pt(double t,
|
|||
// curve at a given parametric point t.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PiecewiseCurve::
|
||||
get_pt(double t, LVector3f &point, LVector3f &tangent) const {
|
||||
get_pt(double t, LVecBase3f &point, LVecBase3f &tangent) const {
|
||||
const ParametricCurve *curve;
|
||||
bool result = find_curve(curve, t);
|
||||
|
||||
|
|
@ -802,7 +812,7 @@ get_num_segs() const {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
ParametricCurve *PiecewiseCurve::
|
||||
get_curveseg(int ti) {
|
||||
assert(ti>=0 && ti<_segs.size());
|
||||
assert(ti >= 0 && ti < (int)_segs.size());
|
||||
return _segs[ti]._curve;
|
||||
}
|
||||
|
||||
|
|
@ -822,11 +832,11 @@ get_curveseg(int ti) {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
bool PiecewiseCurve::
|
||||
insert_curveseg(int ti, ParametricCurve *seg, double tlength) {
|
||||
if (ti<0 || ti>_segs.size()) {
|
||||
if (ti < 0 || ti > (int)_segs.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ti==_segs.size()) {
|
||||
if (ti == (int)_segs.size()) {
|
||||
_segs.push_back(Curveseg(seg, get_max_t() + tlength));
|
||||
|
||||
} else if (ti==0) {
|
||||
|
|
@ -851,16 +861,16 @@ insert_curveseg(int ti, ParametricCurve *seg, double tlength) {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
bool PiecewiseCurve::
|
||||
remove_curveseg(int ti) {
|
||||
if (ti<0 || ti>=_segs.size()) {
|
||||
if (ti < 0 || ti >= (int)_segs.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int tlength = get_tlength(ti);
|
||||
double tlength = get_tlength(ti);
|
||||
_segs.erase(_segs.begin() + ti);
|
||||
|
||||
// Now update the _tend figures for everything after the one we
|
||||
// removed.
|
||||
while (ti < _segs.size()) {
|
||||
while (ti < (int)_segs.size()) {
|
||||
_segs[ti]._tend -= tlength;
|
||||
ti++;
|
||||
}
|
||||
|
|
@ -888,7 +898,7 @@ remove_all_curvesegs() {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
double PiecewiseCurve::
|
||||
get_tlength(int ti) const {
|
||||
assert(ti>=0 && ti<_segs.size());
|
||||
assert(ti >= 0 && ti < (int)_segs.size());
|
||||
return (ti==0) ? _segs[ti]._tend : _segs[ti]._tend - _segs[ti-1]._tend;
|
||||
}
|
||||
|
||||
|
|
@ -900,7 +910,7 @@ get_tlength(int ti) const {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
double PiecewiseCurve::
|
||||
get_tstart(int ti) const {
|
||||
assert(ti>=0 && ti<=_segs.size());
|
||||
assert(ti >= 0 && ti <= (int)_segs.size());
|
||||
return (ti==0) ? 0.0 : _segs[ti-1]._tend;
|
||||
}
|
||||
|
||||
|
|
@ -912,7 +922,7 @@ get_tstart(int ti) const {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
double PiecewiseCurve::
|
||||
get_tend(int ti) const {
|
||||
assert(ti>=0 && ti<_segs.size());
|
||||
assert(ti >= 0 && ti < (int)_segs.size());
|
||||
return _segs[ti]._tend;
|
||||
}
|
||||
|
||||
|
|
@ -927,7 +937,7 @@ get_tend(int ti) const {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
bool PiecewiseCurve::
|
||||
set_tlength(int ti, double tlength) {
|
||||
if (ti<0 || ti>=_segs.size()) {
|
||||
if (ti < 0 || ti >= (int)_segs.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -953,7 +963,7 @@ set_tlength(int ti, double tlength) {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
void PiecewiseCurve::
|
||||
make_nurbs(int order, int num_cvs,
|
||||
const double knots[], const LVector4f cvs[]) {
|
||||
const double knots[], const LVecBase4f cvs[]) {
|
||||
remove_all_curvesegs();
|
||||
|
||||
for (int i=0; i<num_cvs - order + 1; i++) {
|
||||
|
|
@ -982,7 +992,7 @@ GetBezierSegs(BezierSegs &bz_segs) const {
|
|||
bz_segs.erase(bz_segs.begin(), bz_segs.end());
|
||||
int i;
|
||||
BezierSeg seg;
|
||||
for (i = 0; i < _segs.size(); i++) {
|
||||
for (i = 0; i < (int)_segs.size(); i++) {
|
||||
if (!_segs[i]._curve->GetBezierSeg(seg)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1003,24 +1013,14 @@ GetBezierSegs(BezierSegs &bz_segs) const {
|
|||
// possible, false if something goes horribly wrong.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PiecewiseCurve::
|
||||
rebuild_curveseg(int, double, const LVector4f &,
|
||||
int, double, const LVector4f &,
|
||||
int, double, const LVector4f &,
|
||||
int, double, const LVector4f &) {
|
||||
rebuild_curveseg(int, double, const LVecBase4f &,
|
||||
int, double, const LVecBase4f &,
|
||||
int, double, const LVecBase4f &,
|
||||
int, double, const LVecBase4f &) {
|
||||
cerr << "rebuild_curveseg not implemented for this curve type.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PiecewiseCurve::Destructor
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PiecewiseCurve::
|
||||
~PiecewiseCurve() {
|
||||
remove_all_curvesegs();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PiecewiseCurve::find_curve
|
||||
// Access: Protected
|
||||
|
|
@ -1053,13 +1053,13 @@ find_curve(const ParametricCurve *&curve, double &t) const {
|
|||
}
|
||||
|
||||
int ti;
|
||||
for (ti = _last_ti; ti<_segs.size(); ti++) {
|
||||
for (ti = _last_ti; ti < (int)_segs.size(); ti++) {
|
||||
if (_segs[ti]._tend+0.00001 > t) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ti < _segs.size()) {
|
||||
if (ti < (int)_segs.size()) {
|
||||
// Adjust t to the range [0,1).
|
||||
if (ti > 0) {
|
||||
t = (t - _segs[ti-1]._tend) / (_segs[ti]._tend - _segs[ti-1]._tend);
|
||||
|
|
@ -1075,8 +1075,8 @@ find_curve(const ParametricCurve *&curve, double &t) const {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (ti >= _segs.size() || !_segs[ti]._curve->is_valid()) {
|
||||
assert(ti <= _segs.size());
|
||||
if (ti >= (int)_segs.size() || !_segs[ti]._curve->is_valid()) {
|
||||
assert(ti <= (int)_segs.size());
|
||||
|
||||
// If we're out of bounds, or the curve is undefined, we're probably
|
||||
// screwed. There's one exception: if we were right on a border between
|
||||
|
|
@ -1087,7 +1087,7 @@ find_curve(const ParametricCurve *&curve, double &t) const {
|
|||
t = 1.0;
|
||||
}
|
||||
|
||||
if (ti >= _segs.size()) {
|
||||
if (ti >= (int)_segs.size()) {
|
||||
if (_segs.empty()) {
|
||||
curve = NULL;
|
||||
t = 0.0;
|
||||
|
|
@ -1132,7 +1132,7 @@ double PiecewiseCurve::
|
|||
current_seg_range(double t) const {
|
||||
int ti = _last_ti;
|
||||
|
||||
assert(ti < _segs.size());
|
||||
assert(ti < (int)_segs.size());
|
||||
|
||||
// Adjust t to the range [0,1).
|
||||
if (ti > 0) {
|
||||
|
|
@ -1187,10 +1187,19 @@ CubicCurveseg(const BezierSeg &seg) {
|
|||
// nurbs_basis for a description of the parameters.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
CubicCurveseg::
|
||||
CubicCurveseg(int order, const double knots[], const LVector4f cvs[]) {
|
||||
CubicCurveseg(int order, const double knots[], const LVecBase4f cvs[]) {
|
||||
nurbs_basis(order, knots, cvs);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CubicCurveseg::Destructor
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
CubicCurveseg::
|
||||
~CubicCurveseg() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -1200,8 +1209,8 @@ CubicCurveseg(int order, const double knots[], const LVector4f cvs[]) {
|
|||
// point t.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool CubicCurveseg::
|
||||
get_point(double t, LVector3f &point) const {
|
||||
evaluate_point(LVector4f(t*t*t, t*t, t, 1.0), point);
|
||||
get_point(double t, LVecBase3f &point) const {
|
||||
evaluate_point(LVecBase4f(t*t*t, t*t, t, 1.0), point);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1212,8 +1221,8 @@ get_point(double t, LVector3f &point) const {
|
|||
// point t.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool CubicCurveseg::
|
||||
get_tangent(double t, LVector3f &tangent) const {
|
||||
evaluate_vector(LVector4f(3.0*t*t, 2.0*t, 1.0, 0.0), tangent);
|
||||
get_tangent(double t, LVecBase3f &tangent) const {
|
||||
evaluate_vector(LVecBase4f(3.0*t*t, 2.0*t, 1.0, 0.0), tangent);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1224,9 +1233,9 @@ get_tangent(double t, LVector3f &tangent) const {
|
|||
// the given parametric point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool CubicCurveseg::
|
||||
get_pt(double t, LVector3f &point, LVector3f &tangent) const {
|
||||
evaluate_point(LVector4f(t*t*t, t*t, t, 1.0), point);
|
||||
evaluate_vector(LVector4f(3.0*t*t, 2.0*t, 1.0, 0.0), tangent);
|
||||
get_pt(double t, LVecBase3f &point, LVecBase3f &tangent) const {
|
||||
evaluate_point(LVecBase4f(t*t*t, t*t, t, 1.0), point);
|
||||
evaluate_vector(LVecBase4f(3.0*t*t, 2.0*t, 1.0, 0.0), tangent);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1237,8 +1246,8 @@ get_pt(double t, LVector3f &point, LVector3f &tangent) const {
|
|||
// parametric point t.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool CubicCurveseg::
|
||||
get_2ndtangent(double t, LVector3f &tangent2) const {
|
||||
evaluate_vector(LVector4f(6.0*t, 2.0, 0.0, 0.0), tangent2);
|
||||
get_2ndtangent(double t, LVecBase3f &tangent2) const {
|
||||
evaluate_vector(LVecBase4f(6.0*t, 2.0, 0.0, 0.0), tangent2);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1260,11 +1269,11 @@ hermite_basis(const HermiteCurveCV &cv0,
|
|||
1, -2, 1, 0,
|
||||
1, -1, 0, 0);
|
||||
|
||||
LVector4f Gx(cv0._p[0], cv1._p[0],
|
||||
LVecBase4f Gx(cv0._p[0], cv1._p[0],
|
||||
cv0._out[0]*tlength, cv1._in[0]*tlength);
|
||||
LVector4f Gy(cv0._p[1], cv1._p[1],
|
||||
LVecBase4f Gy(cv0._p[1], cv1._p[1],
|
||||
cv0._out[1]*tlength, cv1._in[1]*tlength);
|
||||
LVector4f Gz(cv0._p[2], cv1._p[2],
|
||||
LVecBase4f Gz(cv0._p[2], cv1._p[2],
|
||||
cv0._out[2]*tlength, cv1._in[2]*tlength);
|
||||
|
||||
Bx = Gx * Mh;
|
||||
|
|
@ -1288,9 +1297,9 @@ bezier_basis(const BezierSeg &seg) {
|
|||
-3, 3, 0, 0,
|
||||
1, 0, 0, 0);
|
||||
|
||||
LVector4f Gx(seg._v[0][0], seg._v[1][0], seg._v[2][0], seg._v[3][0]);
|
||||
LVector4f Gy(seg._v[0][1], seg._v[1][1], seg._v[2][1], seg._v[3][1]);
|
||||
LVector4f Gz(seg._v[0][2], seg._v[1][2], seg._v[2][2], seg._v[3][2]);
|
||||
LVecBase4f Gx(seg._v[0][0], seg._v[1][0], seg._v[2][0], seg._v[3][0]);
|
||||
LVecBase4f Gy(seg._v[0][1], seg._v[1][1], seg._v[2][1], seg._v[3][1]);
|
||||
LVecBase4f Gz(seg._v[0][2], seg._v[1][2], seg._v[2][2], seg._v[3][2]);
|
||||
|
||||
Bx = Gx * Mb;
|
||||
By = Gy * Mb;
|
||||
|
|
@ -1298,11 +1307,11 @@ bezier_basis(const BezierSeg &seg) {
|
|||
rational = false;
|
||||
}
|
||||
|
||||
static LVector4f
|
||||
static LVecBase4f
|
||||
nurbs_blending_function(int order, int i, int j,
|
||||
const double knots[]) {
|
||||
// This is doubly recursive. Ick.
|
||||
LVector4f r;
|
||||
LVecBase4f r;
|
||||
|
||||
if (j==1) {
|
||||
if (i==order-1 && knots[i] < knots[i+1]) {
|
||||
|
|
@ -1312,8 +1321,8 @@ nurbs_blending_function(int order, int i, int j,
|
|||
}
|
||||
|
||||
} else {
|
||||
LVector4f bi0 = nurbs_blending_function(order, i, j-1, knots);
|
||||
LVector4f bi1 = nurbs_blending_function(order, i+1, j-1, knots);
|
||||
LVecBase4f bi0 = nurbs_blending_function(order, i, j-1, knots);
|
||||
LVecBase4f bi1 = nurbs_blending_function(order, i+1, j-1, knots);
|
||||
|
||||
float d0 = knots[i+j-1] - knots[i];
|
||||
float d1 = knots[i+j] - knots[i+1];
|
||||
|
|
@ -1379,7 +1388,7 @@ compute_nurbs_basis(int order,
|
|||
}
|
||||
|
||||
|
||||
LVector4f b[4];
|
||||
LVecBase4f b[4];
|
||||
for (i = 0; i<order; i++) {
|
||||
b[i] = nurbs_blending_function(order, i, order, knots);
|
||||
}
|
||||
|
|
@ -1389,7 +1398,7 @@ compute_nurbs_basis(int order,
|
|||
}
|
||||
|
||||
for (i=order; i<4; i++) {
|
||||
basis.set_row(i, LVector4f::zero());
|
||||
basis.set_row(i, LVecBase4f::zero());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1404,7 +1413,7 @@ compute_nurbs_basis(int order,
|
|||
// array of order values.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CubicCurveseg::
|
||||
nurbs_basis(int order, const double knots[], const LVector4f cvs[]) {
|
||||
nurbs_basis(int order, const double knots[], const LVecBase4f cvs[]) {
|
||||
assert(order>=1 && order<=4);
|
||||
|
||||
LMatrix4f B;
|
||||
|
|
@ -1412,15 +1421,15 @@ nurbs_basis(int order, const double knots[], const LVector4f cvs[]) {
|
|||
|
||||
// Create a local copy of our CV's, so we can zero out the unused
|
||||
// elements.
|
||||
LVector4f c[4];
|
||||
LVecBase4f c[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
c[i] = (i<order) ? cvs[i] : LVector4f(0.0, 0.0, 0.0, 0.0);
|
||||
c[i] = (i<order) ? cvs[i] : LVecBase4f(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
Bx = LVector4f(c[0][0], c[1][0], c[2][0], c[3][0]) * B;
|
||||
By = LVector4f(c[0][1], c[1][1], c[2][1], c[3][1]) * B;
|
||||
Bz = LVector4f(c[0][2], c[1][2], c[2][2], c[3][2]) * B;
|
||||
Bw = LVector4f(c[0][3], c[1][3], c[2][3], c[3][3]) * B;
|
||||
Bx = LVecBase4f(c[0][0], c[1][0], c[2][0], c[3][0]) * B;
|
||||
By = LVecBase4f(c[0][1], c[1][1], c[2][1], c[3][1]) * B;
|
||||
Bz = LVecBase4f(c[0][2], c[1][2], c[2][2], c[3][2]) * B;
|
||||
Bw = LVecBase4f(c[0][3], c[1][3], c[2][3], c[3][3]) * B;
|
||||
|
||||
rational = true;
|
||||
}
|
||||
|
|
@ -1441,12 +1450,12 @@ GetBezierSeg(BezierSeg &seg) const {
|
|||
0.0, 1.0/3.0, 2.0/3.0, 1.0,
|
||||
1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
LVector4f Gx = Bx * Mbi;
|
||||
LVector4f Gy = By * Mbi;
|
||||
LVector4f Gz = Bz * Mbi;
|
||||
LVecBase4f Gx = Bx * Mbi;
|
||||
LVecBase4f Gy = By * Mbi;
|
||||
LVecBase4f Gz = Bz * Mbi;
|
||||
|
||||
if (rational) {
|
||||
LVector4f Gw = Bw * Mbi;
|
||||
LVecBase4f Gw = Bw * Mbi;
|
||||
seg._v[0].set(Gx[0]/Gw[0], Gy[0]/Gw[0], Gz[0]/Gw[0]);
|
||||
seg._v[1].set(Gx[1]/Gw[1], Gy[1]/Gw[1], Gz[1]/Gw[1]);
|
||||
seg._v[2].set(Gx[2]/Gw[2], Gy[2]/Gw[2], Gz[2]/Gw[2]);
|
||||
|
|
@ -1463,9 +1472,9 @@ GetBezierSeg(BezierSeg &seg) const {
|
|||
|
||||
|
||||
// We need this operator since Performer didn't supply it.
|
||||
inline LVector4f
|
||||
operator * (const LMatrix4f &M, const LVector4f &v) {
|
||||
return LVector4f(M(0,0)*v[0] + M(0,1)*v[1] + M(0,2)*v[2] + M(0,3)*v[3],
|
||||
inline LVecBase4f
|
||||
operator * (const LMatrix4f &M, const LVecBase4f &v) {
|
||||
return LVecBase4f(M(0,0)*v[0] + M(0,1)*v[1] + M(0,2)*v[2] + M(0,3)*v[3],
|
||||
M(1,0)*v[0] + M(1,1)*v[1] + M(1,2)*v[2] + M(1,3)*v[3],
|
||||
M(2,0)*v[0] + M(2,1)*v[1] + M(2,2)*v[2] + M(2,3)*v[3],
|
||||
M(3,0)*v[0] + M(3,1)*v[1] + M(3,2)*v[2] + M(3,3)*v[3]);
|
||||
|
|
@ -1479,7 +1488,7 @@ operator * (const LMatrix4f &M, const LVector4f &v) {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
static bool
|
||||
compute_seg_col(int c,
|
||||
int rtype, double t, const LVector4f &v,
|
||||
int rtype, double t, const LVecBase4f &v,
|
||||
const LMatrix4f &B,
|
||||
const LMatrix4f &Bi,
|
||||
const LMatrix4f &G,
|
||||
|
|
@ -1491,9 +1500,9 @@ compute_seg_col(int c,
|
|||
// RT_point defines the point on the curve at t. This is the vector
|
||||
// [ t^3 t^2 t^1 t^0 ].
|
||||
case RT_POINT:
|
||||
T.set_col(c, LVector4f(t*t*t, t*t, t, 1.0));
|
||||
T.set_col(c, LVecBase4f(t*t*t, t*t, t, 1.0));
|
||||
if (keep_orig) {
|
||||
LVector4f ov = GB * LVector4f(t*t*t, t*t, t, 1.0);
|
||||
LVecBase4f ov = GB * LVecBase4f(t*t*t, t*t, t, 1.0);
|
||||
|
||||
P.set_col(c, ov);
|
||||
} else {
|
||||
|
|
@ -1504,9 +1513,9 @@ compute_seg_col(int c,
|
|||
// RT_tangent defines the tangent to the curve at t. This is
|
||||
// the vector [ 3t^2 2t 1 0 ].
|
||||
case RT_TANGENT:
|
||||
T.set_col(c, LVector4f(3.0*t*t, 2.0*t, 1.0, 0.0));
|
||||
T.set_col(c, LVecBase4f(3.0*t*t, 2.0*t, 1.0, 0.0));
|
||||
if (keep_orig) {
|
||||
LVector4f ov = GB * LVector4f(3.0*t*t, 2.0*t, 1.0, 0.0);
|
||||
LVecBase4f ov = GB * LVecBase4f(3.0*t*t, 2.0*t, 1.0, 0.0);
|
||||
P.set_col(c, ov);
|
||||
} else {
|
||||
P.set_col(c, v);
|
||||
|
|
@ -1584,10 +1593,10 @@ compute_seg_col(int c,
|
|||
// sensible, or false if there is some error.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool CubicCurveseg::
|
||||
compute_seg(int rtype0, double t0, const LVector4f &v0,
|
||||
int rtype1, double t1, const LVector4f &v1,
|
||||
int rtype2, double t2, const LVector4f &v2,
|
||||
int rtype3, double t3, const LVector4f &v3,
|
||||
compute_seg(int rtype0, double t0, const LVecBase4f &v0,
|
||||
int rtype1, double t1, const LVecBase4f &v1,
|
||||
int rtype2, double t2, const LVecBase4f &v2,
|
||||
int rtype3, double t3, const LVecBase4f &v3,
|
||||
const LMatrix4f &B,
|
||||
const LMatrix4f &Bi,
|
||||
LMatrix4f &G) {
|
||||
|
|
@ -1639,12 +1648,3 @@ compute_seg(int rtype0, double t0, const LVector4f &v0,
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CubicCurveseg::Destructor
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
CubicCurveseg::
|
||||
~CubicCurveseg() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,8 +54,8 @@ BEGIN_PUBLISH //[
|
|||
END_PUBLISH //]
|
||||
|
||||
|
||||
//#define LVector3f LVector3f
|
||||
//typedef LVector3f LVector3f;
|
||||
//#define LVecBase3f LVecBase3f
|
||||
//typedef LVecBase3f LVecBase3f;
|
||||
|
||||
|
||||
// These symbols are used to define the shape of the curve segment to
|
||||
|
|
@ -84,6 +84,9 @@ class NurbsCurve;
|
|||
class EXPCL_PANDA ParametricCurve : public TypedWriteableReferenceCount,
|
||||
public Namable {
|
||||
PUBLISHED:
|
||||
ParametricCurve();
|
||||
virtual ~ParametricCurve();
|
||||
|
||||
virtual bool is_valid() const;
|
||||
|
||||
virtual double get_max_t() const;
|
||||
|
|
@ -105,22 +108,20 @@ PUBLISHED:
|
|||
void ascii_draw() const;
|
||||
|
||||
public:
|
||||
virtual bool get_point(double t, LVector3f &point) const=0;
|
||||
virtual bool get_tangent(double t, LVector3f &tangent) const=0;
|
||||
virtual bool get_pt(double t, LVector3f &point, LVector3f &tangent) const=0;
|
||||
virtual bool get_2ndtangent(double t, LVector3f &tangent2) const=0;
|
||||
virtual bool get_point(double t, LVecBase3f &point) const=0;
|
||||
virtual bool get_tangent(double t, LVecBase3f &tangent) const=0;
|
||||
virtual bool get_pt(double t, LVecBase3f &point, LVecBase3f &tangent) const=0;
|
||||
virtual bool get_2ndtangent(double t, LVecBase3f &tangent2) const=0;
|
||||
|
||||
public:
|
||||
|
||||
struct BezierSeg {
|
||||
public:
|
||||
LVector3f _v[4];
|
||||
LVecBase3f _v[4];
|
||||
double _t;
|
||||
};
|
||||
typedef vector<BezierSeg> BezierSegs;
|
||||
|
||||
ParametricCurve();
|
||||
|
||||
virtual void write_datagram(BamWriter *, Datagram &);
|
||||
|
||||
virtual bool GetBezierSegs(BezierSegs &) const {
|
||||
|
|
@ -135,13 +136,11 @@ public:
|
|||
void unregister_drawer(ParametricCurveDrawer *drawer);
|
||||
|
||||
protected:
|
||||
virtual ~ParametricCurve();
|
||||
|
||||
void invalidate(double t1, double t2);
|
||||
void invalidate_all();
|
||||
|
||||
float r_calc_length(double t1, double t2,
|
||||
const LVector3f &p1, const LVector3f &p2,
|
||||
const LPoint3f &p1, const LPoint3f &p2,
|
||||
float seglength) const;
|
||||
|
||||
typedef list< ParametricCurveDrawer * > DrawerList;
|
||||
|
|
@ -155,7 +154,11 @@ public:
|
|||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
register_type(_type_handle, "ParametricCurve");
|
||||
TypedWriteableReferenceCount::init_type();
|
||||
Namable::init_type();
|
||||
register_type(_type_handle, "ParametricCurve",
|
||||
TypedWriteableReferenceCount::get_class_type(),
|
||||
Namable::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
|
|
@ -176,13 +179,16 @@ private:
|
|||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA PiecewiseCurve : public ParametricCurve {
|
||||
PUBLISHED:
|
||||
PiecewiseCurve();
|
||||
~PiecewiseCurve();
|
||||
|
||||
virtual bool is_valid() const;
|
||||
virtual double get_max_t() const;
|
||||
|
||||
virtual bool get_point(double t, LVector3f &point) const;
|
||||
virtual bool get_tangent(double t, LVector3f &tangent) const;
|
||||
virtual bool get_pt(double t, LVector3f &point, LVector3f &tangent) const;
|
||||
virtual bool get_2ndtangent(double t, LVector3f &tangent2) const;
|
||||
virtual bool get_point(double t, LVecBase3f &point) const;
|
||||
virtual bool get_tangent(double t, LVecBase3f &tangent) const;
|
||||
virtual bool get_pt(double t, LVecBase3f &point, LVecBase3f &tangent) const;
|
||||
virtual bool get_2ndtangent(double t, LVecBase3f &tangent2) const;
|
||||
|
||||
bool adjust_point(double t,
|
||||
float px, float py, float pz);
|
||||
|
|
@ -193,8 +199,6 @@ PUBLISHED:
|
|||
float tx, float ty, float tz);
|
||||
|
||||
public:
|
||||
PiecewiseCurve();
|
||||
|
||||
int get_num_segs() const;
|
||||
|
||||
ParametricCurve *get_curveseg(int ti);
|
||||
|
|
@ -209,19 +213,17 @@ public:
|
|||
bool set_tlength(int ti, double tlength);
|
||||
|
||||
void make_nurbs(int order, int num_cvs,
|
||||
const double knots[], const LVector4f cvs[]);
|
||||
const double knots[], const LVecBase4f cvs[]);
|
||||
|
||||
virtual bool GetBezierSegs(BezierSegs &bz_segs) const;
|
||||
|
||||
virtual bool
|
||||
rebuild_curveseg(int rtype0, double t0, const LVector4f &v0,
|
||||
int rtype1, double t1, const LVector4f &v1,
|
||||
int rtype2, double t2, const LVector4f &v2,
|
||||
int rtype3, double t3, const LVector4f &v3);
|
||||
rebuild_curveseg(int rtype0, double t0, const LVecBase4f &v0,
|
||||
int rtype1, double t1, const LVecBase4f &v1,
|
||||
int rtype2, double t2, const LVecBase4f &v2,
|
||||
int rtype3, double t3, const LVecBase4f &v3);
|
||||
|
||||
protected:
|
||||
~PiecewiseCurve();
|
||||
|
||||
bool find_curve(const ParametricCurve *&curve, double &t) const;
|
||||
double current_seg_range(double t) const;
|
||||
|
||||
|
|
@ -289,22 +291,24 @@ private:
|
|||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA CubicCurveseg : public ParametricCurve {
|
||||
PUBLISHED:
|
||||
virtual bool get_point(double t, LVector3f &point) const;
|
||||
virtual bool get_tangent(double t, LVector3f &tangent) const;
|
||||
virtual bool get_pt(double t, LVector3f &point, LVector3f &tangent) const;
|
||||
virtual bool get_2ndtangent(double t, LVector3f &tangent2) const;
|
||||
virtual bool get_point(double t, LVecBase3f &point) const;
|
||||
virtual bool get_tangent(double t, LVecBase3f &tangent) const;
|
||||
virtual bool get_pt(double t, LVecBase3f &point, LVecBase3f &tangent) const;
|
||||
virtual bool get_2ndtangent(double t, LVecBase3f &tangent2) const;
|
||||
|
||||
public:
|
||||
CubicCurveseg();
|
||||
CubicCurveseg(const LMatrix4f &basis);
|
||||
CubicCurveseg(const BezierSeg &seg);
|
||||
CubicCurveseg(int order, const double knots[], const LVector4f cvs[]);
|
||||
CubicCurveseg(int order, const double knots[], const LVecBase4f cvs[]);
|
||||
|
||||
virtual ~CubicCurveseg();
|
||||
|
||||
void hermite_basis(const HermiteCurveCV &cv0,
|
||||
const HermiteCurveCV &cv1,
|
||||
double tlength = 1.0);
|
||||
void bezier_basis(const BezierSeg &seg);
|
||||
void nurbs_basis(int order, const double knots[], const LVector4f cvs[]);
|
||||
void nurbs_basis(int order, const double knots[], const LVecBase4f cvs[]);
|
||||
|
||||
// evaluate_point() and evaluate_vector() both evaluate the curve at
|
||||
// a given point by applying the basis vector against the vector
|
||||
|
|
@ -317,14 +321,14 @@ public:
|
|||
// points, and will never scale by the homogeneous coordinate (which
|
||||
// would be zero anyway).
|
||||
|
||||
void evaluate_point(const LVector4f &tv, LVector3f &result) const {
|
||||
void evaluate_point(const LVecBase4f &tv, LVecBase3f &result) const {
|
||||
double h = (rational) ? tv.dot(Bw) : 1.0;
|
||||
result.set(tv.dot(Bx) / h,
|
||||
tv.dot(By) / h,
|
||||
tv.dot(Bz) / h);
|
||||
}
|
||||
|
||||
void evaluate_vector(const LVector4f &tv, LVector3f &result) const {
|
||||
void evaluate_vector(const LVecBase4f &tv, LVecBase3f &result) const {
|
||||
result.set(tv.dot(Bx),
|
||||
tv.dot(By),
|
||||
tv.dot(Bz));
|
||||
|
|
@ -332,21 +336,17 @@ public:
|
|||
|
||||
virtual bool GetBezierSeg(BezierSeg &seg) const;
|
||||
|
||||
static bool compute_seg(int rtype0, double t0, const LVector4f &v0,
|
||||
int rtype1, double t1, const LVector4f &v1,
|
||||
int rtype2, double t2, const LVector4f &v2,
|
||||
int rtype3, double t3, const LVector4f &v3,
|
||||
static bool compute_seg(int rtype0, double t0, const LVecBase4f &v0,
|
||||
int rtype1, double t1, const LVecBase4f &v1,
|
||||
int rtype2, double t2, const LVecBase4f &v2,
|
||||
int rtype3, double t3, const LVecBase4f &v3,
|
||||
const LMatrix4f &B,
|
||||
const LMatrix4f &Bi,
|
||||
LMatrix4f &G);
|
||||
|
||||
LVector4f Bx, By, Bz, Bw;
|
||||
LVecBase4f Bx, By, Bz, Bw;
|
||||
bool rational;
|
||||
|
||||
protected:
|
||||
virtual ~CubicCurveseg();
|
||||
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
|
|
|
|||
|
|
@ -298,11 +298,11 @@ draw() {
|
|||
}
|
||||
|
||||
// Otherwise, let's go to town!
|
||||
int total_segs = floor(_curve->get_max_t() * _num_segs + 0.5);
|
||||
int total_segs = (int)floor(_curve->get_max_t() * _num_segs + 0.5);
|
||||
|
||||
double scale = _curve->get_max_t() / (double)(total_segs-1);
|
||||
double t;
|
||||
LVector3f point, tangent;
|
||||
LVecBase3f point, tangent;
|
||||
bool last_in, next_in;
|
||||
|
||||
last_in = false;
|
||||
|
|
@ -316,7 +316,7 @@ draw() {
|
|||
|
||||
next_in = _curve->get_pt(t, point, tangent);
|
||||
|
||||
LVector3f p = _mapper(point, tangent, t);
|
||||
LVecBase3f p = _mapper(point, tangent, t);
|
||||
|
||||
if (!next_in || !last_in) {
|
||||
_lines.move_to(p);
|
||||
|
|
@ -331,8 +331,8 @@ draw() {
|
|||
|
||||
// Now draw the time tick marks.
|
||||
if (_num_ticks > 0) {
|
||||
LVector3f tangent2;
|
||||
int total_ticks = floor(_curve->get_max_t() * _num_ticks + 0.5);
|
||||
LVecBase3f tangent2;
|
||||
int total_ticks = (int)floor(_curve->get_max_t() * _num_ticks + 0.5);
|
||||
|
||||
scale = get_max_t() / (double)(total_ticks-1);
|
||||
for (i = 0; i<total_ticks; i++) {
|
||||
|
|
@ -345,8 +345,8 @@ draw() {
|
|||
_curve->get_pt(t, point, tangent);
|
||||
_curve->get_2ndtangent(t, tangent2);
|
||||
|
||||
LVector3f pt = _mapper(point, tangent, t);
|
||||
LVector3f t1, t2;
|
||||
LVecBase3f pt = _mapper(point, tangent, t);
|
||||
LVecBase3f t1, t2;
|
||||
get_tick_marks(_mapper(tangent, tangent2, t + 1.0), t1, t2);
|
||||
|
||||
_ticks.move_to(pt - t1 * _tick_scale);
|
||||
|
|
@ -397,13 +397,13 @@ recompute(double t1, double t2, ParametricCurve *curve) {
|
|||
|
||||
int n1, n2, i;
|
||||
double scale, t;
|
||||
LVector3f point, tangent;
|
||||
LVecBase3f point, tangent;
|
||||
|
||||
if (redraw_curve) {
|
||||
// Compute the number of total segments we will draw. This is based
|
||||
// on the parametric length of the curve, _curve->get_max_t().
|
||||
|
||||
int total_segs = floor(_curve->get_max_t() * _num_segs + 0.5);
|
||||
int total_segs = (int)floor(_curve->get_max_t() * _num_segs + 0.5);
|
||||
|
||||
n1 = (int)floor(t1 * (total_segs-1));
|
||||
n2 = (int)ceil(t2 * (total_segs-1));
|
||||
|
|
@ -419,14 +419,14 @@ recompute(double t1, double t2, ParametricCurve *curve) {
|
|||
|
||||
_curve->get_pt(t, point, tangent);
|
||||
|
||||
LVector3f p = _mapper(point, tangent, t);
|
||||
LVecBase3f p = _mapper(point, tangent, t);
|
||||
_lines.set_vertex(i, p);
|
||||
}
|
||||
}
|
||||
|
||||
if (_num_ticks > 0) {
|
||||
LVector3f tangent2;
|
||||
int total_ticks = floor(_curve->get_max_t() * _num_ticks + 0.5);
|
||||
LVecBase3f tangent2;
|
||||
int total_ticks = (int)floor(_curve->get_max_t() * _num_ticks + 0.5);
|
||||
|
||||
n1 = (int)floor(t1 * (total_ticks-1));
|
||||
n2 = (int)ceil(t2 * (total_ticks-1));
|
||||
|
|
@ -442,8 +442,8 @@ recompute(double t1, double t2, ParametricCurve *curve) {
|
|||
_curve->get_pt(t, point, tangent);
|
||||
_curve->get_2ndtangent(t, tangent2);
|
||||
|
||||
LVector3f pt = _mapper(point, tangent, t);
|
||||
LVector3f t1, t2;
|
||||
LVecBase3f pt = _mapper(point, tangent, t);
|
||||
LVecBase3f t1, t2;
|
||||
get_tick_marks(_mapper(tangent, tangent2, t + 1.0),
|
||||
t1, t2);
|
||||
|
||||
|
|
@ -583,7 +583,7 @@ disable(ParametricCurve *curve) {
|
|||
// it to a three-dimensional representation.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ParametricCurveDrawer::
|
||||
set_mapper(LVector3fMapper *mapper) {
|
||||
set_mapper(LVecBase3fMapper *mapper) {
|
||||
// If the mapper hasn't changed, don't force a redraw.
|
||||
if (_mapper != mapper) {
|
||||
_mapper = mapper;
|
||||
|
|
@ -601,9 +601,9 @@ set_mapper(LVector3fMapper *mapper) {
|
|||
// each point, showing the line's three-dimensional
|
||||
// shape.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
LVector3f ParametricCurveDrawer::
|
||||
DefaultMap(const LVector3f &point, const LVector3f &, double) {
|
||||
return LVector3f(point[0], point[1], point[2]);
|
||||
LVecBase3f ParametricCurveDrawer::
|
||||
DefaultMap(const LVecBase3f &point, const LVecBase3f &, double) {
|
||||
return LVecBase3f(point[0], point[1], point[2]);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -613,9 +613,9 @@ DefaultMap(const LVector3f &point, const LVector3f &, double) {
|
|||
// Description: This mapping function shows a graph of X(t), with the
|
||||
// x along the Y axis and t along the X axis.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
LVector3f ParametricCurveDrawer::
|
||||
XvsT(const LVector3f &point, const LVector3f &, double t) {
|
||||
return LVector3f(t, point[0], 0.0);
|
||||
LVecBase3f ParametricCurveDrawer::
|
||||
XvsT(const LVecBase3f &point, const LVecBase3f &, double t) {
|
||||
return LVecBase3f(t, point[0], 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -624,9 +624,9 @@ XvsT(const LVector3f &point, const LVector3f &, double t) {
|
|||
// Description: This mapping function shows a graph of X(t), with the
|
||||
// x along the X axis and t along the Y axis.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
LVector3f ParametricCurveDrawer::
|
||||
iXvsT(const LVector3f &point, const LVector3f &, double t) {
|
||||
return LVector3f(point[0], t, 0.0);
|
||||
LVecBase3f ParametricCurveDrawer::
|
||||
iXvsT(const LVecBase3f &point, const LVecBase3f &, double t) {
|
||||
return LVecBase3f(point[0], t, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -635,9 +635,9 @@ iXvsT(const LVector3f &point, const LVector3f &, double t) {
|
|||
// Description: This mapping function shows a graph of Y(t), with the
|
||||
// y along the Y axis and t along the X axis.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
LVector3f ParametricCurveDrawer::
|
||||
YvsT(const LVector3f &point, const LVector3f &, double t) {
|
||||
return LVector3f(t, point[1], 0.0);
|
||||
LVecBase3f ParametricCurveDrawer::
|
||||
YvsT(const LVecBase3f &point, const LVecBase3f &, double t) {
|
||||
return LVecBase3f(t, point[1], 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -646,9 +646,9 @@ YvsT(const LVector3f &point, const LVector3f &, double t) {
|
|||
// Description: This mapping function shows a graph of Y(t), with the
|
||||
// y along the X axis and t along the Y axis.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
LVector3f ParametricCurveDrawer::
|
||||
iYvsT(const LVector3f &point, const LVector3f &, double t) {
|
||||
return LVector3f(point[1], t, 0.0);
|
||||
LVecBase3f ParametricCurveDrawer::
|
||||
iYvsT(const LVecBase3f &point, const LVecBase3f &, double t) {
|
||||
return LVecBase3f(point[1], t, 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -657,9 +657,9 @@ iYvsT(const LVector3f &point, const LVector3f &, double t) {
|
|||
// Description: This mapping function shows a graph of Z(t), with the
|
||||
// z along the Y axis and t along the X axis.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
LVector3f ParametricCurveDrawer::
|
||||
ZvsT(const LVector3f &point, const LVector3f &, double t) {
|
||||
return LVector3f(t, point[2], 0.0);
|
||||
LVecBase3f ParametricCurveDrawer::
|
||||
ZvsT(const LVecBase3f &point, const LVecBase3f &, double t) {
|
||||
return LVecBase3f(t, point[2], 0.0);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -669,9 +669,9 @@ ZvsT(const LVector3f &point, const LVector3f &, double t) {
|
|||
// Description: This mapping function shows a graph of dX(t), the
|
||||
// derivative of X(t).
|
||||
////////////////////////////////////////////////////////////////////
|
||||
LVector3f ParametricCurveDrawer::
|
||||
dXvsT(const LVector3f &, const LVector3f &tangent, double t) {
|
||||
return LVector3f(t, tangent[0], 0.0);
|
||||
LVecBase3f ParametricCurveDrawer::
|
||||
dXvsT(const LVecBase3f &, const LVecBase3f &tangent, double t) {
|
||||
return LVecBase3f(t, tangent[0], 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -680,9 +680,9 @@ dXvsT(const LVector3f &, const LVector3f &tangent, double t) {
|
|||
// Description: This mapping function shows a graph of dY(t), the
|
||||
// derivative of Y(t).
|
||||
////////////////////////////////////////////////////////////////////
|
||||
LVector3f ParametricCurveDrawer::
|
||||
dYvsT(const LVector3f &, const LVector3f &tangent, double t) {
|
||||
return LVector3f(t, tangent[1], 0.0);
|
||||
LVecBase3f ParametricCurveDrawer::
|
||||
dYvsT(const LVecBase3f &, const LVecBase3f &tangent, double t) {
|
||||
return LVecBase3f(t, tangent[1], 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -691,9 +691,9 @@ dYvsT(const LVector3f &, const LVector3f &tangent, double t) {
|
|||
// Description: This mapping function shows a graph of dZ(t), the
|
||||
// derivative of Z(t).
|
||||
////////////////////////////////////////////////////////////////////
|
||||
LVector3f ParametricCurveDrawer::
|
||||
dZvsT(const LVector3f &, const LVector3f &tangent, double t) {
|
||||
return LVector3f(t, tangent[2], 0.0);
|
||||
LVecBase3f ParametricCurveDrawer::
|
||||
dZvsT(const LVecBase3f &, const LVecBase3f &tangent, double t) {
|
||||
return LVecBase3f(t, tangent[2], 0.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -704,7 +704,7 @@ dZvsT(const LVector3f &, const LVector3f &tangent, double t) {
|
|||
// drawing as tick marks.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ParametricCurveDrawer::
|
||||
get_tick_marks(const LVector3f &tangent, LVector3f &t1, LVector3f &t2) {
|
||||
get_tick_marks(const LVecBase3f &tangent, LVecBase3f &t1, LVecBase3f &t2) {
|
||||
LVector3f tn = tangent;
|
||||
tn.normalize();
|
||||
|
||||
|
|
|
|||
|
|
@ -22,12 +22,14 @@
|
|||
#include "curve.h"
|
||||
#include "lineSegs.h"
|
||||
|
||||
#include <typeHandle.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Defines
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef LVector3f LVector3fMapper(const LVector3f &point,
|
||||
const LVector3f &tangent,
|
||||
typedef LVecBase3f LVecBase3fMapper(const LVecBase3f &point,
|
||||
const LVecBase3f &tangent,
|
||||
double t);
|
||||
|
||||
BEGIN_PUBLISH //[
|
||||
|
|
@ -50,7 +52,7 @@ class ParametricSurface;
|
|||
// Description : Draws a 3-d parametric curve in the scene by creating
|
||||
// a series of line segments to approximate the curve.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA ParametricCurveDrawer {
|
||||
class EXPCL_PANDA ParametricCurveDrawer : public TypedObject {
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Member functions visible to Scheme
|
||||
|
|
@ -101,20 +103,20 @@ public:
|
|||
|
||||
void disable(ParametricCurve *curve);
|
||||
|
||||
void set_mapper(LVector3fMapper *mapper);
|
||||
void set_mapper(LVecBase3fMapper *mapper);
|
||||
|
||||
static LVector3f DefaultMap(const LVector3f &point, const LVector3f &, double);
|
||||
static LVector3f XvsT(const LVector3f &point, const LVector3f &, double t);
|
||||
static LVector3f iXvsT(const LVector3f &point, const LVector3f &, double t);
|
||||
static LVector3f YvsT(const LVector3f &point, const LVector3f &, double t);
|
||||
static LVector3f iYvsT(const LVector3f &point, const LVector3f &, double t);
|
||||
static LVector3f ZvsT(const LVector3f &point, const LVector3f &, double t);
|
||||
static LVector3f dXvsT(const LVector3f &, const LVector3f &tangent, double t);
|
||||
static LVector3f dYvsT(const LVector3f &, const LVector3f &tangent, double t);
|
||||
static LVector3f dZvsT(const LVector3f &, const LVector3f &tangent, double t);
|
||||
static LVecBase3f DefaultMap(const LVecBase3f &point, const LVecBase3f &, double);
|
||||
static LVecBase3f XvsT(const LVecBase3f &point, const LVecBase3f &, double t);
|
||||
static LVecBase3f iXvsT(const LVecBase3f &point, const LVecBase3f &, double t);
|
||||
static LVecBase3f YvsT(const LVecBase3f &point, const LVecBase3f &, double t);
|
||||
static LVecBase3f iYvsT(const LVecBase3f &point, const LVecBase3f &, double t);
|
||||
static LVecBase3f ZvsT(const LVecBase3f &point, const LVecBase3f &, double t);
|
||||
static LVecBase3f dXvsT(const LVecBase3f &, const LVecBase3f &tangent, double t);
|
||||
static LVecBase3f dYvsT(const LVecBase3f &, const LVecBase3f &tangent, double t);
|
||||
static LVecBase3f dZvsT(const LVecBase3f &, const LVecBase3f &tangent, double t);
|
||||
|
||||
protected:
|
||||
static void get_tick_marks(const LVector3f &tangent, LVector3f &t1, LVector3f &t2);
|
||||
static void get_tick_marks(const LVecBase3f &tangent, LVecBase3f &t1, LVecBase3f &t2);
|
||||
|
||||
PT(GeomNode) _geom_node;
|
||||
int _num_segs;
|
||||
|
|
@ -124,7 +126,7 @@ protected:
|
|||
int _num_ticks;
|
||||
double _tick_scale;
|
||||
bool _frame_accurate;
|
||||
LVector3fMapper *_mapper;
|
||||
LVecBase3fMapper *_mapper;
|
||||
|
||||
|
||||
public:
|
||||
|
|
@ -132,7 +134,8 @@ public:
|
|||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
register_type(_type_handle, "ParametricCurveDrawer");
|
||||
register_type(_type_handle, "ParametricCurveDrawer",
|
||||
TypedObject::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
|
|
|
|||
|
|
@ -23,6 +23,24 @@
|
|||
|
||||
TypeHandle CurveFitter::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CurveFitter::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
CurveFitter::
|
||||
CurveFitter() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CurveFitter::Destructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
CurveFitter::
|
||||
~CurveFitter() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CurveFitter::reset
|
||||
// Access: Public
|
||||
|
|
@ -40,7 +58,7 @@ reset() {
|
|||
// Description: Adds a single sample point.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CurveFitter::
|
||||
add_point(double t, const LVector3f &point) {
|
||||
add_point(double t, const LVecBase3f &point) {
|
||||
DataPoint dp;
|
||||
dp._t = t;
|
||||
dp._point = point;
|
||||
|
|
@ -117,8 +135,8 @@ generate_even(int count, double net_distance, double net_time) {
|
|||
void CurveFitter::
|
||||
wrap_hpr() {
|
||||
Data::iterator di;
|
||||
LVector3f last(0.0, 0.0, 0.0);
|
||||
LVector3f net(0.0, 0.0, 0.0);
|
||||
LVecBase3f last(0.0, 0.0, 0.0);
|
||||
LVecBase3f net(0.0, 0.0, 0.0);
|
||||
|
||||
for (di = _data.begin(); di != _data.end(); ++di) {
|
||||
int i;
|
||||
|
|
@ -167,14 +185,14 @@ compute_timewarp(const ParametricCurve *xyz) {
|
|||
/*
|
||||
// Special HPR computation
|
||||
{
|
||||
LVector3f tangent;
|
||||
LVecBase3f tangent;
|
||||
LMatrix4f mat;
|
||||
pfCoord c;
|
||||
static double last_h = 0.0;
|
||||
static double h_net = 0.0;
|
||||
|
||||
xyz->get_tangent(t, tangent);
|
||||
look_at(mat, tangent, LVector3f(0.0, 0.0, 1.0));
|
||||
look_at(mat, tangent, LVecBase3f(0.0, 0.0, 1.0));
|
||||
mat.getOrthoCoord(&c);
|
||||
cerr << "Replacing R " << c.hpr[2] << " with " << (*di)._point[1] << "\n";
|
||||
c.hpr[2] = (*di)._point[1];
|
||||
|
|
@ -232,7 +250,7 @@ desample(double factor) {
|
|||
double count = factor;
|
||||
|
||||
out = 0;
|
||||
for (in = 0; in < _data.size()-1; in++) {
|
||||
for (in = 0; in < (int)_data.size()-1; in++) {
|
||||
if (count >= factor) {
|
||||
_data[out] = _data[in];
|
||||
out++;
|
||||
|
|
@ -296,9 +314,9 @@ compute_tangents(double scale) {
|
|||
// Description: Converts the current set of data points into a
|
||||
// Hermite curve.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
HermiteCurve *CurveFitter::
|
||||
PT(HermiteCurve) CurveFitter::
|
||||
make_hermite() const {
|
||||
HermiteCurve *hc = new HermiteCurve;
|
||||
PT(HermiteCurve) hc = new HermiteCurve;
|
||||
|
||||
Data::const_iterator di;
|
||||
for (di = _data.begin(); di != _data.end(); ++di) {
|
||||
|
|
@ -319,30 +337,30 @@ make_hermite() const {
|
|||
// NURBS curve. This gives a smoother curve than
|
||||
// produced by MakeHermite().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
NurbsCurve *CurveFitter::
|
||||
PT(NurbsCurve) CurveFitter::
|
||||
make_nurbs() const {
|
||||
if (_data.size() < 2) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
NurbsCurve *nc = new NurbsCurve;
|
||||
PT(NurbsCurve) nc = new NurbsCurve;
|
||||
nc->set_order(4);
|
||||
|
||||
// First, we need four CV's to get started.
|
||||
nc->append_cv(LVector3f(0.0, 0.0, 0.0));
|
||||
nc->append_cv(LVector3f(0.0, 0.0, 0.0));
|
||||
nc->append_cv(LVector3f(0.0, 0.0, 0.0));
|
||||
nc->append_cv(LVector3f(0.0, 0.0, 0.0));
|
||||
nc->append_cv(LVecBase3f(0.0, 0.0, 0.0));
|
||||
nc->append_cv(LVecBase3f(0.0, 0.0, 0.0));
|
||||
nc->append_cv(LVecBase3f(0.0, 0.0, 0.0));
|
||||
nc->append_cv(LVecBase3f(0.0, 0.0, 0.0));
|
||||
nc->set_knot(4, _data[1]._t);
|
||||
|
||||
nc->recompute();
|
||||
LVector3f junk;
|
||||
LVecBase3f junk;
|
||||
nc->get_point(nc->get_max_t(), junk); // Reference the last segment.
|
||||
const LVector3f &p0 = _data[0]._point;
|
||||
LVector3f t0 = _data[0]._tangent * 2.0;
|
||||
LVector3f t1 = _data[1]._tangent * 2.0;
|
||||
const LVector3f &p1 = _data[1]._point;
|
||||
const LVecBase3f &p0 = _data[0]._point;
|
||||
LVecBase3f t0 = _data[0]._tangent * 2.0;
|
||||
LVecBase3f t1 = _data[1]._tangent * 2.0;
|
||||
const LVecBase3f &p1 = _data[1]._point;
|
||||
|
||||
nc->rebuild_curveseg(RT_POINT, 0.0, pfVec4(p0[0], p0[1], p0[2], 1.0),
|
||||
RT_TANGENT, 0.0, pfVec4(t0[0], t0[1], t0[2], 0.0),
|
||||
|
|
@ -352,16 +370,16 @@ make_nurbs() const {
|
|||
int i;
|
||||
for (i = 2; i < _data.size(); i++) {
|
||||
cerr << "Adding point " << i << "\n";
|
||||
nc->append_cv(LVector3f(0.0, 0.0, 0.0));
|
||||
nc->append_cv(LVecBase3f(0.0, 0.0, 0.0));
|
||||
nc->set_knot(i + 3, _data[i]._t);
|
||||
nc->recompute();
|
||||
nc->get_point(nc->get_max_t(), junk);
|
||||
|
||||
/*
|
||||
const LVector3f &p0 = _data[i-1]._point;
|
||||
const LVector3f &t0 = _data[i-1]._tangent;
|
||||
const LVector3f &p1 = _data[i]._point;
|
||||
const LVector3f &t1 = _data[i]._tangent;
|
||||
const LVecBase3f &p0 = _data[i-1]._point;
|
||||
const LVecBase3f &t0 = _data[i-1]._tangent;
|
||||
const LVecBase3f &p1 = _data[i]._point;
|
||||
const LVecBase3f &t1 = _data[i]._tangent;
|
||||
|
||||
nc->rebuild_curveseg(RT_POINT, 0.0, pfVec4(p0[0], p0[1], p0[2], 1.0),
|
||||
RT_TANGENT, 0.0, pfVec4(t0[0], t0[1], t0[2], 0.0),
|
||||
|
|
@ -369,7 +387,7 @@ make_nurbs() const {
|
|||
RT_POINT, 1.0, pfVec4(p1[0], p1[1], p1[2], 1.0));
|
||||
*/
|
||||
|
||||
const LVector3f &pi = _data[i]._point;
|
||||
const LVecBase3f &pi = _data[i]._point;
|
||||
nc->rebuild_curveseg(RT_CV | RT_KEEP_ORIG, 0.0, pfVec4(),
|
||||
RT_CV | RT_KEEP_ORIG, 0.0, pfVec4(),
|
||||
RT_CV | RT_KEEP_ORIG, 0.0, pfVec4(),
|
||||
|
|
@ -377,10 +395,10 @@ make_nurbs() const {
|
|||
}
|
||||
|
||||
/*
|
||||
nc->append_cv(LVector3f(0.0, 0.0, 0.0));
|
||||
nc->append_cv(LVecBase3f(0.0, 0.0, 0.0));
|
||||
nc->recompute();
|
||||
nc->get_point(nc->get_max_t(), junk);
|
||||
const LVector3f &pi = _data[_data.size()-1]._point;
|
||||
const LVecBase3f &pi = _data[_data.size()-1]._point;
|
||||
nc->rebuild_curveseg(RT_CV | RT_KEEP_ORIG, 0.0, pfVec4(),
|
||||
RT_CV | RT_KEEP_ORIG, 0.0, pfVec4(),
|
||||
RT_CV | RT_KEEP_ORIG, 0.0, pfVec4(),
|
||||
|
|
@ -394,8 +412,8 @@ make_nurbs() const {
|
|||
|
||||
// We start with the HermiteCurve produced above, then convert it to
|
||||
// NURBS form.
|
||||
PT(HermiteCurve) hc = new HermiteCurve();
|
||||
NurbsCurve *nc = new NurbsCurve(*hc);
|
||||
PT(HermiteCurve) hc = make_hermite();
|
||||
PT(NurbsCurve) nc = new NurbsCurve(*hc);
|
||||
|
||||
// Now we even out the knots to smooth out the curve and make
|
||||
// everything c2 continuous.
|
||||
|
|
|
|||
|
|
@ -30,8 +30,11 @@ class ParametricCurve;
|
|||
////////////////////////////////////////////////////////////////////
|
||||
class CurveFitter {
|
||||
PUBLISHED:
|
||||
CurveFitter();
|
||||
~CurveFitter();
|
||||
|
||||
void reset();
|
||||
void add_point(double t, const LVector3f &point);
|
||||
void add_point(double t, const LVecBase3f &point);
|
||||
|
||||
void sample(ParametricCurve *curve, int count, bool even);
|
||||
void generate_even(int count, double net_distance, double net_time);
|
||||
|
|
@ -42,8 +45,8 @@ PUBLISHED:
|
|||
void desample(double factor);
|
||||
|
||||
void compute_tangents(double scale);
|
||||
HermiteCurve *make_hermite() const;
|
||||
NurbsCurve *make_nurbs() const;
|
||||
PT(HermiteCurve) make_hermite() const;
|
||||
PT(NurbsCurve) make_nurbs() const;
|
||||
|
||||
void print() const;
|
||||
|
||||
|
|
@ -62,8 +65,8 @@ public:
|
|||
}
|
||||
|
||||
double _t;
|
||||
LVector3f _point;
|
||||
LVector3f _tangent;
|
||||
LVecBase3f _point;
|
||||
LVecBase3f _tangent;
|
||||
};
|
||||
|
||||
typedef vector<DataPoint> Data;
|
||||
|
|
@ -76,10 +79,6 @@ public:
|
|||
static void init_type() {
|
||||
register_type(_type_handle, "CurveFitter");
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
}
|
||||
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
TypeHandle HermiteCurve::_type_handle;
|
||||
|
||||
static const LVector3f zero = LVector3f(0.0, 0.0, 0.0);
|
||||
static const LVecBase3f zero = LVecBase3f(0.0, 0.0, 0.0);
|
||||
// This is returned occasionally from some of the functions, and is
|
||||
// used from time to time as an initializer.
|
||||
|
||||
|
|
@ -49,11 +49,11 @@ Indent(ostream &out, int indent) {
|
|||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: show_vec3
|
||||
// Description: This function writes a LVector3f, with a specified
|
||||
// Description: This function writes a LVecBase3f, with a specified
|
||||
// number of significant dimensions.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
static ostream &
|
||||
show_vec3(ostream &out, int indent, const LVector3f &v, int num_dimensions) {
|
||||
show_vec3(ostream &out, int indent, const LVecBase3f &v, int num_dimensions) {
|
||||
Indent(out, indent) << v[0];
|
||||
for (int i = 1; i<num_dimensions; i++) {
|
||||
out << " " << v[i];
|
||||
|
|
@ -110,7 +110,7 @@ HermiteCurveCV::
|
|||
// Description: Sets the CV's in tangent.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void HermiteCurveCV::
|
||||
set_in(const LVector3f &in) {
|
||||
set_in(const LVecBase3f &in) {
|
||||
_in = in;
|
||||
/*
|
||||
double l;
|
||||
|
|
@ -136,7 +136,7 @@ set_in(const LVector3f &in) {
|
|||
// Description: Sets the CV's out tangent.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void HermiteCurveCV::
|
||||
set_out(const LVector3f &out) {
|
||||
set_out(const LVecBase3f &out) {
|
||||
_out = out;
|
||||
/*
|
||||
double l;
|
||||
|
|
@ -279,6 +279,15 @@ HermiteCurve(const ParametricCurve &nc) {
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: HermiteCurve::Destructor
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
HermiteCurve::
|
||||
~HermiteCurve() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -325,7 +334,7 @@ insert_cv(double t) {
|
|||
nassertr(n+1<get_num_cvs(), 0);
|
||||
|
||||
HermiteCurveCV cv;
|
||||
LVector3f tan;
|
||||
LVecBase3f tan;
|
||||
cv._type = HC_SMOOTH;
|
||||
get_pt(t, cv._p, tan);
|
||||
cv._out = cv._in = tan / 2.0;
|
||||
|
|
@ -353,7 +362,7 @@ int HermiteCurve::
|
|||
append_cv(int type, float x, float y, float z) {
|
||||
HermiteCurveCV cv;
|
||||
cv.set_type(type);
|
||||
cv.set_point(LVector3f(x, y, z));
|
||||
cv.set_point(LVecBase3f(x, y, z));
|
||||
cv.set_in(zero);
|
||||
cv.set_out(zero);
|
||||
_points.push_back(cv);
|
||||
|
|
@ -378,7 +387,7 @@ append_cv(int type, float x, float y, float z) {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
bool HermiteCurve::
|
||||
remove_cv(int n) {
|
||||
if (n<0 || n>=_points.size()) {
|
||||
if (n < 0 || n >= (int)_points.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -428,7 +437,7 @@ remove_all_cvs() {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
bool HermiteCurve::
|
||||
set_cv_type(int n, int type) {
|
||||
if (n<0 || n>=_points.size()) {
|
||||
if (n < 0 || n >= (int)_points.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -451,10 +460,10 @@ set_cv_type(int n, int type) {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
bool HermiteCurve::
|
||||
set_cv_point(int n, float x, float y, float z) {
|
||||
if (n<0 || n>=_points.size()) {
|
||||
if (n < 0 || n >= (int)_points.size()) {
|
||||
return false;
|
||||
}
|
||||
_points[n].set_point(LVector3f(x, y, z));
|
||||
_points[n].set_point(LVecBase3f(x, y, z));
|
||||
invalidate_cv(n, false);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -468,10 +477,10 @@ set_cv_point(int n, float x, float y, float z) {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
bool HermiteCurve::
|
||||
set_cv_in(int n, float x, float y, float z) {
|
||||
if (n<0 || n>=_points.size()) {
|
||||
if (n < 0 || n >= (int)_points.size()) {
|
||||
return false;
|
||||
}
|
||||
_points[n].set_in(LVector3f(x, y, z));
|
||||
_points[n].set_in(LVecBase3f(x, y, z));
|
||||
invalidate_cv(n, false);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -485,10 +494,10 @@ set_cv_in(int n, float x, float y, float z) {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
bool HermiteCurve::
|
||||
set_cv_out(int n, float x, float y, float z) {
|
||||
if (n<0 || n>=_points.size()) {
|
||||
if (n < 0 || n >= (int)_points.size()) {
|
||||
return false;
|
||||
}
|
||||
_points[n].set_out(LVector3f(x, y, z));
|
||||
_points[n].set_out(LVecBase3f(x, y, z));
|
||||
invalidate_cv(n, false);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -501,7 +510,7 @@ set_cv_out(int n, float x, float y, float z) {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
bool HermiteCurve::
|
||||
set_cv_tstart(int n, double tstart) {
|
||||
if (n<=0 || n>=_points.size()) {
|
||||
if (n <= 0 || n >= (int)_points.size()) {
|
||||
return false;
|
||||
}
|
||||
if (fabs(tstart - get_cv_tstart(n)) > 0.0001) {
|
||||
|
|
@ -520,7 +529,7 @@ set_cv_tstart(int n, double tstart) {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
bool HermiteCurve::
|
||||
set_cv_name(int n, const char *name) {
|
||||
if (n<0 || n>=_points.size()) {
|
||||
if (n < 0 || n >= (int)_points.size()) {
|
||||
return false;
|
||||
}
|
||||
_points[n].set_name(name);
|
||||
|
|
@ -538,7 +547,7 @@ set_cv_name(int n, const char *name) {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
int HermiteCurve::
|
||||
get_cv_type(int n) const {
|
||||
if (n<0 || n>=_points.size()) {
|
||||
if (n < 0 || n >= (int)_points.size()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -551,16 +560,16 @@ get_cv_type(int n) const {
|
|||
// Access: Public, Scheme
|
||||
// Description: Returns the position of the given CV.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
const LVector3f &HermiteCurve::
|
||||
const LVecBase3f &HermiteCurve::
|
||||
get_cv_point(int n) const {
|
||||
if (n<0 || n>=_points.size()) {
|
||||
if (n < 0 || n >= (int)_points.size()) {
|
||||
return zero;
|
||||
}
|
||||
|
||||
return _points[n]._p;
|
||||
}
|
||||
void HermiteCurve::
|
||||
get_cv_point(int n, LVector3f &v) const {
|
||||
get_cv_point(int n, LVecBase3f &v) const {
|
||||
v = get_cv_point(n);
|
||||
}
|
||||
|
||||
|
|
@ -570,16 +579,16 @@ get_cv_point(int n, LVector3f &v) const {
|
|||
// Access: Public, Scheme
|
||||
// Description: Returns the in tangent of the given CV.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
const LVector3f &HermiteCurve::
|
||||
const LVecBase3f &HermiteCurve::
|
||||
get_cv_in(int n) const {
|
||||
if (n<0 || n>=_points.size() || _points[n-1]._type==HC_CUT) {
|
||||
if (n < 0 || n >= (int)_points.size() || _points[n-1]._type==HC_CUT) {
|
||||
return zero;
|
||||
}
|
||||
|
||||
return _points[n]._in;
|
||||
}
|
||||
void HermiteCurve::
|
||||
get_cv_in(int n, LVector3f &v) const {
|
||||
get_cv_in(int n, LVecBase3f &v) const {
|
||||
v = get_cv_in(n);
|
||||
}
|
||||
|
||||
|
|
@ -589,16 +598,16 @@ get_cv_in(int n, LVector3f &v) const {
|
|||
// Access: Public, Scheme
|
||||
// Description: Returns the out tangent of the given CV.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
const LVector3f &HermiteCurve::
|
||||
const LVecBase3f &HermiteCurve::
|
||||
get_cv_out(int n) const {
|
||||
if (n<0 || n>=_points.size() || _points[n]._type==HC_CUT) {
|
||||
if (n < 0 || n >= (int)_points.size() || _points[n]._type==HC_CUT) {
|
||||
return zero;
|
||||
}
|
||||
|
||||
return _points[n]._out;
|
||||
}
|
||||
void HermiteCurve::
|
||||
get_cv_out(int n, LVector3f &v) const {
|
||||
get_cv_out(int n, LVecBase3f &v) const {
|
||||
v = get_cv_out(n);
|
||||
}
|
||||
|
||||
|
|
@ -613,7 +622,7 @@ double HermiteCurve::
|
|||
get_cv_tstart(int n) const {
|
||||
if (n<0) {
|
||||
return 0.0;
|
||||
} else if (n>=_points.size()) {
|
||||
} else if (n >= (int)_points.size()) {
|
||||
return get_max_t();
|
||||
}
|
||||
|
||||
|
|
@ -627,7 +636,7 @@ get_cv_tstart(int n) const {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
const char *HermiteCurve::
|
||||
get_cv_name(int n) const {
|
||||
if (n<0 || n>=_points.size()) {
|
||||
if (n < 0 || n >= (int)_points.size()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -784,10 +793,10 @@ write_egg(ostream &out, const char *basename) {
|
|||
// possible, false if something goes horribly wrong.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool HermiteCurve::
|
||||
rebuild_curveseg(int, double, const LVector4f &,
|
||||
int, double, const LVector4f &,
|
||||
int, double, const LVector4f &,
|
||||
int, double, const LVector4f &) {
|
||||
rebuild_curveseg(int, double, const LVecBase4f &,
|
||||
int, double, const LVecBase4f &,
|
||||
int, double, const LVecBase4f &,
|
||||
int, double, const LVecBase4f &) {
|
||||
cerr << "rebuild_curveseg not implemented for this curve type.\n";
|
||||
return false;
|
||||
}
|
||||
|
|
@ -803,9 +812,9 @@ Output(ostream &out, int indent) const {
|
|||
<< "<VertexPool> " << get_name() << ".pool {\n";
|
||||
|
||||
int i;
|
||||
for (i = 0; i<_points.size(); i++) {
|
||||
bool show_in = (i!=0);
|
||||
bool show_out = (i!=_points.size()-1);
|
||||
for (i = 0; i < (int)_points.size(); i++) {
|
||||
bool show_in = (i != 0);
|
||||
bool show_out = (i != (int)_points.size()-1);
|
||||
_points[i].Output(out, indent+2, _num_dimensions,
|
||||
show_in, show_out,
|
||||
show_in ? get_tlength(i-1) : 0.0,
|
||||
|
|
@ -835,7 +844,7 @@ Output(ostream &out, int indent) const {
|
|||
|
||||
Indent(out, indent+2) << "<TLengths> {";
|
||||
if (_points.size() > 1) {
|
||||
for (i = 0; i<_segs.size(); i++) {
|
||||
for (i = 0; i < (int)_segs.size(); i++) {
|
||||
if (i%10 == 1) {
|
||||
out << "\n";
|
||||
Indent(out, indent+3);
|
||||
|
|
@ -847,7 +856,7 @@ Output(ostream &out, int indent) const {
|
|||
Indent(out, indent+2) << "}\n";
|
||||
|
||||
Indent(out, indent+2) << "<VertexRef> {";
|
||||
for (i = 1; i<=_points.size() * 3 - 2; i++) {
|
||||
for (i = 1; i <= (int)_points.size() * 3 - 2; i++) {
|
||||
if (i%10 == 1) {
|
||||
out << "\n";
|
||||
Indent(out, indent+3);
|
||||
|
|
@ -862,17 +871,8 @@ Output(ostream &out, int indent) const {
|
|||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: HermiteCurve::Destructor
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
HermiteCurve::
|
||||
~HermiteCurve() {
|
||||
}
|
||||
|
||||
static void
|
||||
wrap_hpr(const LVector3f &hpr1, LVector3f &hpr2) {
|
||||
wrap_hpr(const LVecBase3f &hpr1, LVecBase3f &hpr2) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
while ((hpr2[i] - hpr1[i]) > 180.0) {
|
||||
hpr2[i] -= 360.0;
|
||||
|
|
@ -903,7 +903,7 @@ invalidate_cv(int n, bool redo_all) {
|
|||
t1 = get_cv_tstart(n-1);
|
||||
}
|
||||
|
||||
if (n+1 < _points.size()) {
|
||||
if (n+1 < (int)_points.size()) {
|
||||
if (_points[n]._type==HC_CUT) {
|
||||
BezierSeg seg;
|
||||
seg._v[0] = seg._v[1] = seg._v[2] = seg._v[3] = _points[n]._p;
|
||||
|
|
@ -941,7 +941,7 @@ find_cv(double t) {
|
|||
nassertr(is_valid(), 0);
|
||||
|
||||
int n;
|
||||
for (n = 0; n<_segs.size(); n++) {
|
||||
for (n = 0; n < (int)_segs.size(); n++) {
|
||||
if (_segs[n]._tend+0.00001 > t) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -962,7 +962,7 @@ find_cv(double t) {
|
|||
void HermiteCurve::
|
||||
recompute_basis() {
|
||||
int n;
|
||||
for (n = 0; n<_segs.size(); n++) {
|
||||
for (n = 0; n < (int)_segs.size(); n++) {
|
||||
if (_points[n]._type==HC_CUT) {
|
||||
BezierSeg seg;
|
||||
seg._v[0] = seg._v[1] = seg._v[2] = seg._v[3] = _points[n]._p;
|
||||
|
|
|
|||
|
|
@ -64,9 +64,9 @@ public:
|
|||
HermiteCurveCV(const HermiteCurveCV &c);
|
||||
~HermiteCurveCV();
|
||||
|
||||
void set_point(const LVector3f &point) { _p = point; }
|
||||
void set_in(const LVector3f &in);
|
||||
void set_out(const LVector3f &out);
|
||||
void set_point(const LVecBase3f &point) { _p = point; }
|
||||
void set_in(const LVecBase3f &in);
|
||||
void set_out(const LVecBase3f &out);
|
||||
void set_type(int type);
|
||||
void set_name(const char *name);
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ public:
|
|||
bool show_in, bool show_out,
|
||||
double scale_in, double scale_out) const;
|
||||
|
||||
LVector3f _p, _in, _out;
|
||||
LVecBase3f _p, _in, _out;
|
||||
int _type;
|
||||
char *_name;
|
||||
};
|
||||
|
|
@ -95,12 +95,13 @@ class HermiteCurve : public PiecewiseCurve {
|
|||
PUBLISHED:
|
||||
HermiteCurve();
|
||||
HermiteCurve(const ParametricCurve &pc);
|
||||
virtual ~HermiteCurve();
|
||||
|
||||
int get_num_cvs() const;
|
||||
|
||||
int insert_cv(double t);
|
||||
int append_cv(int type, float x, float y, float z);
|
||||
inline int append_cv(int type, const LVector3f &v) {
|
||||
inline int append_cv(int type, const LVecBase3f &v) {
|
||||
return append_cv(type, v[0], v[1], v[2]);
|
||||
}
|
||||
|
||||
|
|
@ -109,15 +110,15 @@ PUBLISHED:
|
|||
|
||||
bool set_cv_type(int n, int type);
|
||||
bool set_cv_point(int n, float x, float y, float z);
|
||||
inline bool set_cv_point(int n, const LVector3f &v) {
|
||||
inline bool set_cv_point(int n, const LVecBase3f &v) {
|
||||
return set_cv_point(n, v[0], v[1], v[2]);
|
||||
}
|
||||
bool set_cv_in(int n, float x, float y, float z);
|
||||
inline bool set_cv_in(int n, const LVector3f &v) {
|
||||
inline bool set_cv_in(int n, const LVecBase3f &v) {
|
||||
return set_cv_in(n, v[0], v[1], v[2]);
|
||||
}
|
||||
bool set_cv_out(int n, float x, float y, float z);
|
||||
inline bool set_cv_out(int n, const LVector3f &v) {
|
||||
inline bool set_cv_out(int n, const LVecBase3f &v) {
|
||||
return set_cv_out(n, v[0], v[1], v[2]);
|
||||
}
|
||||
bool set_cv_tstart(int n, double tstart);
|
||||
|
|
@ -125,12 +126,12 @@ PUBLISHED:
|
|||
|
||||
|
||||
int get_cv_type(int n) const;
|
||||
const LVector3f &get_cv_point(int n) const;
|
||||
void get_cv_point(int n, LVector3f &v) const;
|
||||
const LVector3f &get_cv_in(int n) const;
|
||||
void get_cv_in(int n, LVector3f &v) const;
|
||||
const LVector3f &get_cv_out(int n) const;
|
||||
void get_cv_out(int n, LVector3f &v) const;
|
||||
const LVecBase3f &get_cv_point(int n) const;
|
||||
void get_cv_point(int n, LVecBase3f &v) const;
|
||||
const LVecBase3f &get_cv_in(int n) const;
|
||||
void get_cv_in(int n, LVecBase3f &v) const;
|
||||
const LVecBase3f &get_cv_out(int n) const;
|
||||
void get_cv_out(int n, LVecBase3f &v) const;
|
||||
double get_cv_tstart(int n) const;
|
||||
const char *get_cv_name(int n) const;
|
||||
|
||||
|
|
@ -147,14 +148,13 @@ public:
|
|||
}
|
||||
|
||||
virtual bool
|
||||
rebuild_curveseg(int rtype0, double t0, const LVector4f &v0,
|
||||
int rtype1, double t1, const LVector4f &v1,
|
||||
int rtype2, double t2, const LVector4f &v2,
|
||||
int rtype3, double t3, const LVector4f &v3);
|
||||
rebuild_curveseg(int rtype0, double t0, const LVecBase4f &v0,
|
||||
int rtype1, double t1, const LVecBase4f &v1,
|
||||
int rtype2, double t2, const LVecBase4f &v2,
|
||||
int rtype3, double t3, const LVecBase4f &v3);
|
||||
|
||||
void Output(ostream &out, int indent=0) const;
|
||||
|
||||
virtual ~HermiteCurve();////
|
||||
protected:
|
||||
|
||||
void invalidate_cv(int n, bool redo_all);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
TypeHandle NurbsCurve::_type_handle;
|
||||
|
||||
static const LVector3f zero = LVector3f(0.0, 0.0, 0.0);
|
||||
static const LVecBase3f zero = LVecBase3f(0.0, 0.0, 0.0);
|
||||
// This is returned occasionally from some of the functions, and is
|
||||
// used from time to time as an initializer.
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ NurbsCurve(const ParametricCurve &pc) {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
NurbsCurve::
|
||||
NurbsCurve(int order, int num_cvs,
|
||||
const double knots[], const LVector4f cvs[]) {
|
||||
const double knots[], const LVecBase4f cvs[]) {
|
||||
_order = order;
|
||||
|
||||
int i;
|
||||
|
|
@ -92,6 +92,15 @@ NurbsCurve(int order, int num_cvs,
|
|||
recompute();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: NurbsCurve::Destructor
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
NurbsCurve::
|
||||
~NurbsCurve() {
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: NurbsCurve::set_order
|
||||
|
|
@ -168,7 +177,7 @@ insert_cv(double t) {
|
|||
// First, get the new values of all the CV's that will change.
|
||||
// These are the CV's in the range [k - (_order-1), k-1].
|
||||
|
||||
LVector4f new_cvs[3];
|
||||
LVecBase4f new_cvs[3];
|
||||
int i;
|
||||
for (i = 0; i < _order-1; i++) {
|
||||
int nk = i + k - (_order-1);
|
||||
|
|
@ -206,7 +215,7 @@ insert_cv(double t) {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
int NurbsCurve::
|
||||
append_cv(float x, float y, float z) {
|
||||
return append_cv(LVector4f(x, y, z, 1.0));
|
||||
return append_cv(LVecBase4f(x, y, z, 1.0));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -218,7 +227,7 @@ append_cv(float x, float y, float z) {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
bool NurbsCurve::
|
||||
remove_cv(int n) {
|
||||
if (n < 0 || n >= _cvs.size()) {
|
||||
if (n < 0 || n >= (int)_cvs.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -245,7 +254,7 @@ remove_all_cvs() {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
bool NurbsCurve::
|
||||
set_cv_point(int n, float x, float y, float z) {
|
||||
if (n < 0 || n >= _cvs.size()) {
|
||||
if (n < 0 || n >= (int)_cvs.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -260,11 +269,11 @@ set_cv_point(int n, float x, float y, float z) {
|
|||
// Description: Returns the position of the indicated CV.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void NurbsCurve::
|
||||
get_cv_point(int n, LVector3f &v) const {
|
||||
if (n < 0 || n >= _cvs.size()) {
|
||||
get_cv_point(int n, LVecBase3f &v) const {
|
||||
if (n < 0 || n >= (int)_cvs.size()) {
|
||||
v = zero;
|
||||
} else {
|
||||
v = (const LVector3f &)_cvs[n]._p / _cvs[n]._p[3];
|
||||
v = (const LVecBase3f &)_cvs[n]._p / _cvs[n]._p[3];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -273,13 +282,13 @@ get_cv_point(int n, LVector3f &v) const {
|
|||
// Access: Public, Scheme
|
||||
// Description: Returns the position of the indicated CV.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
const LVector3f &NurbsCurve::
|
||||
const LVecBase3f &NurbsCurve::
|
||||
get_cv_point(int n) const {
|
||||
if (n < 0 || n >= _cvs.size()) {
|
||||
if (n < 0 || n >= (int)_cvs.size()) {
|
||||
return zero;
|
||||
} else {
|
||||
static LVector3f result;
|
||||
result = (LVector3f &)_cvs[n]._p / _cvs[n]._p[3];
|
||||
static LVecBase3f result;
|
||||
result = (LVecBase3f &)_cvs[n]._p / _cvs[n]._p[3];
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -292,7 +301,7 @@ get_cv_point(int n) const {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
bool NurbsCurve::
|
||||
set_cv_weight(int n, float w) {
|
||||
if (n < 0 || n >= _cvs.size()) {
|
||||
if (n < 0 || n >= (int)_cvs.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -307,7 +316,7 @@ set_cv_weight(int n, float w) {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
float NurbsCurve::
|
||||
get_cv_weight(int n) const {
|
||||
if (n < 0 || n >= _cvs.size()) {
|
||||
if (n < 0 || n >= (int)_cvs.size()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
|
@ -326,7 +335,7 @@ get_cv_weight(int n) const {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
bool NurbsCurve::
|
||||
set_knot(int n, double t) {
|
||||
if (n < _order || n-1 >= _cvs.size()) {
|
||||
if (n < _order || n-1 >= (int)_cvs.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -374,13 +383,13 @@ print() const {
|
|||
|
||||
cout << "CV's:\n";
|
||||
int i;
|
||||
for (i = 0; i < _cvs.size(); i++) {
|
||||
LVector3f p = (const LVector3f &)_cvs[i]._p / _cvs[i]._p[3];
|
||||
for (i = 0; i < (int)_cvs.size(); i++) {
|
||||
LVecBase3f p = (const LVecBase3f &)_cvs[i]._p / _cvs[i]._p[3];
|
||||
cout << i << ") " << p << ", weight " << _cvs[i]._p[3] << "\n";
|
||||
}
|
||||
|
||||
cout << "Knots: ";
|
||||
for (i = 0; i < _cvs.size()+_order; i++) {
|
||||
for (i = 0; i < (int)_cvs.size()+_order; i++) {
|
||||
cout << " " << GetKnot(i);
|
||||
}
|
||||
cout << "\n" << flush;
|
||||
|
|
@ -393,10 +402,10 @@ print() const {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
void NurbsCurve::
|
||||
print_cv(int n) const {
|
||||
if (n < 0 || n >= _cvs.size()) {
|
||||
if (n < 0 || n >= (int)_cvs.size()) {
|
||||
cout << "No such CV: " << n << "\n";
|
||||
} else {
|
||||
LVector3f p = (const LVector3f &)_cvs[n]._p / _cvs[n]._p[3];
|
||||
LVecBase3f p = (const LVecBase3f &)_cvs[n]._p / _cvs[n]._p[3];
|
||||
cout << "CV " << n << ": " << p << ", weight "
|
||||
<< _cvs[n]._p[3] << "\n";
|
||||
}
|
||||
|
|
@ -419,10 +428,10 @@ recompute() {
|
|||
_segs.erase(_segs.begin(), _segs.end());
|
||||
|
||||
double knots[8];
|
||||
LVector4f cvs[4];
|
||||
LVecBase4f cvs[4];
|
||||
|
||||
if (_cvs.size() > _order-1) {
|
||||
for (int cv = 0; cv < _cvs.size()-(_order-1); cv++) {
|
||||
if ((int)_cvs.size() > _order-1) {
|
||||
for (int cv = 0; cv < (int)_cvs.size()-(_order-1); cv++) {
|
||||
if (GetKnot(cv+_order-1) < GetKnot(cv+_order)) {
|
||||
// There are _order consecutive CV's that define each segment,
|
||||
// beginning at cv. Collect the CV's and knot values that define
|
||||
|
|
@ -520,11 +529,11 @@ adjust_pt(double t,
|
|||
|
||||
// Now copy the cvs and knots in question.
|
||||
double knots[8];
|
||||
LVector4f cvs[4];
|
||||
LVecBase4f cvs[4];
|
||||
|
||||
int c;
|
||||
for (c = 0; c < 4; c++) {
|
||||
cvs[c] = (c < _order) ? _cvs[c+cv]._p : LVector4f(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++) {
|
||||
knots[c] = GetKnot(c+cv);
|
||||
|
|
@ -592,7 +601,7 @@ adjust_pt(double t,
|
|||
// Now extract the new CV's from the new G matrix, and restore them
|
||||
// to the curve.
|
||||
for (c = 0; c < _order; c++) {
|
||||
LVector4f &s = _cvs[c+cv]._p;
|
||||
LVecBase4f &s = _cvs[c+cv]._p;
|
||||
G.getCol(c, &s[0], &s[1], &s[2], &s[3]);
|
||||
}
|
||||
}
|
||||
|
|
@ -608,17 +617,17 @@ adjust_pt(double t,
|
|||
// possible, false if something goes horribly wrong.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool NurbsCurve::
|
||||
rebuild_curveseg(int rtype0, double t0, const LVector4f &v0,
|
||||
int rtype1, double t1, const LVector4f &v1,
|
||||
int rtype2, double t2, const LVector4f &v2,
|
||||
int rtype3, double t3, const LVector4f &v3) {
|
||||
rebuild_curveseg(int rtype0, double t0, const LVecBase4f &v0,
|
||||
int rtype1, double t1, const LVecBase4f &v1,
|
||||
int rtype2, double t2, const LVecBase4f &v2,
|
||||
int rtype3, double t3, const LVecBase4f &v3) {
|
||||
// Figure out which CV's contributed to this segment.
|
||||
int seg = 0;
|
||||
|
||||
nassertr(_cvs.size() > _order-1, false);
|
||||
nassertr((int)_cvs.size() > _order-1, false);
|
||||
|
||||
int cv = 0;
|
||||
for (cv = 0; cv < _cvs.size()-(_order-1); cv++) {
|
||||
for (cv = 0; cv < (int)_cvs.size()-(_order-1); cv++) {
|
||||
if (GetKnot(cv+_order-1) < GetKnot(cv+_order)) {
|
||||
if (seg == _last_ti) {
|
||||
break;
|
||||
|
|
@ -637,8 +646,8 @@ rebuild_curveseg(int rtype0, double t0, const LVector4f &v0,
|
|||
// properties depends on the original value.
|
||||
if ((rtype0 | rtype1 | rtype2 | rtype3) & RT_KEEP_ORIG) {
|
||||
for (c = 0; c < 4; c++) {
|
||||
static const LVector4f zero(0.0, 0.0, 0.0, 0.0);
|
||||
const LVector4f &s = (c < _order) ? _cvs[c+cv]._p : zero;
|
||||
static const LVecBase4f zero(0.0, 0.0, 0.0, 0.0);
|
||||
const LVecBase4f &s = (c < _order) ? _cvs[c+cv]._p : zero;
|
||||
|
||||
G.set_col(c, s);
|
||||
}
|
||||
|
|
@ -775,7 +784,7 @@ splice(double t, const NurbsCurve &other) {
|
|||
|
||||
// Now add all the new CV's.
|
||||
int cv;
|
||||
for (cv = 0; cv < other._cvs.size(); cv++) {
|
||||
for (cv = 0; cv < (int)other._cvs.size(); cv++) {
|
||||
CV new_cv(other._cvs[cv]);
|
||||
|
||||
if (cv+1 < _order) {
|
||||
|
|
@ -805,7 +814,7 @@ Output(ostream &out, int indent) const {
|
|||
<< "<VertexPool> " << get_name() << ".pool {\n";
|
||||
|
||||
int cv;
|
||||
for (cv = 0; cv < _cvs.size(); cv++) {
|
||||
for (cv = 0; cv < (int)_cvs.size(); cv++) {
|
||||
Indent(out, indent+2) << "<Vertex> " << cv << " { "
|
||||
<< _cvs[cv]._p << " }\n";
|
||||
}
|
||||
|
|
@ -848,7 +857,7 @@ Output(ostream &out, int indent) const {
|
|||
Indent(out, indent+2) << "}\n";
|
||||
|
||||
Indent(out, indent+2) << "<VertexRef> {";
|
||||
for (cv = 0; cv < _cvs.size(); cv++) {
|
||||
for (cv = 0; cv < (int)_cvs.size(); cv++) {
|
||||
if (cv%10 == 1) {
|
||||
out << "\n";
|
||||
Indent(out, indent+3);
|
||||
|
|
@ -862,15 +871,6 @@ Output(ostream &out, int indent) const {
|
|||
Indent(out, indent) << "}\n";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: NurbsCurve::Destructor
|
||||
// Access: Protected
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
NurbsCurve::
|
||||
~NurbsCurve() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: NurbsCurve::FindCV
|
||||
// Access: Protected
|
||||
|
|
@ -880,7 +880,7 @@ NurbsCurve::
|
|||
int NurbsCurve::
|
||||
FindCV(double t) {
|
||||
int i;
|
||||
for (i = _order-1; i < _cvs.size(); i++) {
|
||||
for (i = _order-1; i < (int)_cvs.size(); i++) {
|
||||
if (_cvs[i]._t >= t) {
|
||||
return i+1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@
|
|||
// Defines
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////#define LVector3f pfVec3
|
||||
//typedef pfVec3 LVector3f;
|
||||
////#define LVecBase3f pfVec3
|
||||
//typedef pfVec3 LVecBase3f;
|
||||
|
||||
|
||||
class HermiteCurve;
|
||||
|
|
@ -50,7 +50,8 @@ PUBLISHED:
|
|||
NurbsCurve();
|
||||
NurbsCurve(const ParametricCurve &hc);
|
||||
NurbsCurve(int order, int num_cvs,
|
||||
const double knots[], const LVector4f cvs[]);
|
||||
const double knots[], const LVecBase4f cvs[]);
|
||||
virtual ~NurbsCurve();
|
||||
|
||||
void set_order(int order);
|
||||
int get_order() const;
|
||||
|
|
@ -62,10 +63,10 @@ PUBLISHED:
|
|||
|
||||
int insert_cv(double t);
|
||||
int append_cv(float x, float y, float z);
|
||||
inline int append_cv(const LVector3f &v) {
|
||||
return append_cv(LVector4f(v[0], v[1], v[2], 1.0));
|
||||
inline int append_cv(const LVecBase3f &v) {
|
||||
return append_cv(LVecBase4f(v[0], v[1], v[2], 1.0));
|
||||
}
|
||||
inline int append_cv(const LVector4f &v) {
|
||||
inline int append_cv(const LVecBase4f &v) {
|
||||
_cvs.push_back(CV(v, GetKnot(_cvs.size())+1.0));
|
||||
return _cvs.size()-1;
|
||||
}
|
||||
|
|
@ -74,11 +75,11 @@ PUBLISHED:
|
|||
void remove_all_cvs();
|
||||
|
||||
bool set_cv_point(int n, float x, float y, float z);
|
||||
inline bool set_cv_point(int n, const LVector3f &v) {
|
||||
inline bool set_cv_point(int n, const LVecBase3f &v) {
|
||||
return set_cv_point(n, v[0], v[1], v[2]);
|
||||
}
|
||||
void get_cv_point(int n, LVector3f &v) const;
|
||||
const LVector3f &get_cv_point(int n) const;
|
||||
void get_cv_point(int n, LVecBase3f &v) const;
|
||||
const LVecBase3f &get_cv_point(int n) const;
|
||||
|
||||
bool set_cv_weight(int n, float w);
|
||||
float get_cv_weight(int n) const;
|
||||
|
|
@ -103,10 +104,10 @@ PUBLISHED:
|
|||
////////////////////////////////////////////////////////////////////
|
||||
public:
|
||||
virtual bool
|
||||
rebuild_curveseg(int rtype0, double t0, const LVector4f &v0,
|
||||
int rtype1, double t1, const LVector4f &v1,
|
||||
int rtype2, double t2, const LVector4f &v2,
|
||||
int rtype3, double t3, const LVector4f &v3);
|
||||
rebuild_curveseg(int rtype0, double t0, const LVecBase4f &v0,
|
||||
int rtype1, double t1, const LVecBase4f &v1,
|
||||
int rtype2, double t2, const LVecBase4f &v2,
|
||||
int rtype3, double t3, const LVecBase4f &v3);
|
||||
|
||||
CubicCurveseg *get_curveseg(int ti) {
|
||||
return (CubicCurveseg *)PiecewiseCurve::get_curveseg(ti);
|
||||
|
|
@ -116,7 +117,7 @@ public:
|
|||
GetKnot(int n) const {
|
||||
if (n < _order || _cvs.empty()) {
|
||||
return 0.0;
|
||||
} else if (n-1 >= _cvs.size()) {
|
||||
} else if (n-1 >= (int)_cvs.size()) {
|
||||
return _cvs.back()._t;
|
||||
} else {
|
||||
return _cvs[n-1]._t;
|
||||
|
|
@ -126,8 +127,6 @@ public:
|
|||
void Output(ostream &out, int indent=0) const;
|
||||
|
||||
protected:
|
||||
virtual ~NurbsCurve();
|
||||
|
||||
int FindCV(double t);
|
||||
|
||||
int _order;
|
||||
|
|
@ -135,8 +134,8 @@ protected:
|
|||
class CV {
|
||||
public:
|
||||
CV() {}
|
||||
CV(const LVector4f &p, double t) : _p(p), _t(t) {}
|
||||
LVector4f _p;
|
||||
CV(const LVecBase4f &p, double t) : _p(p), _t(t) {}
|
||||
LVecBase4f _p;
|
||||
double _t;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ draw() {
|
|||
double t = nurbs->GetKnot(i);
|
||||
if (t != lt) {
|
||||
lt = t;
|
||||
LVector3f knot_pos, knot_tan;
|
||||
LVecBase3f knot_pos, knot_tan;
|
||||
nurbs->get_pt(nurbs->GetKnot(i), knot_pos, knot_tan);
|
||||
_knots.move_to(_mapper(knot_pos, knot_tan, t));
|
||||
ki++;
|
||||
|
|
@ -142,7 +142,7 @@ draw() {
|
|||
if (_show_cvs) {
|
||||
_num_cvs = nurbs->get_num_cvs();
|
||||
for (i = 0; i < _num_cvs; i++) {
|
||||
_cvs.move_to(_mapper(nurbs->get_cv_point(i), LVector3f(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)));
|
||||
}
|
||||
|
||||
|
|
@ -152,7 +152,7 @@ draw() {
|
|||
if (_show_hull) {
|
||||
_num_cvs = nurbs->get_num_cvs();
|
||||
for (i = 0; i < _num_cvs; i++) {
|
||||
_hull.draw_to(_mapper(nurbs->get_cv_point(i), LVector3f(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)));
|
||||
}
|
||||
|
||||
|
|
@ -264,7 +264,7 @@ hilight(int n, float hr, float hg, float hb) {
|
|||
return false;
|
||||
}
|
||||
|
||||
NurbsCurve *nurbs = (NurbsCurve *)_curve;
|
||||
// NurbsCurve *nurbs = (NurbsCurve *)_curve;
|
||||
if (_show_cvs) {
|
||||
_cvs.set_vertex_color(n, hr, hg, hb);
|
||||
}
|
||||
|
|
@ -292,7 +292,7 @@ unhilight(int n) {
|
|||
return false;
|
||||
}
|
||||
|
||||
NurbsCurve *nurbs = (NurbsCurve *)_curve;
|
||||
// NurbsCurve *nurbs = (NurbsCurve *)_curve;
|
||||
if (_show_cvs) {
|
||||
_cvs.set_vertex_color(n, _cv_color[0], _cv_color[1], _cv_color[2]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ PUBLISHED:
|
|||
// Member functions not visible to Scheme
|
||||
////////////////////////////////////////////////////////////////////
|
||||
protected:
|
||||
LVector3f _cv_color, _hull_color, _knot_color;
|
||||
LVecBase3f _cv_color, _hull_color, _knot_color;
|
||||
int _num_cvs, _num_hull, _num_knots;
|
||||
LineSegs _hull, _knots, _cvs;
|
||||
vector<int> _knotnums;
|
||||
|
|
|
|||
Loading…
Reference in New Issue