Panda3D
|
00001 // Filename: portalClipper.I 00002 // Created by: masad (4May04) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: PortalClipper::Point::Constructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE PortalClipper::Point:: 00022 Point() { 00023 } 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: PortalClipper::Point::Constructor 00027 // Access: Public 00028 // Description: 00029 //////////////////////////////////////////////////////////////////// 00030 INLINE PortalClipper::Point:: 00031 Point(const LVecBase3 &point, const LColor &color) : 00032 _point(point[0], point[1], point[2]), 00033 _color(color) 00034 { 00035 } 00036 00037 //////////////////////////////////////////////////////////////////// 00038 // Function: PortalClipper::Point::Copy Constructor 00039 // Access: Public 00040 // Description: 00041 //////////////////////////////////////////////////////////////////// 00042 INLINE PortalClipper::Point:: 00043 Point(const PortalClipper::Point ©) : 00044 _point(copy._point), 00045 _color(copy._color) 00046 { 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function: PortalClipper::Point::Copy Assignment Operator 00051 // Access: Public 00052 // Description: 00053 //////////////////////////////////////////////////////////////////// 00054 INLINE void PortalClipper::Point:: 00055 operator = (const PortalClipper::Point ©) { 00056 _point = copy._point; 00057 _color = copy._color; 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function: PortalClipper::move_to 00062 // Access: Public 00063 // Description: Moves the pen to the given point without drawing a 00064 // line. When followed by draw_to(), this marks the 00065 // first point of a line segment; when followed by 00066 // move_to() or create(), this creates a single point. 00067 //////////////////////////////////////////////////////////////////// 00068 INLINE void PortalClipper:: 00069 move_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) { 00070 move_to(LVertex(x, y, z)); 00071 } 00072 00073 //////////////////////////////////////////////////////////////////// 00074 // Function: PortalClipper::draw_to 00075 // Access: Public 00076 // Description: Draws a line segment from the pen's last position 00077 // (the last call to move_to or draw_to) to the 00078 // indicated point. move_to() and draw_to() only update 00079 // tables; the actual drawing is performed when create() 00080 // is called. 00081 //////////////////////////////////////////////////////////////////// 00082 INLINE void PortalClipper:: 00083 draw_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) { 00084 draw_to(LVertex(x, y, z)); 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: PortalClipper::draw_camera_frustum 00089 // Access: Public 00090 // Description: Draw the current camera frustum in white color 00091 // 00092 //////////////////////////////////////////////////////////////////// 00093 INLINE void PortalClipper:: 00094 draw_camera_frustum() { 00095 _color = LColor(1,1,1,1); 00096 draw_hexahedron(_view_frustum); 00097 } 00098 00099 //////////////////////////////////////////////////////////////////// 00100 // Function: PortalClipper::set_reduced_frustum 00101 // Access: Public 00102 // Description: Set the current view frustum that is being calculated 00103 // by the portal clipper 00104 // 00105 //////////////////////////////////////////////////////////////////// 00106 INLINE void PortalClipper:: 00107 set_reduced_frustum(BoundingHexahedron *frustum) { 00108 _reduced_frustum = frustum; 00109 } 00110 00111 //////////////////////////////////////////////////////////////////// 00112 // Function: PortalClipper::get_reduced_frustum 00113 // Access: Published 00114 // Description: Return the reduced frustum 00115 //////////////////////////////////////////////////////////////////// 00116 INLINE BoundingHexahedron *PortalClipper:: 00117 get_reduced_frustum() const { 00118 return _reduced_frustum; 00119 } 00120 00121 //////////////////////////////////////////////////////////////////// 00122 // Function: PortalClipper::set_clip_state 00123 // Access: Public 00124 // Description: Set the clip state of the current portal node 00125 // This is done to remember the state for the child portal nodes 00126 // 00127 //////////////////////////////////////////////////////////////////// 00128 INLINE void PortalClipper:: 00129 set_clip_state(const RenderState* clip_state) { 00130 _clip_state = clip_state; 00131 } 00132 00133 //////////////////////////////////////////////////////////////////// 00134 // Function: PortalClipper::get_clip_state 00135 // Access: Published 00136 // Description: Returns the stored clip state 00137 //////////////////////////////////////////////////////////////////// 00138 INLINE const RenderState *PortalClipper:: 00139 get_clip_state() const { 00140 return _clip_state; 00141 } 00142 00143 //////////////////////////////////////////////////////////////////// 00144 // Function: PortalClipper::set_reduced_viewport 00145 // Access: Public 00146 // Description: Set the current viewport that is being used 00147 // by the portal clipper 00148 // 00149 //////////////////////////////////////////////////////////////////// 00150 INLINE void PortalClipper:: 00151 set_reduced_viewport(const LPoint2& min, const LPoint2& max) { 00152 _reduced_viewport_min = min; 00153 _reduced_viewport_max = max; 00154 } 00155 00156 00157 //////////////////////////////////////////////////////////////////// 00158 // Function: PortalClipper::get_reduced_viewport 00159 // Access: Published 00160 // Description: Return the reduced viewport 00161 //////////////////////////////////////////////////////////////////// 00162 INLINE void PortalClipper:: 00163 get_reduced_viewport(LPoint2& min, LPoint2& max) const { 00164 min = _reduced_viewport_min; 00165 max = _reduced_viewport_max; 00166 } 00167 00168 00169 00170 //////////////////////////////////////////////////////////////////// 00171 // Function: PortalClipper::is_facing_view 00172 // Access: Public 00173 // Description: checks if the portal plane (in camera space) 00174 // is facing the camera's near plane 00175 //////////////////////////////////////////////////////////////////// 00176 INLINE bool PortalClipper:: 00177 is_facing_view(const LPlane &portal_plane) { 00178 portal_cat.debug() << "portal plane check value: " << portal_plane[3] << "\n"; 00179 return (portal_plane[3] > 0); 00180 } 00181 00182 //////////////////////////////////////////////////////////////////// 00183 // Function: PortalClipper::is_whole_portal_in_view 00184 // Access: Public 00185 // Description: checks if portal_node is within the view frustum. 00186 // If so, then the portal is worth considering. This 00187 // is a 2nd level test to weed out most of the portals 00188 //////////////////////////////////////////////////////////////////// 00189 INLINE bool PortalClipper:: 00190 is_whole_portal_in_view(const LMatrix4 &cmat) { 00191 // I am about to xform this gbv, so lets make a copy 00192 const BoundingVolume *bv = _portal_node->get_bounds(); 00193 BoundingVolume *cbv = bv->make_copy(); 00194 GeometricBoundingVolume *gbv = DCAST(GeometricBoundingVolume, cbv); 00195 00196 // trasform it to camera space 00197 gbv->xform(cmat); 00198 00199 int result = _reduced_frustum->contains(gbv); 00200 00201 portal_cat.spam() << "1st level test if portal: " << *_reduced_frustum << " is in view " << result << endl; 00202 return (result != 0); 00203 } 00204 00205 /* 00206 //////////////////////////////////////////////////////////////////// 00207 // Function: PortalClipper::is_partial_portal_in_view 00208 // Access: Public 00209 // Description: checks if any of the _coords is within the view frustum. 00210 // If so, then the portal is facing the camera. 2nd level 00211 // test to make sure this portal is worth visiting 00212 //////////////////////////////////////////////////////////////////// 00213 INLINE bool PortalClipper:: 00214 is_partial_portal_in_view() { 00215 int result = 0; 00216 00217 // check if any of the _coords in tested frustum 00218 for (int j=0; j<_num_vert; ++j) { 00219 result |= _reduced_frustum->contains(_coords[j]); 00220 } 00221 portal_cat.spam() << "frustum: " << *_reduced_frustum << " contains(coord) result = " << result << endl; 00222 00223 return (result != 0); 00224 } 00225 */ 00226 00227 /* 00228 //////////////////////////////////////////////////////////////////// 00229 // Function: PortalClipper::get_plane_depth 00230 // Access: Public 00231 // Description: Given the x and z, solve for y: from the plane 00232 //////////////////////////////////////////////////////////////////// 00233 INLINE PN_stdfloat PortalClipper:: 00234 get_plane_depth(PN_stdfloat x, PN_stdfloat z, LPlane *portal_plane) { 00235 PN_stdfloat y = 0.0; 00236 // Plane equation: Ax + By + Cz + D = 0 00237 // y = (Ax + Cz + D) / -B 00238 portal_cat.spam() << *portal_plane << endl; 00239 portal_cat.spam() << portal_plane->_v.v._0 << " " << portal_plane->_v.v._1 << " " 00240 << portal_plane->_v.v._2 << " " << portal_plane->_v.v._3 << endl; 00241 00242 if (portal_plane->_v.v._1 != 0.0) { 00243 y = (((portal_plane->_v.v._0*x)+(portal_plane->_v.v._2*z)+portal_plane->_v.v._3) 00244 / -(portal_plane->_v.v._1)); 00245 } 00246 return y; 00247 } 00248 */ 00249