00001 // Filename: collisionSolid.I 00002 // Created by: drose (27Jun00) 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: CollisionSolid::set_tangible 00018 // Access: Published 00019 // Description: Sets the current state of the 'tangible' flag. Set 00020 // this true to make the solid tangible, so that a 00021 // CollisionHandlerPusher will not allow another object 00022 // to intersect it, or false to make it intangible, so 00023 // that a CollisionHandlerPusher will ignore it except 00024 // to throw an event. 00025 //////////////////////////////////////////////////////////////////// 00026 INLINE void CollisionSolid:: 00027 set_tangible(bool tangible) { 00028 LightMutexHolder holder(_lock); 00029 if (tangible) { 00030 _flags |= F_tangible; 00031 } else { 00032 _flags &= ~F_tangible; 00033 } 00034 _flags |= F_viz_geom_stale; 00035 } 00036 00037 //////////////////////////////////////////////////////////////////// 00038 // Function: CollisionSolid::is_tangible 00039 // Access: Published 00040 // Description: Returns whether the solid is considered 'tangible' or 00041 // not. An intangible solid has no effect in a 00042 // CollisionHandlerPusher (except to throw an event); 00043 // it's useful for defining 'trigger' planes and 00044 // spheres, that cause an effect when passed through. 00045 //////////////////////////////////////////////////////////////////// 00046 INLINE bool CollisionSolid:: 00047 is_tangible() const { 00048 LightMutexHolder holder(_lock); 00049 return do_is_tangible(); 00050 } 00051 00052 //////////////////////////////////////////////////////////////////// 00053 // Function: CollisionSolid::set_effective_normal 00054 // Access: Published 00055 // Description: Records a false normal for this CollisionSolid that 00056 // will be reported by the collision system with all 00057 // collisions into it, instead of its actual normal. 00058 // This is useful as a workaround for the problem of an 00059 // avatar wanting to stand on a sloping ground; by 00060 // storing a false normal, the ground appears to be 00061 // perfectly level, and the avatar does not tend to 00062 // slide down it. 00063 //////////////////////////////////////////////////////////////////// 00064 INLINE void CollisionSolid:: 00065 set_effective_normal(const LVector3 &effective_normal) { 00066 LightMutexHolder holder(_lock); 00067 _effective_normal = effective_normal; 00068 _flags |= F_effective_normal; 00069 } 00070 00071 //////////////////////////////////////////////////////////////////// 00072 // Function: CollisionSolid::clear_effective_normal 00073 // Access: Published 00074 // Description: Removes the normal previously set by 00075 // set_effective_normal(). 00076 //////////////////////////////////////////////////////////////////// 00077 INLINE void CollisionSolid:: 00078 clear_effective_normal() { 00079 LightMutexHolder holder(_lock); 00080 _flags &= ~F_effective_normal; 00081 } 00082 00083 //////////////////////////////////////////////////////////////////// 00084 // Function: CollisionSolid::has_effective_normal 00085 // Access: Published 00086 // Description: Returns true if a special normal was set by 00087 // set_effective_normal(), false otherwise. 00088 //////////////////////////////////////////////////////////////////// 00089 INLINE bool CollisionSolid:: 00090 has_effective_normal() const { 00091 LightMutexHolder holder(_lock); 00092 return do_has_effective_normal(); 00093 } 00094 00095 //////////////////////////////////////////////////////////////////// 00096 // Function: CollisionSolid::get_effective_normal 00097 // Access: Published 00098 // Description: Returns the normal that was set by 00099 // set_effective_normal(). It is an error to call this 00100 // unless has_effective_normal() returns true. 00101 //////////////////////////////////////////////////////////////////// 00102 INLINE const LVector3 &CollisionSolid:: 00103 get_effective_normal() const { 00104 LightMutexHolder holder(_lock); 00105 nassertr(do_has_effective_normal(), LVector3::zero()); 00106 return _effective_normal; 00107 } 00108 00109 //////////////////////////////////////////////////////////////////// 00110 // Function: CollisionSolid::set_respect_effective_normal 00111 // Access: Published 00112 // Description: This is only meaningful for CollisionSolids that will 00113 // be added to a traverser as colliders. It is normally 00114 // true, but if set false, it means that this particular 00115 // solid does not care about the "effective" normal of 00116 // other solids it meets, but rather always uses the 00117 // true normal. 00118 //////////////////////////////////////////////////////////////////// 00119 INLINE void CollisionSolid:: 00120 set_respect_effective_normal(bool respect_effective_normal) { 00121 LightMutexHolder holder(_lock); 00122 // For historical reasons, the bit we store is the opposite of the 00123 // bool flag we present. 00124 if (respect_effective_normal) { 00125 _flags &= ~F_ignore_effective_normal; 00126 } else { 00127 _flags |= F_ignore_effective_normal; 00128 } 00129 } 00130 00131 //////////////////////////////////////////////////////////////////// 00132 // Function: CollisionSolid::get_respect_effective_normal 00133 // Access: Published 00134 // Description: See set_respect_effective_normal(). 00135 //////////////////////////////////////////////////////////////////// 00136 INLINE bool CollisionSolid:: 00137 get_respect_effective_normal() const { 00138 LightMutexHolder holder(_lock); 00139 return (_flags & F_ignore_effective_normal) == 0; 00140 } 00141 00142 //////////////////////////////////////////////////////////////////// 00143 // Function: CollisionSolid::do_is_tangible 00144 // Access: Protected 00145 // Description: Returns whether the solid is considered 'tangible' or 00146 // not. Assumes the lock is already held. 00147 //////////////////////////////////////////////////////////////////// 00148 INLINE bool CollisionSolid:: 00149 do_is_tangible() const { 00150 return (_flags & F_tangible) != 0; 00151 } 00152 00153 //////////////////////////////////////////////////////////////////// 00154 // Function: CollisionSolid::do_has_effective_normal 00155 // Access: Protected 00156 // Description: Returns true if a special normal was set by 00157 // set_effective_normal(), false otherwise. Assumes the 00158 // lock is already held. 00159 //////////////////////////////////////////////////////////////////// 00160 INLINE bool CollisionSolid:: 00161 do_has_effective_normal() const { 00162 return respect_effective_normal && (_flags & F_effective_normal) != 0; 00163 } 00164 00165 //////////////////////////////////////////////////////////////////// 00166 // Function: CollisionSolid::mark_internal_bounds_stale 00167 // Access: Protected 00168 // Description: Should be called by a derived class to mark the 00169 // internal bounding volume stale, so that 00170 // recompute_internal_bounds() will be called when the 00171 // bounding volume is next requested. 00172 //////////////////////////////////////////////////////////////////// 00173 INLINE void CollisionSolid:: 00174 mark_internal_bounds_stale() { 00175 LightMutexHolder holder(_lock); 00176 _flags |= F_internal_bounds_stale; 00177 } 00178 00179 //////////////////////////////////////////////////////////////////// 00180 // Function: CollisionSolid::mark_viz_stale 00181 // Access: Protected 00182 // Description: Called internally when the visualization may have 00183 // been compromised by some change to internal state and 00184 // will need to be recomputed the next time it is 00185 // rendered. 00186 //////////////////////////////////////////////////////////////////// 00187 INLINE void CollisionSolid:: 00188 mark_viz_stale() { 00189 LightMutexHolder holder(_lock); 00190 _flags |= F_viz_geom_stale; 00191 }