Panda3D
Loading...
Searching...
No Matches
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 */
30class EXPCL_PANDA_PGRAPH PortalNode : public PandaNode {
31PUBLISHED:
32 explicit PortalNode(const std::string &name);
33 explicit PortalNode(const std::string &name, LPoint3 pos, PN_stdfloat scale=10.0);
34
35protected:
36 PortalNode(const PortalNode &copy);
37
38public:
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
52PUBLISHED:
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
100protected:
101 virtual void compute_internal_bounds(CPT(BoundingVolume) &internal_bounds,
102 int &internal_vertices,
103 int pipeline_stage,
104 Thread *current_thread) const;
105
106private:
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
138public:
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
143protected:
144 static TypedWritable *make_from_bam(const FactoryParams &params);
145 void fillin(DatagramIterator &scan, BamReader *manager);
146
147public:
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
161private:
162 static TypeHandle _type_handle;
163};
164
165#include "portalNode.I"
166
167#endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
An instance of this class is passed to the Factory when requesting it to do its business and construc...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
virtual bool preserve_name() const
Returns true if the node's name has extrinsic meaning and must be preserved across a flatten operatio...
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
virtual PandaNode * combine_with(PandaNode *other)
Collapses this PandaNode with the other PandaNode, if possible, and returns a pointer to the combined...
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
static void register_with_read_factory()
Tells the BamReader how to create objects of type PandaNode.
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this PandaNode by the indicated matrix, if it means anything to do so.
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
A node that contains a plane.
Definition planeNode.h:36
get_vertex
Returns the nth vertex of the portal polygon.
Definition portalNode.h:67
get_into_portal_mask
Returns the current "into" PortalMask.
Definition portalNode.h:89
set_from_portal_mask
Sets the "from" PortalMask.
Definition portalNode.h:90
set_open
Python sets this based on curent camera zone.
Definition portalNode.h:98
get_portal_geom
Returns the current state of the portal_geom flag.
Definition portalNode.h:91
is_visible
Is this portal facing the camera.
Definition portalNode.h:96
void add_vertex(const LPoint3 &vertex)
Adds a new vertex to the portal polygon.
Definition portalNode.I:109
set_cell_in
Sets the cell that this portal belongs to.
Definition portalNode.h:93
is_clip_plane
Is this portal clipping against its left-right planes.
Definition portalNode.h:95
get_num_vertices
Returns the number of vertices in the portal polygon.
Definition portalNode.h:67
virtual void enable_clipping_planes()
initialize the clipping planes and renderstate
set_into_portal_mask
Sets the "into" PortalMask.
Definition portalNode.h:89
set_visible
this is set if the portal is facing camera
Definition portalNode.h:96
set_portal_geom
Sets the state of the "portal geom" flag for this PortalNode.
Definition portalNode.h:91
set_cell_out
Sets the cell that this portal leads out to.
Definition portalNode.h:94
get_from_portal_mask
Returns the current "from" PortalMask.
Definition portalNode.h:90
set_max_depth
Set the maximum depth this portal will be visible at.
Definition portalNode.h:97
PortalNode(const std::string &name)
Default constructor, just an empty node, no geo This is used to read portal from model.
get_cell_out
Sets the cell that this portal leads out to.
Definition portalNode.h:94
get_cell_in
Sets the cell that this portal belongs to.
Definition portalNode.h:93
void clear_vertices()
Resets the vertices of the portal to the empty list.
Definition portalNode.I:100
get_max_depth
Returns the maximum depth this portal will be visible at.
Definition portalNode.h:97
is_open
Is this portal open from current camera zone.
Definition portalNode.h:98
virtual void output(std::ostream &out) const
Writes a brief description of the node to the indicated output stream.
set_clip_plane
this is set if the portal will clip against its left and right planes
Definition portalNode.h:95
void set_portal_mask(PortalMask mask)
Simultaneously sets both the "from" and "into" PortalMask values to the same thing.
Definition portalNode.I:19
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
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
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 our own Panda specialization on the default STL list.
Definition plist.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...