Panda3D
portalNode.h
1 // Filename: portalNode.h
2 // Created by: masad (13May04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PORTALNODE_H
16 #define PORTALNODE_H
17 
18 #include "pandabase.h"
19 
20 #include "portalMask.h"
21 #include "pandaNode.h"
22 #include "planeNode.h"
23 #include "nodePath.h"
24 #include "pvector.h"
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : PortalNode
28 // Description : A node in the scene graph that can hold a
29 // Portal Polygon, which is a rectangle. Other
30 // types of polygons are not supported for
31 // now. It also holds a PT(PandaNode) Cell that
32 // this portal is connected to
33 ////////////////////////////////////////////////////////////////////
34 class EXPCL_PANDA_PGRAPH PortalNode : public PandaNode {
35 PUBLISHED:
36  PortalNode(const string &name);
37  PortalNode(const string &name, LPoint3 pos, PN_stdfloat scale=10.0);
38 
39 protected:
40  PortalNode(const PortalNode &copy);
41 
42 public:
43  virtual ~PortalNode();
44  virtual PandaNode *make_copy() const;
45  virtual bool preserve_name() const;
46  virtual void xform(const LMatrix4 &mat);
47  virtual PandaNode *combine_with(PandaNode *other);
48 
49  virtual void enable_clipping_planes();
50 
51  virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
52  virtual bool is_renderable() const;
53 
54  virtual void output(ostream &out) const;
55 
56 PUBLISHED:
57  INLINE void set_portal_mask(PortalMask mask);
58  INLINE void set_from_portal_mask(PortalMask mask);
59  INLINE void set_into_portal_mask(PortalMask mask);
60  INLINE PortalMask get_from_portal_mask() const;
61  INLINE PortalMask get_into_portal_mask() const;
62 
63  INLINE void set_portal_geom(bool flag);
64  INLINE bool get_portal_geom() const;
65 
66  INLINE void clear_vertices();
67  INLINE void add_vertex(const LPoint3 &vertex);
68 
69  INLINE int get_num_vertices() const;
70  INLINE const LPoint3 &get_vertex(int n) const;
71  MAKE_SEQ(get_vertices, get_num_vertices, get_vertex);
72 
73  INLINE void set_cell_in(const NodePath &cell);
74  INLINE NodePath get_cell_in() const;
75 
76  INLINE void set_cell_out(const NodePath &cell);
77  INLINE NodePath get_cell_out() const;
78 
79  INLINE void set_clip_plane(bool value);
80  INLINE bool is_clip_plane();
81 
82  INLINE void set_visible(bool value);
83  INLINE bool is_visible();
84 
85  INLINE void set_max_depth(int value);
86  INLINE int get_max_depth();
87 
88  INLINE void set_open(bool value);
89  INLINE bool is_open();
90 
91  // void draw () const;
92 
93 protected:
94  virtual void compute_internal_bounds(CPT(BoundingVolume) &internal_bounds,
95  int &internal_vertices,
96  int pipeline_stage,
97  Thread *current_thread) const;
98 
99 private:
100  CPT(RenderState) get_last_pos_state();
101 
102  // This data is not cycled, for now. We assume the collision
103  // traversal will take place in App only. Perhaps we will revisit
104  // this later.
105  PortalMask _from_portal_mask;
106  PortalMask _into_portal_mask;
107 
108  enum Flags {
109  F_portal_geom = 0x0001,
110  // Presently only 8 bits are written to the bam file.
111  };
112  int _flags;
113 
114  typedef pvector<LPoint3> Vertices;
115  Vertices _vertices;
116 
117  NodePath _cell_in; // This is the cell it resides in
118  NodePath _cell_out; // This is the cell it leads out to
119 
120  // enable plane clipping on this portal
121  bool _clip_plane;
122  PT(PlaneNode) _left_plane_node;
123  PT(PlaneNode) _right_plane_node;
124  PT(PlaneNode) _top_plane_node;
125  PT(PlaneNode) _bottom_plane_node;
126  CPT(RenderState) _clip_state;
127 
128  bool _visible;
129  bool _open;
130  int _max_depth;
131 
132 public:
133  static void register_with_read_factory();
134  virtual void write_datagram(BamWriter *manager, Datagram &dg);
135  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
136 
137 protected:
138  static TypedWritable *make_from_bam(const FactoryParams &params);
139  void fillin(DatagramIterator &scan, BamReader *manager);
140 
141 public:
142  static TypeHandle get_class_type() {
143  return _type_handle;
144  }
145  static void init_type() {
146  PandaNode::init_type();
147  register_type(_type_handle, "PortalNode",
148  PandaNode::get_class_type());
149  }
150  virtual TypeHandle get_type() const {
151  return get_class_type();
152  }
153  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
154 
155 private:
156  static TypeHandle _type_handle;
157 };
158 
159 #include "portalNode.I"
160 
161 #endif
virtual bool preserve_name() const
Returns true if the node&#39;s name has extrinsic meaning and must be preserved across a flatten operatio...
Definition: pandaNode.cxx:319
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: pandaNode.cxx:4164
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
virtual PandaNode * combine_with(PandaNode *other)
Collapses this PandaNode with the other PandaNode, if possible, and returns a pointer to the combined...
Definition: pandaNode.cxx:397
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is our own Panda specialization on the default STL list.
Definition: plist.h:38
static void register_with_read_factory()
Tells the BamReader how to create objects of type PandaNode.
Definition: pandaNode.cxx:4153
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this PandaNode by the indicated matrix, if it means anything to do so...
Definition: pandaNode.cxx:377
A node in the scene graph that can hold a Portal Polygon, which is a rectangle.
Definition: portalNode.h:34
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:604
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
A thread; that is, a lightweight process.
Definition: thread.h:51
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
Definition: pandaNode.cxx:578
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48
A node that contains a plane.
Definition: planeNode.h:39