00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef PIECEWISECURVE_H
00016 #define PIECEWISECURVE_H
00017
00018 #include "pandabase.h"
00019
00020 #include "parametricCurve.h"
00021 #include "pointerTo.h"
00022
00023
00024
00025
00026
00027
00028
00029
00030 class EXPCL_PANDA_PARAMETRICS PiecewiseCurve : public ParametricCurve {
00031 PUBLISHED:
00032 PiecewiseCurve();
00033 ~PiecewiseCurve();
00034
00035 public:
00036
00037
00038 virtual bool is_valid() const;
00039 virtual PN_stdfloat get_max_t() const;
00040
00041 virtual bool get_point(PN_stdfloat t, LVecBase3 &point) const;
00042 virtual bool get_tangent(PN_stdfloat t, LVecBase3 &tangent) const;
00043 virtual bool get_pt(PN_stdfloat t, LVecBase3 &point, LVecBase3 &tangent) const;
00044 virtual bool get_2ndtangent(PN_stdfloat t, LVecBase3 &tangent2) const;
00045
00046 virtual bool adjust_point(PN_stdfloat t, PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz);
00047 virtual bool adjust_tangent(PN_stdfloat t, PN_stdfloat tx, PN_stdfloat ty, PN_stdfloat tz);
00048 virtual bool adjust_pt(PN_stdfloat t,
00049 PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz,
00050 PN_stdfloat tx, PN_stdfloat ty, PN_stdfloat tz);
00051
00052 public:
00053 int get_num_segs() const;
00054
00055 ParametricCurve *get_curveseg(int ti);
00056 bool insert_curveseg(int ti, ParametricCurve *seg, PN_stdfloat tlength);
00057
00058 bool remove_curveseg(int ti);
00059 void remove_all_curvesegs();
00060
00061 PN_stdfloat get_tlength(int ti) const;
00062 PN_stdfloat get_tstart(int ti) const;
00063 PN_stdfloat get_tend(int ti) const;
00064 bool set_tlength(int ti, PN_stdfloat tlength);
00065
00066 void make_nurbs(int order, int num_cvs,
00067 const PN_stdfloat knots[], const LVecBase4 cvs[]);
00068
00069 virtual bool get_bezier_segs(BezierSegs &bz_segs) const;
00070
00071 virtual bool
00072 rebuild_curveseg(int rtype0, PN_stdfloat t0, const LVecBase4 &v0,
00073 int rtype1, PN_stdfloat t1, const LVecBase4 &v1,
00074 int rtype2, PN_stdfloat t2, const LVecBase4 &v2,
00075 int rtype3, PN_stdfloat t3, const LVecBase4 &v3);
00076
00077 protected:
00078 bool find_curve(const ParametricCurve *&curve, PN_stdfloat &t) const;
00079 PN_stdfloat current_seg_range(PN_stdfloat t) const;
00080
00081 class Curveseg {
00082 public:
00083 Curveseg() {}
00084 Curveseg(ParametricCurve *c, PN_stdfloat t) : _curve(c), _tend(t) {}
00085
00086 PT(ParametricCurve) _curve;
00087 PN_stdfloat _tend;
00088 };
00089
00090 pvector<Curveseg> _segs;
00091 int _last_ti;
00092
00093
00094
00095 protected:
00096 virtual void write_datagram(BamWriter *manager, Datagram &me);
00097 void fillin(DatagramIterator &scan, BamReader *manager);
00098 virtual int complete_pointers(TypedWritable **plist,
00099 BamReader *manager);
00100
00101 public:
00102 static TypeHandle get_class_type() {
00103 return _type_handle;
00104 }
00105 static void init_type() {
00106 ParametricCurve::init_type();
00107 register_type(_type_handle, "PiecewiseCurve",
00108 ParametricCurve::get_class_type());
00109 }
00110 virtual TypeHandle get_type() const {
00111 return get_class_type();
00112 }
00113 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00114
00115 private:
00116 static TypeHandle _type_handle;
00117 };
00118
00119
00120 #endif