Panda3D
portalClipper.I
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 portalClipper.I
10  * @author masad
11  * @date 2004-05-04
12  */
13 
14 /**
15  *
16  */
17 INLINE PortalClipper::Point::
18 Point() {
19 }
20 
21 /**
22  *
23  */
24 INLINE PortalClipper::Point::
25 Point(const LVecBase3 &point, const LColor &color) :
26  _point(point[0], point[1], point[2]),
27  _color(color)
28 {
29 }
30 
31 /**
32  *
33  */
34 INLINE PortalClipper::Point::
35 Point(const PortalClipper::Point &copy) :
36  _point(copy._point),
37  _color(copy._color)
38 {
39 }
40 
41 /**
42  *
43  */
44 INLINE void PortalClipper::Point::
45 operator = (const PortalClipper::Point &copy) {
46  _point = copy._point;
47  _color = copy._color;
48 }
49 
50 /**
51  * Moves the pen to the given point without drawing a line. When followed by
52  * draw_to(), this marks the first point of a line segment; when followed by
53  * move_to() or create(), this creates a single point.
54  */
55 INLINE void PortalClipper::
56 move_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
57  move_to(LVertex(x, y, z));
58 }
59 
60 /**
61  * Draws a line segment from the pen's last position (the last call to move_to
62  * or draw_to) to the indicated point. move_to() and draw_to() only update
63  * tables; the actual drawing is performed when create() is called.
64  */
65 INLINE void PortalClipper::
66 draw_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
67  draw_to(LVertex(x, y, z));
68 }
69 
70 /**
71  * Draw the current camera frustum in white color
72  *
73  */
74 INLINE void PortalClipper::
76  _color = LColor(1,1,1,1);
77  draw_hexahedron(_view_frustum);
78 }
79 
80 /**
81  * Set the current view frustum that is being calculated by the portal clipper
82  *
83  */
84 INLINE void PortalClipper::
86  _reduced_frustum = frustum;
87 }
88 
89 /**
90  * Return the reduced frustum
91  */
94  return _reduced_frustum;
95 }
96 
97 /**
98  * Set the clip state of the current portal node This is done to remember the
99  * state for the child portal nodes
100  *
101  */
102 INLINE void PortalClipper::
103 set_clip_state(const RenderState* clip_state) {
104  _clip_state = clip_state;
105 }
106 
107 /**
108  * Returns the stored clip state
109  */
110 INLINE const RenderState *PortalClipper::
111 get_clip_state() const {
112  return _clip_state;
113 }
114 
115 /**
116  * Set the current viewport that is being used by the portal clipper
117  *
118  */
119 INLINE void PortalClipper::
120 set_reduced_viewport(const LPoint2& min, const LPoint2& max) {
121  _reduced_viewport_min = min;
122  _reduced_viewport_max = max;
123 }
124 
125 
126 /**
127  * Return the reduced viewport
128  */
129 INLINE void PortalClipper::
130 get_reduced_viewport(LPoint2& min, LPoint2& max) const {
131  min = _reduced_viewport_min;
132  max = _reduced_viewport_max;
133 }
134 
135 
136 
137 /**
138  * checks if the portal plane (in camera space) is facing the camera's near
139  * plane
140  */
141 INLINE bool PortalClipper::
142 is_facing_view(const LPlane &portal_plane) {
143  portal_cat.debug() << "portal plane check value: " << portal_plane[3] << "\n";
144  return (portal_plane[3] > 0);
145 }
146 
147 /**
148  * checks if portal_node is within the view frustum. If so, then the portal
149  * is worth considering. This is a 2nd level test to weed out most of the
150  * portals
151  */
152 INLINE bool PortalClipper::
153 is_whole_portal_in_view(const LMatrix4 &cmat) {
154  // I am about to xform this gbv, so lets make a copy
155  const BoundingVolume *bv = _portal_node->get_bounds();
156  BoundingVolume *cbv = bv->make_copy();
158 
159  // trasform it to camera space
160  gbv->xform(cmat);
161 
162  int result = _reduced_frustum->contains(gbv);
163 
164  portal_cat.spam() << "1st level test if portal: " << *_reduced_frustum << " is in view " << result << std::endl;
165  return (result != 0);
166 }
167 
168 /**
169  * checks if any of the _coords is within the view frustum. If so, then the
170  * portal is facing the camera. 2nd level test to make sure this portal is
171  * worth visiting
172  */
173 /*
174 INLINE bool PortalClipper::
175 is_partial_portal_in_view() {
176  int result = 0;
177 
178  // check if any of the _coords in tested frustum
179  for (int j=0; j<_num_vert; ++j) {
180  result |= _reduced_frustum->contains(_coords[j]);
181  }
182  portal_cat.spam() << "frustum: " << *_reduced_frustum << " contains(coord) result = " << result << endl;
183 
184  return (result != 0);
185 }
186 */
187 
188 /**
189  * Given the x and z, solve for y: from the plane
190  */
191 /*
192 INLINE PN_stdfloat PortalClipper::
193 get_plane_depth(PN_stdfloat x, PN_stdfloat z, LPlane *portal_plane) {
194  PN_stdfloat y = 0.0;
195  // Plane equation: Ax + By + Cz + D = 0 y = (Ax + Cz + D) -B
196  portal_cat.spam() << *portal_plane << endl;
197  portal_cat.spam() << portal_plane->_v.v._0 << " " << portal_plane->_v.v._1 << " "
198  << portal_plane->_v.v._2 << " " << portal_plane->_v.v._3 << endl;
199 
200  if (portal_plane->_v.v._1 != 0.0) {
201  y = (((portal_plane->_v.v._0*x)+(portal_plane->_v.v._2*z)+portal_plane->_v.v._3)
202  / -(portal_plane->_v.v._1));
203  }
204  return y;
205 }
206 */
void draw_camera_frustum()
Draw the current camera frustum in white color.
Definition: portalClipper.I:75
const RenderState * get_clip_state() const
Returns the stored clip state.
int contains(const GeometricBoundingVolume *vol) const
Returns the appropriate set of IntersectionFlags to indicate the amount of intersection with the indi...
void move_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Moves the pen to the given point without drawing a line.
Definition: portalClipper.I:56
bool is_facing_view(const LPlane &portal_plane)
checks if the portal plane (in camera space) is facing the camera's near plane
void set_reduced_frustum(BoundingHexahedron *bh)
Set the current view frustum that is being calculated by the portal clipper.
Definition: portalClipper.I:85
BoundingHexahedron * get_reduced_frustum() const
Return the reduced frustum.
Definition: portalClipper.I:93
void get_reduced_viewport(LPoint2 &min, LPoint2 &max) const
Return the reduced viewport.
void draw_hexahedron(BoundingHexahedron *frustum)
Given the BoundingHexahedron draw it using lines.
void set_clip_state(const RenderState *clip_state)
Set the clip state of the current portal node This is done to remember the state for the child portal...
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:47
void draw_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Draws a line segment from the pen's last position (the last call to move_to or draw_to) to the indica...
Definition: portalClipper.I:66
bool is_whole_portal_in_view(const LMatrix4 &cmat)
checks if portal_node is within the view frustum.
void set_reduced_viewport(const LPoint2 &min, const LPoint2 &max)
Set the current viewport that is being used by the portal clipper.
This defines a bounding convex hexahedron.