00001 // Filename: collisionLevelState.I 00002 // Created by: drose (16Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: CollisionLevelState::Constructor 00022 // Access: Public 00023 // Description: 00024 //////////////////////////////////////////////////////////////////// 00025 INLINE CollisionLevelState:: 00026 CollisionLevelState(const NodePath &node_path) : 00027 _node_path(node_path) 00028 { 00029 } 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Function: CollisionLevelState::Constructor 00033 // Access: Public 00034 // Description: This constructor goes to the next child node in the 00035 // traversal. 00036 //////////////////////////////////////////////////////////////////// 00037 INLINE CollisionLevelState:: 00038 CollisionLevelState(const CollisionLevelState &parent, PandaNode *child) : 00039 _node_path(parent._node_path, child), 00040 _colliders(parent._colliders), 00041 _current(parent._current), 00042 _colliders_with_geom(parent._colliders_with_geom), 00043 _local_bounds(parent._local_bounds) 00044 { 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: CollisionLevelState::get_node_path 00049 // Access: Public 00050 // Description: Returns the NodePath representing the node instance 00051 // we have traversed to. 00052 //////////////////////////////////////////////////////////////////// 00053 INLINE NodePath CollisionLevelState:: 00054 get_node_path() const { 00055 return _node_path.get_node_path(); 00056 } 00057 00058 //////////////////////////////////////////////////////////////////// 00059 // Function: CollisionLevelState::node 00060 // Access: Public 00061 // Description: Returns the PandaNode pointer of the node we have 00062 // traversed to. 00063 //////////////////////////////////////////////////////////////////// 00064 INLINE PandaNode *CollisionLevelState:: 00065 node() const { 00066 return _node_path.node(); 00067 } 00068 00069 //////////////////////////////////////////////////////////////////// 00070 // Function: CollisionLevelState::get_num_colliders 00071 // Access: Public 00072 // Description: 00073 //////////////////////////////////////////////////////////////////// 00074 INLINE int CollisionLevelState:: 00075 get_num_colliders() const { 00076 return _colliders.size(); 00077 } 00078 00079 //////////////////////////////////////////////////////////////////// 00080 // Function: CollisionLevelState::has_collider 00081 // Access: Public 00082 // Description: Returns true if the nth collider in the LevelState is 00083 // still part of the level. 00084 //////////////////////////////////////////////////////////////////// 00085 INLINE bool CollisionLevelState:: 00086 has_collider(int n) const { 00087 nassertr(n >= 0 && n < (int)_colliders.size(), false); 00088 return (_current & get_mask(n)) != 0; 00089 } 00090 00091 //////////////////////////////////////////////////////////////////// 00092 // Function: CollisionLevelState::has_collider_with_geom 00093 // Access: Public 00094 // Description: Returns true if the nth collider in the LevelState is 00095 // still part of the level, and it has the 00096 // "collide_geom" flag set. 00097 //////////////////////////////////////////////////////////////////// 00098 INLINE bool CollisionLevelState:: 00099 has_collider_with_geom(int n) const { 00100 nassertr(n >= 0 && n < (int)_colliders.size(), false); 00101 return (_current & _colliders_with_geom & get_mask(n)) != 0; 00102 } 00103 00104 //////////////////////////////////////////////////////////////////// 00105 // Function: CollisionLevelState::has_any_collider 00106 // Access: Public 00107 // Description: 00108 //////////////////////////////////////////////////////////////////// 00109 INLINE bool CollisionLevelState:: 00110 has_any_collider() const { 00111 return _current != 0; 00112 } 00113 00114 //////////////////////////////////////////////////////////////////// 00115 // Function: CollisionLevelState::has_any_collide_geom 00116 // Access: Public 00117 // Description: Returns true if any Collider in the level state has 00118 // the "collide_geom" flag set, false otherwise. 00119 //////////////////////////////////////////////////////////////////// 00120 INLINE bool CollisionLevelState:: 00121 has_any_collide_geom() const { 00122 return (_current & _colliders_with_geom) != 0; 00123 } 00124 00125 //////////////////////////////////////////////////////////////////// 00126 // Function: CollisionLevelState::reached_collision_node 00127 // Access: Public 00128 // Description: Called by the traverser when we reach a CollisionNode 00129 // in the traversal. At this point, we zero out our set 00130 // of colliders with the "collide_geom" flag set, 00131 // because no colliders will test against geometry 00132 // parented beneath a CollisionNode. 00133 //////////////////////////////////////////////////////////////////// 00134 INLINE void CollisionLevelState:: 00135 reached_collision_node() { 00136 _colliders_with_geom = 0; 00137 } 00138 00139 //////////////////////////////////////////////////////////////////// 00140 // Function: CollisionLevelState::get_collider 00141 // Access: Public 00142 // Description: 00143 //////////////////////////////////////////////////////////////////// 00144 INLINE CollisionSolid *CollisionLevelState:: 00145 get_collider(int n) const { 00146 nassertr(n >= 0 && n < (int)_colliders.size(), NULL); 00147 nassertr(has_collider(n), NULL); 00148 00149 return _colliders[n]._collider; 00150 } 00151 00152 //////////////////////////////////////////////////////////////////// 00153 // Function: CollisionLevelState::get_node 00154 // Access: Public 00155 // Description: 00156 //////////////////////////////////////////////////////////////////// 00157 INLINE CollisionNode *CollisionLevelState:: 00158 get_node(int n) const { 00159 nassertr(n >= 0 && n < (int)_colliders.size(), NULL); 00160 nassertr(has_collider(n), NULL); 00161 00162 return _colliders[n]._node; 00163 } 00164 00165 //////////////////////////////////////////////////////////////////// 00166 // Function: CollisionLevelState::get_space 00167 // Access: Public 00168 // Description: 00169 //////////////////////////////////////////////////////////////////// 00170 INLINE const LMatrix4f &CollisionLevelState:: 00171 get_space(int n) const { 00172 nassertr(n >= 0 && n < (int)_colliders.size(), LMatrix4f::ident_mat()); 00173 nassertr(has_collider(n), LMatrix4f::ident_mat()); 00174 00175 return _colliders[n]._space; 00176 } 00177 00178 //////////////////////////////////////////////////////////////////// 00179 // Function: CollisionLevelState::get_inv_space 00180 // Access: Public 00181 // Description: 00182 //////////////////////////////////////////////////////////////////// 00183 INLINE const LMatrix4f &CollisionLevelState:: 00184 get_inv_space(int n) const { 00185 nassertr(n >= 0 && n < (int)_colliders.size(), LMatrix4f::ident_mat()); 00186 nassertr(has_collider(n), LMatrix4f::ident_mat()); 00187 00188 return _colliders[n]._inv_space; 00189 } 00190 00191 //////////////////////////////////////////////////////////////////// 00192 // Function: CollisionLevelState::get_local_bound 00193 // Access: Public 00194 // Description: Returns the bounding volume of the indicated 00195 // collider, transformed into the current node's 00196 // transform space. 00197 //////////////////////////////////////////////////////////////////// 00198 INLINE const GeometricBoundingVolume *CollisionLevelState:: 00199 get_local_bound(int n) const { 00200 nassertr(n >= 0 && n < (int)_colliders.size(), NULL); 00201 nassertr(has_collider(n), NULL); 00202 nassertr(n >= 0 && n < (int)_local_bounds.size(), NULL); 00203 00204 // For whatever reason, the Intel compiler can't figure this line 00205 // out. 00206 //return _local_bounds[n]; 00207 00208 // But it can figure out this equivalent line. 00209 return *(_local_bounds + n); 00210 } 00211 00212 //////////////////////////////////////////////////////////////////// 00213 // Function: CollisionLevelState::get_parent_bound 00214 // Access: Public 00215 // Description: Returns the bounding volume of the indicated 00216 // collider, transformed into the previous node's 00217 // transform space, but not transformed by the current 00218 // node's transform. This is appropriate for testing 00219 // against the bounding volume of the current node 00220 // (which does not have its own transform applied to 00221 // it). 00222 //////////////////////////////////////////////////////////////////// 00223 INLINE const GeometricBoundingVolume *CollisionLevelState:: 00224 get_parent_bound(int n) const { 00225 nassertr(n >= 0 && n < (int)_colliders.size(), NULL); 00226 nassertr(has_collider(n), NULL); 00227 nassertr(n >= 0 && n < (int)_parent_bounds.size(), NULL); 00228 00229 // But it can figure out this equivalent line. 00230 return *(_parent_bounds + n); 00231 } 00232 00233 //////////////////////////////////////////////////////////////////// 00234 // Function: CollisionLevelState::omit_collider 00235 // Access: Public 00236 // Description: 00237 //////////////////////////////////////////////////////////////////// 00238 INLINE void CollisionLevelState:: 00239 omit_collider(int n) { 00240 nassertv(n >= 0 && n < (int)_colliders.size()); 00241 nassertv(has_collider(n)); 00242 00243 _current &= ~get_mask(n); 00244 } 00245 00246 //////////////////////////////////////////////////////////////////// 00247 // Function: CollisionLevelState::get_mask 00248 // Access: Private 00249 // Description: Returns a single bit associated with the nth 00250 // collider. 00251 //////////////////////////////////////////////////////////////////// 00252 INLINE CollisionLevelState::ColliderMask CollisionLevelState:: 00253 get_mask(int n) const { 00254 return ((ColliderMask)1) << n; 00255 }