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