Panda3D
|
00001 // Filename: parametricCurve.h 00002 // Created by: drose (04Mar01) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef PARAMETRICCURVE_H 00016 #define PARAMETRICCURVE_H 00017 00018 #include "pandabase.h" 00019 00020 #include "pandaNode.h" 00021 #include "luse.h" 00022 00023 #include "typedef.h" 00024 #include "plist.h" 00025 #include "pvector.h" 00026 00027 00028 // Parametric curve semantic types. A parametric curve may have one 00029 // of these types specified. These serve as hints to the egg reader 00030 // and writer code about the intention of this curve, and have no 00031 // other effect on the curve. 00032 00033 BEGIN_PUBLISH //[ 00034 #define PCT_NONE 0 00035 // Unspecified type. 00036 00037 #define PCT_XYZ 1 00038 // A three-dimensional curve in space. 00039 00040 #define PCT_HPR 2 00041 // The curve represents Euler rotation angles. 00042 00043 #define PCT_T 3 00044 // A one-dimensional timewarp curve. 00045 END_PUBLISH //] 00046 00047 class ParametricCurveDrawer; 00048 class HermiteCurveCV; 00049 class HermiteCurve; 00050 class NurbsCurve; 00051 class NurbsCurveInterface; 00052 00053 00054 //////////////////////////////////////////////////////////////////// 00055 // Class : ParametricCurve 00056 // Description : A virtual base class for parametric curves. 00057 // This encapsulates all curves in 3-d space defined 00058 // for a single parameter t in the range [0,get_max_t()]. 00059 //////////////////////////////////////////////////////////////////// 00060 class EXPCL_PANDA_PARAMETRICS ParametricCurve : public PandaNode { 00061 PUBLISHED: 00062 ParametricCurve(); 00063 virtual ~ParametricCurve(); 00064 00065 public: 00066 virtual bool safe_to_flatten() const; 00067 virtual bool safe_to_transform() const; 00068 00069 PUBLISHED: 00070 virtual bool is_valid() const; 00071 00072 virtual PN_stdfloat get_max_t() const; 00073 00074 void set_curve_type(int type); 00075 int get_curve_type() const; 00076 00077 void set_num_dimensions(int num); 00078 int get_num_dimensions() const; 00079 00080 PN_stdfloat calc_length() const; 00081 PN_stdfloat calc_length(PN_stdfloat from, PN_stdfloat to) const; 00082 PN_stdfloat find_length(PN_stdfloat start_t, PN_stdfloat length_offset) const; 00083 00084 virtual bool get_point(PN_stdfloat t, LVecBase3 &point) const=0; 00085 virtual bool get_tangent(PN_stdfloat t, LVecBase3 &tangent) const=0; 00086 virtual bool get_pt(PN_stdfloat t, LVecBase3 &point, LVecBase3 &tangent) const=0; 00087 virtual bool get_2ndtangent(PN_stdfloat t, LVecBase3 &tangent2) const=0; 00088 00089 virtual bool adjust_point(PN_stdfloat t, PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz); 00090 virtual bool adjust_tangent(PN_stdfloat t, PN_stdfloat tx, PN_stdfloat ty, PN_stdfloat tz); 00091 virtual bool adjust_pt(PN_stdfloat t, 00092 PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz, 00093 PN_stdfloat tx, PN_stdfloat ty, PN_stdfloat tz); 00094 00095 virtual bool recompute(); 00096 00097 virtual bool stitch(const ParametricCurve *a, const ParametricCurve *b); 00098 00099 bool write_egg(Filename filename, CoordinateSystem cs = CS_default); 00100 bool write_egg(ostream &out, const Filename &filename, CoordinateSystem cs); 00101 00102 public: 00103 struct BezierSeg { 00104 public: 00105 LVecBase3 _v[4]; 00106 PN_stdfloat _t; 00107 }; 00108 typedef pvector<BezierSeg> BezierSegs; 00109 00110 virtual bool get_bezier_segs(BezierSegs &) const; 00111 virtual bool get_bezier_seg(BezierSeg &) const; 00112 virtual NurbsCurveInterface *get_nurbs_interface(); 00113 00114 virtual bool convert_to_hermite(HermiteCurve *hc) const; 00115 virtual bool convert_to_nurbs(ParametricCurve *nc) const; 00116 00117 void register_drawer(ParametricCurveDrawer *drawer); 00118 void unregister_drawer(ParametricCurveDrawer *drawer); 00119 00120 protected: 00121 void invalidate(PN_stdfloat t1, PN_stdfloat t2); 00122 void invalidate_all(); 00123 00124 virtual bool format_egg(ostream &out, const string &name, 00125 const string &curve_type, int indent_level) const; 00126 00127 private: 00128 PN_stdfloat r_calc_length(PN_stdfloat t1, PN_stdfloat t2, 00129 const LPoint3 &p1, const LPoint3 &p2, 00130 PN_stdfloat seglength) const; 00131 bool r_find_length(PN_stdfloat target_length, PN_stdfloat &found_t, 00132 PN_stdfloat t1, PN_stdfloat t2, 00133 const LPoint3 &p1, const LPoint3 &p2, 00134 PN_stdfloat &seglength) const; 00135 bool r_find_t(PN_stdfloat target_length, PN_stdfloat &found_t, 00136 PN_stdfloat t1, PN_stdfloat t2, 00137 const LPoint3 &p1, const LPoint3 &p2) const; 00138 bool find_t_linear(PN_stdfloat target_length, PN_stdfloat &found_t, 00139 PN_stdfloat t1, PN_stdfloat t2, 00140 const LPoint3 &p1, const LPoint3 &p2) const; 00141 00142 protected: 00143 int _curve_type; 00144 int _num_dimensions; 00145 00146 private: 00147 typedef plist<ParametricCurveDrawer *> DrawerList; 00148 DrawerList _drawers; 00149 00150 // TypedWritable stuff 00151 protected: 00152 virtual void write_datagram(BamWriter *manager, Datagram &me); 00153 void fillin(DatagramIterator &scan, BamReader *manager); 00154 00155 public: 00156 static TypeHandle get_class_type() { 00157 return _type_handle; 00158 } 00159 static void init_type() { 00160 PandaNode::init_type(); 00161 register_type(_type_handle, "ParametricCurve", 00162 PandaNode::get_class_type()); 00163 } 00164 virtual TypeHandle get_type() const { 00165 return get_class_type(); 00166 } 00167 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00168 00169 private: 00170 static TypeHandle _type_handle; 00171 }; 00172 00173 #endif