Panda3D
 All Classes Functions Variables Enumerations
portalClipper.I
1 // Filename: portalClipper.I
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: PortalClipper::Point::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE PortalClipper::Point::
22 Point() {
23 }
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: PortalClipper::Point::Constructor
27 // Access: Public
28 // Description:
29 ////////////////////////////////////////////////////////////////////
30 INLINE PortalClipper::Point::
31 Point(const LVecBase3 &point, const LColor &color) :
32  _point(point[0], point[1], point[2]),
33  _color(color)
34 {
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: PortalClipper::Point::Copy Constructor
39 // Access: Public
40 // Description:
41 ////////////////////////////////////////////////////////////////////
42 INLINE PortalClipper::Point::
43 Point(const PortalClipper::Point &copy) :
44  _point(copy._point),
45  _color(copy._color)
46 {
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: PortalClipper::Point::Copy Assignment Operator
51 // Access: Public
52 // Description:
53 ////////////////////////////////////////////////////////////////////
54 INLINE void PortalClipper::Point::
55 operator = (const PortalClipper::Point &copy) {
56  _point = copy._point;
57  _color = copy._color;
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: PortalClipper::move_to
62 // Access: Public
63 // Description: Moves the pen to the given point without drawing a
64 // line. When followed by draw_to(), this marks the
65 // first point of a line segment; when followed by
66 // move_to() or create(), this creates a single point.
67 ////////////////////////////////////////////////////////////////////
68 INLINE void PortalClipper::
69 move_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
70  move_to(LVertex(x, y, z));
71 }
72 
73 ////////////////////////////////////////////////////////////////////
74 // Function: PortalClipper::draw_to
75 // Access: Public
76 // Description: Draws a line segment from the pen's last position
77 // (the last call to move_to or draw_to) to the
78 // indicated point. move_to() and draw_to() only update
79 // tables; the actual drawing is performed when create()
80 // is called.
81 ////////////////////////////////////////////////////////////////////
82 INLINE void PortalClipper::
83 draw_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
84  draw_to(LVertex(x, y, z));
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: PortalClipper::draw_camera_frustum
89 // Access: Public
90 // Description: Draw the current camera frustum in white color
91 //
92 ////////////////////////////////////////////////////////////////////
93 INLINE void PortalClipper::
95  _color = LColor(1,1,1,1);
96  draw_hexahedron(_view_frustum);
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: PortalClipper::set_reduced_frustum
101 // Access: Public
102 // Description: Set the current view frustum that is being calculated
103 // by the portal clipper
104 //
105 ////////////////////////////////////////////////////////////////////
106 INLINE void PortalClipper::
108  _reduced_frustum = frustum;
109 }
110 
111 ////////////////////////////////////////////////////////////////////
112 // Function: PortalClipper::get_reduced_frustum
113 // Access: Published
114 // Description: Return the reduced frustum
115 ////////////////////////////////////////////////////////////////////
118  return _reduced_frustum;
119 }
120 
121 ////////////////////////////////////////////////////////////////////
122 // Function: PortalClipper::set_clip_state
123 // Access: Public
124 // Description: Set the clip state of the current portal node
125 // This is done to remember the state for the child portal nodes
126 //
127 ////////////////////////////////////////////////////////////////////
128 INLINE void PortalClipper::
129 set_clip_state(const RenderState* clip_state) {
130  _clip_state = clip_state;
131 }
132 
133 ////////////////////////////////////////////////////////////////////
134 // Function: PortalClipper::get_clip_state
135 // Access: Published
136 // Description: Returns the stored clip state
137 ////////////////////////////////////////////////////////////////////
138 INLINE const RenderState *PortalClipper::
139 get_clip_state() const {
140  return _clip_state;
141 }
142 
143 ////////////////////////////////////////////////////////////////////
144 // Function: PortalClipper::set_reduced_viewport
145 // Access: Public
146 // Description: Set the current viewport that is being used
147 // by the portal clipper
148 //
149 ////////////////////////////////////////////////////////////////////
150 INLINE void PortalClipper::
151 set_reduced_viewport(const LPoint2& min, const LPoint2& max) {
152  _reduced_viewport_min = min;
153  _reduced_viewport_max = max;
154 }
155 
156 
157 ////////////////////////////////////////////////////////////////////
158 // Function: PortalClipper::get_reduced_viewport
159 // Access: Published
160 // Description: Return the reduced viewport
161 ////////////////////////////////////////////////////////////////////
162 INLINE void PortalClipper::
164  min = _reduced_viewport_min;
165  max = _reduced_viewport_max;
166 }
167 
168 
169 
170 ////////////////////////////////////////////////////////////////////
171 // Function: PortalClipper::is_facing_view
172 // Access: Public
173 // Description: checks if the portal plane (in camera space)
174 // is facing the camera's near plane
175 ////////////////////////////////////////////////////////////////////
176 INLINE bool PortalClipper::
177 is_facing_view(const LPlane &portal_plane) {
178  portal_cat.debug() << "portal plane check value: " << portal_plane[3] << "\n";
179  return (portal_plane[3] > 0);
180 }
181 
182 ////////////////////////////////////////////////////////////////////
183 // Function: PortalClipper::is_whole_portal_in_view
184 // Access: Public
185 // Description: checks if portal_node is within the view frustum.
186 // If so, then the portal is worth considering. This
187 // is a 2nd level test to weed out most of the portals
188 ////////////////////////////////////////////////////////////////////
189 INLINE bool PortalClipper::
191  // I am about to xform this gbv, so lets make a copy
192  const BoundingVolume *bv = _portal_node->get_bounds();
193  BoundingVolume *cbv = bv->make_copy();
195 
196  // trasform it to camera space
197  gbv->xform(cmat);
198 
199  int result = _reduced_frustum->contains(gbv);
200 
201  portal_cat.spam() << "1st level test if portal: " << *_reduced_frustum << " is in view " << result << endl;
202  return (result != 0);
203 }
204 
205 /*
206 ////////////////////////////////////////////////////////////////////
207 // Function: PortalClipper::is_partial_portal_in_view
208 // Access: Public
209 // Description: checks if any of the _coords is within the view frustum.
210 // If so, then the portal is facing the camera. 2nd level
211 // test to make sure this portal is worth visiting
212 ////////////////////////////////////////////////////////////////////
213 INLINE bool PortalClipper::
214 is_partial_portal_in_view() {
215  int result = 0;
216 
217  // check if any of the _coords in tested frustum
218  for (int j=0; j<_num_vert; ++j) {
219  result |= _reduced_frustum->contains(_coords[j]);
220  }
221  portal_cat.spam() << "frustum: " << *_reduced_frustum << " contains(coord) result = " << result << endl;
222 
223  return (result != 0);
224 }
225 */
226 
227 /*
228 ////////////////////////////////////////////////////////////////////
229 // Function: PortalClipper::get_plane_depth
230 // Access: Public
231 // Description: Given the x and z, solve for y: from the plane
232 ////////////////////////////////////////////////////////////////////
233 INLINE PN_stdfloat PortalClipper::
234 get_plane_depth(PN_stdfloat x, PN_stdfloat z, LPlane *portal_plane) {
235  PN_stdfloat y = 0.0;
236  // Plane equation: Ax + By + Cz + D = 0
237  // y = (Ax + Cz + D) / -B
238  portal_cat.spam() << *portal_plane << endl;
239  portal_cat.spam() << portal_plane->_v.v._0 << " " << portal_plane->_v.v._1 << " "
240  << portal_plane->_v.v._2 << " " << portal_plane->_v.v._3 << endl;
241 
242  if (portal_plane->_v.v._1 != 0.0) {
243  y = (((portal_plane->_v.v._0*x)+(portal_plane->_v.v._2*z)+portal_plane->_v.v._3)
244  / -(portal_plane->_v.v._1));
245  }
246  return y;
247 }
248 */
249 
void draw_camera_frustum()
Draw the current camera frustum in white color.
Definition: portalClipper.I:94
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
void get_reduced_viewport(LPoint2 &min, LPoint2 &max) const
Return the reduced viewport.
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:69
bool is_facing_view(const LPlane &portal_plane)
checks if the portal plane (in camera space) is facing the camera&#39;s near plane
void set_reduced_frustum(BoundingHexahedron *bh)
Set the current view frustum that is being calculated by the portal clipper.
int contains(const GeometricBoundingVolume *vol) const
Returns the appropriate set of IntersectionFlags to indicate the amount of intersection with the indi...
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 ...
const RenderState * get_clip_state() const
Returns the stored clip state.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
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
void draw_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Draws a line segment from the pen&#39;s last position (the last call to move_to or draw_to) to the indica...
Definition: portalClipper.I:83
bool is_whole_portal_in_view(const LMatrix4 &cmat)
checks if portal_node is within the view frustum.
This is a two-component point in space.
Definition: lpoint2.h:92
BoundingHexahedron * get_reduced_frustum() const
Return the reduced 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.