Panda3D
 All Classes Functions Variables Enumerations
planeNode.h
00001 // Filename: planeNode.h
00002 // Created by:  drose (11Jul02)
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 PLANENODE_H
00016 #define PLANENODE_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "plane.h"
00021 #include "pandaNode.h"
00022 #include "updateSeq.h"
00023 #include "geom.h"
00024 #include "cycleData.h"
00025 #include "cycleDataLockedReader.h"
00026 #include "cycleDataReader.h"
00027 #include "cycleDataWriter.h"
00028 #include "cycleDataStageReader.h"
00029 #include "cycleDataStageWriter.h"
00030 #include "pipelineCycler.h"
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 //       Class : PlaneNode
00034 // Description : A node that contains a plane.  This is most often
00035 //               used as a clipping plane, but it can serve other
00036 //               purposes as well; whenever a plane is needed to be
00037 //               defined in some coordinate space in the world.
00038 ////////////////////////////////////////////////////////////////////
00039 class EXPCL_PANDA_PGRAPH PlaneNode : public PandaNode {
00040 PUBLISHED:
00041   PlaneNode(const string &name, const LPlane &plane = LPlane());
00042 
00043 protected:
00044   PlaneNode(const PlaneNode &copy);
00045 public:
00046   virtual void output(ostream &out) const;
00047 
00048   virtual PandaNode *make_copy() const;
00049   virtual void xform(const LMatrix4 &mat);
00050 
00051   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
00052   virtual bool is_renderable() const;
00053 
00054 PUBLISHED:
00055   INLINE void set_plane(const LPlane &plane);
00056   INLINE const LPlane &get_plane() const;
00057 
00058   INLINE void set_viz_scale(PN_stdfloat viz_scale);
00059   INLINE PN_stdfloat get_viz_scale() const;
00060 
00061   INLINE void set_priority(int priority);
00062   INLINE int get_priority() const;
00063 
00064   enum ClipEffect {
00065     CE_visible    = 0x0001,
00066     CE_collision  = 0x0002,
00067   };
00068   INLINE void set_clip_effect(int clip_effect);
00069   INLINE int get_clip_effect() const;
00070 
00071 public:
00072   INLINE static UpdateSeq get_sort_seq();
00073 
00074 protected:
00075   virtual void compute_internal_bounds(CPT(BoundingVolume) &internal_bounds,
00076                                        int &internal_vertices,
00077                                        int pipeline_stage,
00078                                        Thread *current_thread) const;
00079   PT(Geom) get_viz(CullTraverser *trav, CullTraverserData &data);
00080   
00081 private:
00082   // The priority is not cycled, because there's no real reason to do
00083   // so, and cycling it makes it difficult to synchronize with the
00084   // ClipPlaneAttribs.
00085   int _priority;
00086   int _clip_effect;
00087   static UpdateSeq _sort_seq;
00088 
00089   // This is the data that must be cycled between pipeline stages.
00090   class EXPCL_PANDA_PGRAPH CData : public CycleData {
00091   public:
00092     INLINE CData();
00093     INLINE CData(const CData &copy);
00094     virtual CycleData *make_copy() const;
00095     virtual void write_datagram(BamWriter *manager, Datagram &dg) const;
00096     virtual void fillin(DatagramIterator &scan, BamReader *manager);
00097     virtual TypeHandle get_parent_type() const {
00098       return PlaneNode::get_class_type();
00099     }
00100 
00101     LPlane _plane;
00102     PT(Geom) _front_viz, _back_viz;
00103     PN_stdfloat _viz_scale;
00104   };
00105 
00106   PipelineCycler<CData> _cycler;
00107   typedef CycleDataLockedReader<CData> CDLockedReader;
00108   typedef CycleDataReader<CData> CDReader;
00109   typedef CycleDataWriter<CData> CDWriter;
00110   typedef CycleDataStageReader<CData> CDStageReader;
00111   typedef CycleDataStageWriter<CData> CDStageWriter;
00112 
00113 public:
00114   static void register_with_read_factory();
00115   virtual void write_datagram(BamWriter *manager, Datagram &dg);
00116 
00117 protected:
00118   static TypedWritable *make_from_bam(const FactoryParams &params);
00119   void fillin(DatagramIterator &scan, BamReader *manager);
00120 
00121 public:
00122   static TypeHandle get_class_type() {
00123     return _type_handle;
00124   }
00125   static void init_type() {
00126     PandaNode::init_type();
00127     register_type(_type_handle, "PlaneNode",
00128                   PandaNode::get_class_type());
00129   }
00130   virtual TypeHandle get_type() const {
00131     return get_class_type();
00132   }
00133   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00134 
00135 private:
00136   static TypeHandle _type_handle;
00137 };
00138 
00139 #include "planeNode.I"
00140 
00141 #endif
 All Classes Functions Variables Enumerations