Panda3D
|
00001 // Filename: physicsObject.I 00002 // Created by: charles (13Jun00) 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 // Function : set_mass 00017 // Access : Public 00018 // Description : Set the mass in slugs (or kilograms). 00019 //////////////////////////////////////////////////////////////////// 00020 INLINE void PhysicsObject:: 00021 set_mass(PN_stdfloat m) { 00022 nassertv(m > 0); 00023 _mass = m; 00024 } 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function : set_position 00028 // Access : Public 00029 // Description : Vector position assignment. This is also used as 00030 // the center of mass. 00031 //////////////////////////////////////////////////////////////////// 00032 INLINE void PhysicsObject:: 00033 set_position(const LPoint3 &pos) { 00034 nassertv(!pos.is_nan()); 00035 _position = pos; 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function : set_position 00040 // Access : Public 00041 // Description : Piecewise position assignment 00042 //////////////////////////////////////////////////////////////////// 00043 INLINE void PhysicsObject:: 00044 set_position(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) { 00045 nassertv(!LPoint3(x, y, z).is_nan()); 00046 _position.set(x, y, z); 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function : reset_position 00051 // Access : Public 00052 // Description : use this to place an object in a completely new 00053 // position, that has nothing to do with its last 00054 // position. 00055 //////////////////////////////////////////////////////////////////// 00056 INLINE void PhysicsObject:: 00057 reset_position(const LPoint3 &pos) { 00058 nassertv(!pos.is_nan()); 00059 _position = pos; 00060 _last_position = pos; 00061 _velocity.set(0.0f, 0.0f, 0.0f); 00062 } 00063 00064 //////////////////////////////////////////////////////////////////// 00065 // Function : reset_orientation 00066 // Access : Public 00067 // Description : set the orientation while clearing the rotation 00068 // velocity. 00069 //////////////////////////////////////////////////////////////////// 00070 INLINE void PhysicsObject:: 00071 reset_orientation(const LOrientation &orientation) { 00072 nassertv(!orientation.is_nan()); 00073 _orientation = orientation; 00074 _rotation = LRotation::ident_quat(); 00075 } 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Function : set_last_position 00079 // Access : Public 00080 // Description : Last position assignment 00081 //////////////////////////////////////////////////////////////////// 00082 INLINE void PhysicsObject:: 00083 set_last_position(const LPoint3 &pos) { 00084 _last_position = pos; 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function : set_velocity 00089 // Access : Public 00090 // Description : Vector velocity assignment 00091 //////////////////////////////////////////////////////////////////// 00092 INLINE void PhysicsObject:: 00093 set_velocity(const LVector3 &vel) { 00094 nassertv(!vel.is_nan()); 00095 _velocity = vel; 00096 } 00097 00098 //////////////////////////////////////////////////////////////////// 00099 // Function : set_velocity 00100 // Access : Public 00101 // Description : Piecewise velocity assignment 00102 //////////////////////////////////////////////////////////////////// 00103 INLINE void PhysicsObject:: 00104 set_velocity(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) { 00105 nassertv(!LVector3(x, y, z).is_nan()); 00106 _velocity.set(x, y, z); 00107 } 00108 00109 //////////////////////////////////////////////////////////////////// 00110 // Function : add_local_torque 00111 // Access : Public 00112 // Description : Adds an torque force (i.e. an instantanious change 00113 // in velocity). This is a quicker way to get the 00114 // angular velocity, add a vector to it and set that 00115 // value to be the new angular velocity. 00116 //////////////////////////////////////////////////////////////////// 00117 INLINE void PhysicsObject:: 00118 add_local_torque(const LRotation &torque) { 00119 nassertv(!torque.is_nan()); 00120 _rotation+=_orientation.xform(torque); 00121 } 00122 00123 //////////////////////////////////////////////////////////////////// 00124 // Function : add_local_impulse 00125 // Access : Public 00126 // Description : Adds an impulse force (i.e. an instantanious change 00127 // in velocity). This is a quicker way to get the 00128 // velocity, add a vector to it and set that value to 00129 // be the new velocity. 00130 //////////////////////////////////////////////////////////////////// 00131 INLINE void PhysicsObject:: 00132 add_local_impulse(const LVector3 &impulse) { 00133 nassertv(!impulse.is_nan()); 00134 _velocity += _orientation.xform(impulse); 00135 } 00136 00137 //////////////////////////////////////////////////////////////////// 00138 // Function : add_torque 00139 // Access : Public 00140 // Description : Adds an torque force (i.e. an instantanious change 00141 // in velocity). This is a quicker way to get the 00142 // angular velocity, add a vector to it and set that 00143 // value to be the new angular velocity. 00144 //////////////////////////////////////////////////////////////////// 00145 INLINE void PhysicsObject:: 00146 add_torque(const LRotation &torque) { 00147 nassertv(!torque.is_nan()); 00148 _rotation+=torque; 00149 } 00150 00151 //////////////////////////////////////////////////////////////////// 00152 // Function : add_impulse 00153 // Access : Public 00154 // Description : Adds an impulse force (i.e. an instantanious change 00155 // in velocity). This is a quicker way to get the 00156 // velocity, add a vector to it and set that value to 00157 // be the new velocity. 00158 //////////////////////////////////////////////////////////////////// 00159 INLINE void PhysicsObject:: 00160 add_impulse(const LVector3 &impulse) { 00161 nassertv(!impulse.is_nan()); 00162 _velocity+=impulse; 00163 } 00164 00165 //////////////////////////////////////////////////////////////////// 00166 // Function : set_active 00167 // Access : Public 00168 // Description : Process Flag assignment 00169 //////////////////////////////////////////////////////////////////// 00170 INLINE void PhysicsObject:: 00171 set_active(bool flag) { 00172 _process_me = flag; 00173 } 00174 00175 //////////////////////////////////////////////////////////////////// 00176 // Function : set_terminal_velocity 00177 // Access : Public 00178 // Description : tv assignment 00179 //////////////////////////////////////////////////////////////////// 00180 INLINE void PhysicsObject:: 00181 set_terminal_velocity(PN_stdfloat tv) { 00182 _terminal_velocity = tv; 00183 } 00184 00185 //////////////////////////////////////////////////////////////////// 00186 // Function : get_mass 00187 // Access : Public 00188 // Description : Get the mass in slugs (or kilograms). 00189 //////////////////////////////////////////////////////////////////// 00190 INLINE PN_stdfloat PhysicsObject:: 00191 get_mass() const { 00192 return _mass; 00193 } 00194 00195 //////////////////////////////////////////////////////////////////// 00196 // Function : get_position 00197 // Access : Public 00198 // Description : Position Query 00199 //////////////////////////////////////////////////////////////////// 00200 INLINE LPoint3 PhysicsObject:: 00201 get_position() const { 00202 return _position; 00203 } 00204 00205 //////////////////////////////////////////////////////////////////// 00206 // Function : get_last_position 00207 // Access : Public 00208 // Description : Get the position of the physics object at the start 00209 // of the most recent do_physics. 00210 //////////////////////////////////////////////////////////////////// 00211 INLINE LPoint3 PhysicsObject:: 00212 get_last_position() const { 00213 return _last_position; 00214 } 00215 00216 //////////////////////////////////////////////////////////////////// 00217 // Function : get_velocity 00218 // Access : Public 00219 // Description : Velocity Query per second 00220 //////////////////////////////////////////////////////////////////// 00221 INLINE LVector3 PhysicsObject:: 00222 get_velocity() const { 00223 return _velocity; 00224 } 00225 00226 //////////////////////////////////////////////////////////////////// 00227 // Function : get_implicit_velocity 00228 // Access : Public 00229 // Description : Velocity Query over the last dt 00230 //////////////////////////////////////////////////////////////////// 00231 INLINE LVector3 PhysicsObject:: 00232 get_implicit_velocity() const { 00233 return _position-_last_position; 00234 } 00235 00236 //////////////////////////////////////////////////////////////////// 00237 // Function : get_active 00238 // Access : Public 00239 // Description : Process Flag Query 00240 //////////////////////////////////////////////////////////////////// 00241 INLINE bool PhysicsObject:: 00242 get_active() const { 00243 return _process_me; 00244 } 00245 00246 //////////////////////////////////////////////////////////////////// 00247 // Function : get_terminal_velocity 00248 // Access : Public 00249 // Description : tv query 00250 //////////////////////////////////////////////////////////////////// 00251 INLINE PN_stdfloat PhysicsObject:: 00252 get_terminal_velocity() const { 00253 return _terminal_velocity; 00254 } 00255 00256 //////////////////////////////////////////////////////////////////// 00257 // Function : set_orientation 00258 // Access : Public 00259 // Description : 00260 //////////////////////////////////////////////////////////////////// 00261 INLINE void PhysicsObject:: 00262 set_orientation(const LOrientation &orientation) { 00263 nassertv(!orientation.is_nan()); 00264 _orientation = orientation; 00265 } 00266 00267 //////////////////////////////////////////////////////////////////// 00268 // Function : set_rotation 00269 // Access : Public 00270 // Description : set rotation as a quaternion delta per second. 00271 //////////////////////////////////////////////////////////////////// 00272 INLINE void PhysicsObject:: 00273 set_rotation(const LRotation &rotation) { 00274 nassertv(!rotation.is_nan()); 00275 _rotation = rotation; 00276 } 00277 00278 //////////////////////////////////////////////////////////////////// 00279 // Function : get_orientation 00280 // Access : Public 00281 // Description : get current orientation. 00282 //////////////////////////////////////////////////////////////////// 00283 INLINE LOrientation PhysicsObject:: 00284 get_orientation() const { 00285 return _orientation; 00286 } 00287 00288 //////////////////////////////////////////////////////////////////// 00289 // Function : get_rotation 00290 // Access : Public 00291 // Description : get rotation per second. 00292 //////////////////////////////////////////////////////////////////// 00293 INLINE LRotation PhysicsObject:: 00294 get_rotation() const { 00295 return _rotation; 00296 } 00297 00298 //////////////////////////////////////////////////////////////////// 00299 // Function : set_oriented 00300 // Access : Public 00301 // Description : Set flag to determine whether this object should do 00302 // any rotation or orientation calculations. Optimization. 00303 //////////////////////////////////////////////////////////////////// 00304 INLINE void PhysicsObject:: 00305 set_oriented(bool flag) { 00306 _oriented = flag; 00307 } 00308 00309 //////////////////////////////////////////////////////////////////// 00310 // Function : get_oriented 00311 // Access : Public 00312 // Description : See set_oriented(). 00313 //////////////////////////////////////////////////////////////////// 00314 INLINE bool PhysicsObject:: 00315 get_oriented() const { 00316 return _oriented; 00317 }