00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CUBICCURVESEG_H
00016 #define CUBICCURVESEG_H
00017
00018 #include "pandabase.h"
00019
00020 #include "parametricCurve.h"
00021
00022
00023
00024
00025
00026 #define RT_POINT 0x01
00027 #define RT_TANGENT 0x02
00028 #define RT_CV 0x03
00029 #define RT_BASE_TYPE 0xff
00030
00031 #define RT_KEEP_ORIG 0x100
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 class EXPCL_PANDA_PARAMETRICS CubicCurveseg : public ParametricCurve {
00059 PUBLISHED:
00060 virtual bool get_point(PN_stdfloat t, LVecBase3 &point) const;
00061 virtual bool get_tangent(PN_stdfloat t, LVecBase3 &tangent) const;
00062 virtual bool get_pt(PN_stdfloat t, LVecBase3 &point, LVecBase3 &tangent) const;
00063 virtual bool get_2ndtangent(PN_stdfloat t, LVecBase3 &tangent2) const;
00064
00065 public:
00066 CubicCurveseg();
00067 CubicCurveseg(const LMatrix4 &basis);
00068 CubicCurveseg(const BezierSeg &seg);
00069 CubicCurveseg(int order, const PN_stdfloat knots[], const LVecBase4 cvs[]);
00070
00071 virtual ~CubicCurveseg();
00072
00073 void hermite_basis(const HermiteCurveCV &cv0,
00074 const HermiteCurveCV &cv1,
00075 PN_stdfloat tlength = 1.0f);
00076 void bezier_basis(const BezierSeg &seg);
00077 void nurbs_basis(int order, const PN_stdfloat knots[], const LVecBase4 cvs[]);
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 void evaluate_point(const LVecBase4 &tv, LVecBase3 &result) const {
00091 PN_stdfloat recip_h = (rational) ? 1.0f/tv.dot(Bw) : 1.0f;
00092 result.set(tv.dot(Bx) * recip_h,
00093 tv.dot(By) * recip_h,
00094 tv.dot(Bz) * recip_h);
00095 }
00096
00097 void evaluate_vector(const LVecBase4 &tv, LVecBase3 &result) const {
00098 result.set(tv.dot(Bx),
00099 tv.dot(By),
00100 tv.dot(Bz));
00101 }
00102
00103 virtual bool get_bezier_seg(BezierSeg &seg) const;
00104
00105 static bool compute_seg(int rtype0, PN_stdfloat t0, const LVecBase4 &v0,
00106 int rtype1, PN_stdfloat t1, const LVecBase4 &v1,
00107 int rtype2, PN_stdfloat t2, const LVecBase4 &v2,
00108 int rtype3, PN_stdfloat t3, const LVecBase4 &v3,
00109 const LMatrix4 &B,
00110 const LMatrix4 &Bi,
00111 LMatrix4 &G);
00112
00113 LVecBase4 Bx, By, Bz, Bw;
00114 bool rational;
00115
00116
00117
00118 public:
00119 static void register_with_read_factory();
00120
00121 protected:
00122 static TypedWritable *make_CubicCurveseg(const FactoryParams ¶ms);
00123 virtual void write_datagram(BamWriter *manager, Datagram &me);
00124 void fillin(DatagramIterator &scan, BamReader *manager);
00125
00126 public:
00127 static TypeHandle get_class_type() {
00128 return _type_handle;
00129 }
00130 static void init_type() {
00131 ParametricCurve::init_type();
00132 register_type(_type_handle, "CubicCurveseg",
00133 ParametricCurve::get_class_type());
00134 }
00135 virtual TypeHandle get_type() const {
00136 return get_class_type();
00137 }
00138 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00139
00140 private:
00141 static TypeHandle _type_handle;
00142 };
00143
00144
00145
00146 void compute_nurbs_basis(int order,
00147 const PN_stdfloat knots_in[],
00148 LMatrix4 &basis);
00149
00150
00151 #endif