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