Panda3D
portalClipper.h
1 // Filename: portalClipper.h
2 // Created by: masad (4May04)
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 PORTALCLIPPER_H
16 #define PORTALCLIPPER_H
17 
18 #include "pandabase.h"
19 
20 #include "geom.h"
21 #include "geomVertexData.h"
22 #include "sceneSetup.h"
23 #include "renderState.h"
24 #include "portalNode.h"
25 #include "transformState.h"
26 #include "geometricBoundingVolume.h"
27 #include "boundingHexahedron.h"
28 #include "pointerTo.h"
29 #include "drawMask.h"
30 #include "typedObject.h"
31 #include "pStatCollector.h"
32 #include "config_pgraph.h"
33 
34 #include "geom.h"
35 #include "geomNode.h"
36 
37 class PandaNode;
38 class PortalNode;
39 class CullHandler;
40 class CullTraverserData;
41 class CullableObject;
42 class NodePath;
43 
44 ////////////////////////////////////////////////////////////////////
45 // Class : PortalClipper
46 // Description : This object performs a depth-first traversal of the
47 // scene graph, with optional view-frustum culling,
48 // collecting CullState and searching for GeomNodes.
49 // Each renderable Geom encountered is passed along with
50 // its associated RenderState to the CullHandler object.
51 ////////////////////////////////////////////////////////////////////
52 class EXPCL_PANDA_PGRAPH PortalClipper : public TypedObject {
53 public:
54  PortalClipper(GeometricBoundingVolume *frustum, SceneSetup *scene_setup);
55  ~PortalClipper();
56 
57  INLINE bool is_partial_portal_in_view();
58  INLINE bool is_facing_view(const LPlane &portal_plane);
59  INLINE bool is_whole_portal_in_view(const LMatrix4 &cmat);
60 
61  bool prepare_portal(const NodePath &node_path);
62 
63  void draw_lines();
64  INLINE void draw_camera_frustum();
65  void draw_hexahedron(BoundingHexahedron *frustum);
66 
67  INLINE void move_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
68  void move_to(const LVecBase3 &v);
69 
70  INLINE void draw_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
71  void draw_to(const LVecBase3 &v);
72 
73  void draw_current_portal();
74 
75  INLINE BoundingHexahedron *get_reduced_frustum() const;
76  INLINE void set_reduced_frustum(BoundingHexahedron *bh);
77  INLINE void get_reduced_viewport(LPoint2& min, LPoint2& max) const;
78  INLINE void set_reduced_viewport(const LPoint2& min, const LPoint2& max);
79  INLINE const RenderState* get_clip_state() const;
80  INLINE void set_clip_state(const RenderState* clip_state);
81 
82 public:
83  static TypeHandle get_class_type() {
84  return _type_handle;
85  }
86  static void init_type() {
88  register_type(_type_handle, "PortalClipper",
89  TypedObject::get_class_type());
90  }
91  virtual TypeHandle get_type() const {
92  return get_class_type();
93  }
94  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
95 
96 private:
97  static TypeHandle _type_handle;
98 
99 private:
100  class Point {
101  public:
102  INLINE Point();
103  INLINE Point(const LVecBase3 &point, const LColor &color);
104  INLINE Point(const Point &copy);
105  INLINE void operator = (const Point &copy);
106 
107  LVertex _point;
108  UnalignedLVecBase4 _color;
109  };
110 
111  typedef pvector<Point> SegmentList;
113 
114  LineList _list;
115  LColor _color;
116 
117  PT(GeomVertexData) _created_data;
118 
119  BoundingHexahedron *_view_frustum;
120  BoundingHexahedron *_reduced_frustum;
121  LPoint2 _reduced_viewport_min;
122  LPoint2 _reduced_viewport_max;
123  CPT(RenderState) _clip_state; // each portal node needs to know the clip state of its "parent" portal Node
124 
125  PortalNode *_portal_node; // current working portal for dereference ease
126 
127  //int _num_vert;
128  //LVertex _coords[4];
129 
130 public:
131  PT(GeomNode) _previous;
132  SceneSetup *_scene_setup;
133 };
134 
135 #include "portalClipper.I"
136 
137 #endif
138 
139 
140 
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
static void init_type()
This function is declared non-inline to work around a compiler bug in g++ 2.96.
Definition: typedObject.cxx:52
This is an "unaligned" LVecBase4.
Definition: lvecBase4.h:300
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
Definition: typedObject.h:98
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
A node in the scene graph that can hold a Portal Polygon, which is a rectangle.
Definition: portalNode.h:34
This defines the abstract interface for an object that receives Geoms identified by the CullTraverser...
Definition: cullHandler.h:31
The smallest atom of cull.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: portalClipper.h:52
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
This is a two-component point in space.
Definition: lpoint2.h:92
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This object holds the camera position, etc., and other general setup information for rendering a part...
Definition: sceneSetup.h:35
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:37
This defines a bounding convex hexahedron.