Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/parametrics/ropeNode.h

Go to the documentation of this file.
00001 // Filename: ropeNode.h
00002 // Created by:  drose (04Dec02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef ROPENODE_H
00020 #define ROPENODE_H
00021 
00022 #include "pandabase.h"
00023 #include "nurbsCurveEvaluator.h"
00024 #include "pandaNode.h"
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //       Class : RopeNode
00028 // Description : This class draws a visible representation of the
00029 //               NURBS curve stored in its NurbsCurveEvaluator.  It
00030 //               automatically recomputes the curve every frame.
00031 //
00032 //               This is not related to NurbsCurve, ClassicNurbsCurve,
00033 //               CubicCurveseg or any of the ParametricCurve-derived
00034 //               objects in this module.  It is a completely parallel
00035 //               implementation of NURBS curves, and will probably
00036 //               eventually replace the whole ParametricCurve class
00037 //               hierarchy.
00038 ////////////////////////////////////////////////////////////////////
00039 class EXPCL_PANDA RopeNode : public PandaNode {
00040 PUBLISHED:
00041   RopeNode(const string &name);
00042 
00043 protected:
00044   RopeNode(const RopeNode &copy);
00045 public:
00046   virtual void output(ostream &out) const;
00047   virtual void write(ostream &out, int indent_level = 0) const;
00048 
00049   virtual PandaNode *make_copy() const;
00050 
00051   virtual bool safe_to_transform() const;
00052   virtual bool has_cull_callback() const;
00053   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
00054 
00055 PUBLISHED:
00056   enum RenderMode {
00057     // Render the rope as a one-pixel thread using a linestrip.
00058     RM_thread,
00059 
00060     // Render the rope as a continuous triangle strip oriented to be
00061     // perpendicular to the view vector.
00062     RM_billboard
00063   };
00064 
00065   enum UVMode {
00066     // Don't generate UV's along the curve.
00067     UV_none,
00068 
00069     // Generate UV's based on the parametric coordinates along the
00070     // curve.
00071     UV_parametric,
00072 
00073     // Generate UV's in proportion to spatial distance along the
00074     // curve, by using the distance function to compute the length of
00075     // each segment.
00076     UV_distance,
00077 
00078     // As above, but don't bother to take the square root of each
00079     // segment.  The distance is then in proportion to the
00080     // sum-of-squares of the segments along the rope.  If the segments
00081     // are similar in length, this approximates the proportion of
00082     // UV_distance while avoiding hundreds of square root operations.
00083     UV_distance2,
00084   };
00085 
00086   INLINE void set_curve(NurbsCurveEvaluator *curve);
00087   INLINE NurbsCurveEvaluator *get_curve() const;
00088 
00089   INLINE void set_render_mode(RenderMode render_mode);
00090   INLINE RenderMode get_render_mode() const;
00091 
00092   INLINE void set_uv_mode(UVMode uv_mode);
00093   INLINE UVMode get_uv_mode() const;
00094 
00095   INLINE void set_uv_scale(const LVecBase2f &uv_scale);
00096   INLINE const LVecBase2f &get_uv_scale() const;
00097 
00098   INLINE void set_num_segs(int num_segs);
00099   INLINE int get_num_segs() const;
00100 
00101   INLINE void set_thickness(float thickness);
00102   INLINE float get_thickness() const;
00103 
00104   void reset_bound(const NodePath &rel_to);
00105 
00106 protected:
00107   virtual BoundingVolume *recompute_internal_bound();
00108 
00109 private:
00110   BoundingVolume *do_recompute_bound(const NodePath &rel_to);
00111   void render_thread(CullTraverser *trav, CullTraverserData &data, 
00112                      NurbsCurveResult *result);
00113   void render_billboard(CullTraverser *trav, CullTraverserData &data, 
00114                         NurbsCurveResult *result);
00115 
00116 private:
00117   // This is the data that must be cycled between pipeline stages.
00118   class EXPCL_PANDA CData : public CycleData {
00119   public:
00120     INLINE CData();
00121     INLINE CData(const CData &copy);
00122     virtual CycleData *make_copy() const;
00123     virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
00124     virtual void fillin(DatagramIterator &scan, BamReader *manager);
00125 
00126     PT(NurbsCurveEvaluator) _curve;
00127     RenderMode _render_mode;
00128     UVMode _uv_mode;
00129     LVecBase2f _uv_scale;
00130     int _num_segs;
00131     float _thickness;
00132   };
00133 
00134   PipelineCycler<CData> _cycler;
00135   typedef CycleDataReader<CData> CDReader;
00136   typedef CycleDataWriter<CData> CDWriter;
00137 
00138 public:
00139   static void register_with_read_factory();
00140   virtual void write_datagram(BamWriter *manager, Datagram &dg);
00141 
00142 protected:
00143   static TypedWritable *make_from_bam(const FactoryParams &params);
00144   void fillin(DatagramIterator &scan, BamReader *manager);
00145 
00146 public:
00147   static TypeHandle get_class_type() {
00148     return _type_handle;
00149   }
00150   static void init_type() {
00151     PandaNode::init_type();
00152     register_type(_type_handle, "RopeNode",
00153                   PandaNode::get_class_type());
00154   }
00155   virtual TypeHandle get_type() const {
00156     return get_class_type();
00157   }
00158   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00159 
00160 private:
00161   static TypeHandle _type_handle;
00162 };
00163 
00164 #include "ropeNode.I"
00165 
00166 #endif

Generated on Fri May 2 00:40:54 2003 for Panda by doxygen1.3