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