00001 // Filename: physical.I 00002 // Created by: charles (16Jun00) 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 #include <algorithm> 00016 00017 //////////////////////////////////////////////////////////////////// 00018 // Function : clear_linear_forces 00019 // Access : Public 00020 // Description : Erases the linear force list 00021 //////////////////////////////////////////////////////////////////// 00022 INLINE void Physical:: 00023 clear_linear_forces() { 00024 _linear_forces.erase(_linear_forces.begin(), 00025 _linear_forces.end()); 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function : clear_angular_forces 00030 // Access : Public 00031 // Description : Erases the angular force list 00032 //////////////////////////////////////////////////////////////////// 00033 INLINE void Physical:: 00034 clear_angular_forces() { 00035 _angular_forces.erase(_angular_forces.begin(), 00036 _angular_forces.end()); 00037 } 00038 00039 //////////////////////////////////////////////////////////////////// 00040 // Function : clear_physics_objects 00041 // Access : Public 00042 // Description : Erases the object list 00043 //////////////////////////////////////////////////////////////////// 00044 INLINE void Physical:: 00045 clear_physics_objects() { 00046 _physics_objects.erase(_physics_objects.begin(), 00047 _physics_objects.end()); 00048 } 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function : add_linear_force 00052 // Access : Public 00053 // Description : Adds a linear force to the force list 00054 //////////////////////////////////////////////////////////////////// 00055 INLINE void Physical:: 00056 add_linear_force(LinearForce *f) { 00057 _linear_forces.push_back(f); 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function : add_angular_force 00062 // Access : Public 00063 // Description : Adds an angular force to the force list 00064 //////////////////////////////////////////////////////////////////// 00065 INLINE void Physical:: 00066 add_angular_force(AngularForce *f) { 00067 _angular_forces.push_back(f); 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function : remove_linear_force 00072 // Access : Public 00073 // Description : removes a linear force from the force list 00074 //////////////////////////////////////////////////////////////////// 00075 INLINE void Physical:: 00076 remove_linear_force(LinearForce *f) { 00077 LinearForceVector::iterator found; 00078 00079 // this is a PT because the templates don't like what should be 00080 // perfectly allowable, which is to search for bf directly. 00081 PT(LinearForce) pt_lf = f; 00082 found = find(_linear_forces.begin(), _linear_forces.end(), pt_lf); 00083 00084 if (found == _linear_forces.end()) 00085 return; 00086 00087 _linear_forces.erase(found); 00088 } 00089 00090 //////////////////////////////////////////////////////////////////// 00091 // Function : remove_angular_force 00092 // Access : Public 00093 // Description : removes an angular force from the force list 00094 //////////////////////////////////////////////////////////////////// 00095 INLINE void Physical:: 00096 remove_angular_force(AngularForce *f) { 00097 AngularForceVector::iterator found; 00098 00099 PT(AngularForce) pt_af = f; 00100 found = find(_angular_forces.begin(), _angular_forces.end(), pt_af); 00101 00102 if (found == _angular_forces.end()) 00103 return; 00104 00105 _angular_forces.erase(found); 00106 } 00107 00108 //////////////////////////////////////////////////////////////////// 00109 // Function : add_physics_object 00110 // Access : Public 00111 // Description : Adds an object to the physics object vector 00112 //////////////////////////////////////////////////////////////////// 00113 INLINE void Physical:: 00114 add_physics_object(PhysicsObject *po) { 00115 _physics_objects.push_back(po); 00116 } 00117 00118 //////////////////////////////////////////////////////////////////// 00119 // Function : get_physics_manager 00120 // Access : Public 00121 //////////////////////////////////////////////////////////////////// 00122 INLINE PhysicsManager *Physical:: 00123 get_physics_manager() const { 00124 return _physics_manager; 00125 } 00126 00127 //////////////////////////////////////////////////////////////////// 00128 // Function : get_phys_body 00129 // Access : Public 00130 //////////////////////////////////////////////////////////////////// 00131 INLINE PhysicsObject *Physical:: 00132 get_phys_body() const { 00133 return _phys_body; 00134 } 00135 00136 //////////////////////////////////////////////////////////////////// 00137 // Function : get_physical_node 00138 // Access : Public 00139 //////////////////////////////////////////////////////////////////// 00140 INLINE PhysicalNode *Physical:: 00141 get_physical_node() const { 00142 return _physical_node; 00143 } 00144 00145 //////////////////////////////////////////////////////////////////// 00146 // Function : get_physical_node_path 00147 // Access : Public 00148 //////////////////////////////////////////////////////////////////// 00149 INLINE NodePath Physical:: 00150 get_physical_node_path() const { 00151 return NodePath((PandaNode*) _physical_node); 00152 } 00153 00154 //////////////////////////////////////////////////////////////////// 00155 // Function : get_object_vector 00156 // Access : Public 00157 //////////////////////////////////////////////////////////////////// 00158 INLINE const PhysicsObject::Vector &Physical:: 00159 get_object_vector() const { 00160 return _physics_objects; 00161 } 00162 00163 //////////////////////////////////////////////////////////////////// 00164 // Function : get_linear_forces 00165 // Access : Public 00166 //////////////////////////////////////////////////////////////////// 00167 INLINE const Physical::LinearForceVector &Physical:: 00168 get_linear_forces() const { 00169 return _linear_forces; 00170 } 00171 00172 //////////////////////////////////////////////////////////////////// 00173 // Function : get_angular_forces 00174 // Access : Public 00175 //////////////////////////////////////////////////////////////////// 00176 INLINE const Physical::AngularForceVector &Physical:: 00177 get_angular_forces() const { 00178 return _angular_forces; 00179 } 00180 00181 //////////////////////////////////////////////////////////////////// 00182 // Function : get_num_linear_forces 00183 // Access : Public 00184 //////////////////////////////////////////////////////////////////// 00185 INLINE int Physical:: 00186 get_num_linear_forces() const { 00187 return _linear_forces.size(); 00188 } 00189 00190 //////////////////////////////////////////////////////////////////// 00191 // Function : get_linear_force 00192 // Access : Public 00193 //////////////////////////////////////////////////////////////////// 00194 INLINE PT(LinearForce) Physical:: 00195 get_linear_force(int index) const { 00196 nassertr(index >= 0 && index < (int)_linear_forces.size(), NULL); 00197 return _linear_forces[index]; 00198 } 00199 00200 //////////////////////////////////////////////////////////////////// 00201 // Function : get_num_angular_forces 00202 // Access : Public 00203 //////////////////////////////////////////////////////////////////// 00204 INLINE int Physical:: 00205 get_num_angular_forces() const { 00206 return _angular_forces.size(); 00207 } 00208 00209 //////////////////////////////////////////////////////////////////// 00210 // Function : get_angular_force 00211 // Access : Public 00212 //////////////////////////////////////////////////////////////////// 00213 INLINE PT(AngularForce) Physical:: 00214 get_angular_force(int index) const { 00215 nassertr(index >= 0 && index < (int)_angular_forces.size(), NULL); 00216 return _angular_forces[index]; 00217 } 00218 00219 //////////////////////////////////////////////////////////////////// 00220 // Function : set_viscosity 00221 // Access : Public 00222 // Description : Set the local viscosity. 00223 //////////////////////////////////////////////////////////////////// 00224 INLINE void Physical:: 00225 set_viscosity(PN_stdfloat viscosity) { 00226 _viscosity=viscosity; 00227 } 00228 00229 //////////////////////////////////////////////////////////////////// 00230 // Function : get_viscosity 00231 // Access : Public 00232 // Description : Get the local viscosity. 00233 //////////////////////////////////////////////////////////////////// 00234 INLINE PN_stdfloat Physical:: 00235 get_viscosity() const { 00236 //zzzzzzzzzzzzzzzz return max(_viscosity, get_physics_manager()->get_viscosity()); 00237 return _viscosity; 00238 }