Panda3D
|
00001 // Filename: portalNode.h 00002 // Created by: masad (13May04) 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 PORTALNODE_H 00016 #define PORTALNODE_H 00017 00018 #include "pandabase.h" 00019 00020 #include "portalMask.h" 00021 #include "pandaNode.h" 00022 #include "planeNode.h" 00023 #include "nodePath.h" 00024 #include "pvector.h" 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Class : PortalNode 00028 // Description : A node in the scene graph that can hold a 00029 // Portal Polygon, which is a rectangle. Other 00030 // types of polygons are not supported for 00031 // now. It also holds a PT(PandaNode) Cell that 00032 // this portal is connected to 00033 //////////////////////////////////////////////////////////////////// 00034 class EXPCL_PANDA_PGRAPH PortalNode : public PandaNode { 00035 PUBLISHED: 00036 PortalNode(const string &name); 00037 PortalNode(const string &name, LPoint3 pos, PN_stdfloat scale=10.0); 00038 00039 protected: 00040 PortalNode(const PortalNode ©); 00041 00042 public: 00043 virtual ~PortalNode(); 00044 virtual PandaNode *make_copy() const; 00045 virtual bool preserve_name() const; 00046 virtual void xform(const LMatrix4 &mat); 00047 virtual PandaNode *combine_with(PandaNode *other); 00048 00049 virtual void enable_clipping_planes(); 00050 00051 virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data); 00052 virtual bool is_renderable() const; 00053 00054 virtual void output(ostream &out) const; 00055 00056 PUBLISHED: 00057 INLINE void set_portal_mask(PortalMask mask); 00058 INLINE void set_from_portal_mask(PortalMask mask); 00059 INLINE void set_into_portal_mask(PortalMask mask); 00060 INLINE PortalMask get_from_portal_mask() const; 00061 INLINE PortalMask get_into_portal_mask() const; 00062 00063 INLINE void set_portal_geom(bool flag); 00064 INLINE bool get_portal_geom() const; 00065 00066 INLINE void clear_vertices(); 00067 INLINE void add_vertex(const LPoint3 &vertex); 00068 00069 INLINE int get_num_vertices() const; 00070 INLINE const LPoint3 &get_vertex(int n) const; 00071 MAKE_SEQ(get_vertices, get_num_vertices, get_vertex); 00072 00073 INLINE void set_cell_in(const NodePath &cell); 00074 INLINE NodePath get_cell_in() const; 00075 00076 INLINE void set_cell_out(const NodePath &cell); 00077 INLINE NodePath get_cell_out() const; 00078 00079 INLINE void set_clip_plane(bool value); 00080 INLINE bool is_clip_plane(); 00081 00082 INLINE void set_visible(bool value); 00083 INLINE bool is_visible(); 00084 00085 INLINE void set_max_depth(int value); 00086 INLINE int get_max_depth(); 00087 00088 INLINE void set_open(bool value); 00089 INLINE bool is_open(); 00090 00091 // void draw () const; 00092 00093 protected: 00094 virtual void compute_internal_bounds(CPT(BoundingVolume) &internal_bounds, 00095 int &internal_vertices, 00096 int pipeline_stage, 00097 Thread *current_thread) const; 00098 00099 private: 00100 CPT(RenderState) get_last_pos_state(); 00101 00102 // This data is not cycled, for now. We assume the collision 00103 // traversal will take place in App only. Perhaps we will revisit 00104 // this later. 00105 PortalMask _from_portal_mask; 00106 PortalMask _into_portal_mask; 00107 00108 enum Flags { 00109 F_portal_geom = 0x0001, 00110 // Presently only 8 bits are written to the bam file. 00111 }; 00112 int _flags; 00113 00114 typedef pvector<LPoint3> Vertices; 00115 Vertices _vertices; 00116 00117 NodePath _cell_in; // This is the cell it resides in 00118 NodePath _cell_out; // This is the cell it leads out to 00119 00120 // enable plane clipping on this portal 00121 bool _clip_plane; 00122 PT(PlaneNode) _left_plane_node; 00123 PT(PlaneNode) _right_plane_node; 00124 PT(PlaneNode) _top_plane_node; 00125 PT(PlaneNode) _bottom_plane_node; 00126 CPT(RenderState) _clip_state; 00127 00128 bool _visible; 00129 bool _open; 00130 int _max_depth; 00131 00132 public: 00133 static void register_with_read_factory(); 00134 virtual void write_datagram(BamWriter *manager, Datagram &dg); 00135 virtual int complete_pointers(TypedWritable **plist, BamReader *manager); 00136 00137 protected: 00138 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00139 void fillin(DatagramIterator &scan, BamReader *manager); 00140 00141 public: 00142 static TypeHandle get_class_type() { 00143 return _type_handle; 00144 } 00145 static void init_type() { 00146 PandaNode::init_type(); 00147 register_type(_type_handle, "PortalNode", 00148 PandaNode::get_class_type()); 00149 } 00150 virtual TypeHandle get_type() const { 00151 return get_class_type(); 00152 } 00153 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00154 00155 private: 00156 static TypeHandle _type_handle; 00157 }; 00158 00159 #include "portalNode.I" 00160 00161 #endif