Panda3D
|
00001 // Filename: odeBody.I 00002 // Created by: joswilso (27Dec06) 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: OdeBody::is_empty 00017 // Access: Published 00018 // Description: Returns true if the ID is 0, meaning the OdeBody 00019 // does not point to a valid body. It is an error to 00020 // call a method on an empty body. 00021 // Note that an empty OdeBody also evaluates to False. 00022 //////////////////////////////////////////////////////////////////// 00023 INLINE bool OdeBody:: 00024 is_empty() const { 00025 return (_id == 0); 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: OdeBody::get_id 00030 // Access: Published 00031 // Description: Returns the underlying dBodyID. 00032 //////////////////////////////////////////////////////////////////// 00033 INLINE dBodyID OdeBody:: 00034 get_id() const { 00035 return _id; 00036 } 00037 00038 INLINE dReal OdeBody:: 00039 get_auto_disable_linear_threshold() const { 00040 return dBodyGetAutoDisableLinearThreshold(_id); 00041 } 00042 00043 INLINE void OdeBody:: 00044 set_auto_disable_linear_threshold(dReal linear_threshold) { 00045 dBodySetAutoDisableLinearThreshold(_id, linear_threshold); 00046 } 00047 00048 INLINE dReal OdeBody:: 00049 get_auto_disable_angular_threshold() const { 00050 return dBodyGetAutoDisableAngularThreshold(_id); 00051 } 00052 00053 INLINE void OdeBody:: 00054 set_auto_disable_angular_threshold(dReal angular_threshold) { 00055 dBodySetAutoDisableAngularThreshold(_id, angular_threshold); 00056 } 00057 00058 INLINE int OdeBody:: 00059 get_auto_disable_steps() const { 00060 return dBodyGetAutoDisableSteps(_id); 00061 } 00062 00063 INLINE void OdeBody:: 00064 set_auto_disable_steps(int steps) { 00065 dBodySetAutoDisableSteps(_id, steps); 00066 } 00067 00068 INLINE dReal OdeBody:: 00069 get_auto_disable_time() const { 00070 return dBodyGetAutoDisableTime(_id); 00071 } 00072 00073 INLINE void OdeBody:: 00074 set_auto_disable_time(dReal time) { 00075 dBodySetAutoDisableTime(_id, time); 00076 } 00077 00078 INLINE int OdeBody:: 00079 get_auto_disable_flag() const { 00080 return dBodyGetAutoDisableFlag(_id); 00081 } 00082 00083 INLINE void OdeBody:: 00084 set_auto_disable_flag(int do_auto_disable) { 00085 dBodySetAutoDisableFlag(_id, do_auto_disable); 00086 } 00087 00088 INLINE void OdeBody:: 00089 set_auto_disable_defaults() { 00090 dBodySetAutoDisableDefaults(_id); 00091 } 00092 00093 INLINE void OdeBody:: 00094 set_data(void *data) { 00095 dBodySetData(_id, data); 00096 } 00097 00098 #ifdef HAVE_PYTHON 00099 INLINE void OdeBody:: 00100 set_data(PyObject *data) { 00101 Py_XDECREF((PyObject*) dBodyGetData(_id)); 00102 Py_XINCREF(data); 00103 dBodySetData(_id, data); 00104 } 00105 00106 INLINE PyObject* OdeBody:: 00107 get_data() const { 00108 PyObject* data = (PyObject*) dBodyGetData(_id); 00109 Py_XINCREF(data); 00110 return data; 00111 } 00112 #else 00113 00114 INLINE void* OdeBody:: 00115 get_data() const { 00116 return dBodyGetData(_id); 00117 } 00118 #endif 00119 00120 INLINE void OdeBody:: 00121 set_position(dReal x, dReal y, dReal z) { 00122 dBodySetPosition(_id, x, y, z); 00123 } 00124 00125 INLINE void OdeBody:: 00126 set_position(const LVecBase3f &pos) { 00127 set_position(pos[0], pos[1], pos[2]); 00128 } 00129 00130 INLINE void OdeBody:: 00131 set_rotation(const LMatrix3f &r) { 00132 dMatrix3 mat3 = { r(0, 0), r(0, 1), r(0, 2), 0, 00133 r(1, 0), r(1, 1), r(1, 2), 0, 00134 r(2, 0), r(2, 1), r(2, 2), 0 }; 00135 00136 dBodySetRotation(_id, mat3); 00137 } 00138 00139 INLINE void OdeBody:: 00140 set_quaternion(const LQuaternionf &q) { 00141 dQuaternion quat = { q[0], q[1], q[2], q[3] }; 00142 dBodySetQuaternion(_id, quat); 00143 } 00144 00145 INLINE void OdeBody:: 00146 set_linear_vel(dReal x, dReal y, dReal z) { 00147 dBodySetLinearVel(_id, x, y, z); 00148 } 00149 00150 INLINE void OdeBody:: 00151 set_linear_vel(const LVecBase3f &vel) { 00152 set_linear_vel(vel[0], vel[1], vel[2]); 00153 } 00154 00155 INLINE void OdeBody:: 00156 set_angular_vel(dReal x, dReal y, dReal z) { 00157 dBodySetAngularVel(_id, x, y, z); 00158 } 00159 00160 INLINE void OdeBody:: 00161 set_angular_vel(const LVecBase3f &vel) { 00162 set_angular_vel(vel[0], vel[1], vel[2]); 00163 } 00164 00165 INLINE LVecBase3f OdeBody:: 00166 get_position() const { 00167 const dReal *res = dBodyGetPosition(_id); 00168 return LVecBase3f(res[0], res[1], res[2]); 00169 } 00170 00171 INLINE LMatrix3f OdeBody:: 00172 get_rotation() const { 00173 const dReal *rot = dBodyGetRotation(_id); 00174 return LMatrix3f(rot[0], rot[1], rot[2], 00175 rot[4], rot[5], rot[6], 00176 rot[8], rot[9], rot[10]); 00177 } 00178 00179 INLINE LVecBase4f OdeBody:: 00180 get_quaternion() const { 00181 const dReal *res = dBodyGetQuaternion(_id); 00182 return LVecBase4f(res[0], res[1], res[2], res[3]); 00183 } 00184 00185 INLINE LVecBase3f OdeBody:: 00186 get_linear_vel() const { 00187 const dReal *res = dBodyGetLinearVel(_id); 00188 return LVecBase3f(res[0], res[1], res[2]); 00189 } 00190 00191 INLINE LVecBase3f OdeBody:: 00192 get_angular_vel() const { 00193 const dReal *res = dBodyGetAngularVel(_id); 00194 return LVecBase3f(res[0], res[1], res[2]); 00195 } 00196 00197 INLINE void OdeBody:: 00198 set_mass(OdeMass &mass) { 00199 dBodySetMass(_id, mass.get_mass_ptr()); 00200 } 00201 00202 INLINE OdeMass OdeBody:: 00203 get_mass() const { 00204 OdeMass mass; 00205 dBodyGetMass(_id, mass.get_mass_ptr()); 00206 return mass; 00207 } 00208 00209 INLINE void OdeBody:: 00210 add_force(dReal fx, dReal fy, dReal fz) { 00211 dBodyAddForce(_id, fx, fy, fz); 00212 } 00213 00214 INLINE void OdeBody:: 00215 add_force(const LVecBase3f &f) { 00216 add_force(f[0], f[1], f[2]); 00217 } 00218 00219 INLINE void OdeBody:: 00220 add_torque(dReal fx, dReal fy, dReal fz) { 00221 dBodyAddTorque(_id, fx, fy, fz); 00222 } 00223 00224 INLINE void OdeBody:: 00225 add_torque(const LVecBase3f &f) { 00226 add_torque(f[0], f[1], f[2]); 00227 } 00228 00229 INLINE void OdeBody:: 00230 add_rel_force(dReal fx, dReal fy, dReal fz) { 00231 dBodyAddRelForce(_id, fx, fy, fz); 00232 } 00233 00234 INLINE void OdeBody:: 00235 add_rel_force(const LVecBase3f &f) { 00236 add_rel_force(f[0], f[1], f[2]); 00237 } 00238 00239 INLINE void OdeBody:: 00240 add_rel_torque(dReal fx, dReal fy, dReal fz) { 00241 dBodyAddRelTorque(_id, fx, fy, fz); 00242 } 00243 00244 INLINE void OdeBody:: 00245 add_rel_torque(const LVecBase3f &f) { 00246 add_rel_torque(f[0], f[1], f[2]); 00247 } 00248 00249 INLINE void OdeBody:: 00250 add_force_at_pos(dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz) { 00251 dBodyAddForceAtPos(_id, fx, fy, fz, px, py, pz); 00252 } 00253 00254 INLINE void OdeBody:: 00255 add_force_at_pos(const LVecBase3f &f, const LVecBase3f &pos) { 00256 add_force_at_pos(f[0], f[1], f[2], pos[0], pos[1], pos[2]); 00257 } 00258 00259 INLINE void OdeBody:: 00260 add_force_at_rel_pos(dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz) { 00261 dBodyAddForceAtRelPos(_id, fx, fy, fz, px, py, pz); 00262 } 00263 00264 INLINE void OdeBody:: 00265 add_force_at_rel_pos(const LVecBase3f &f, const LVecBase3f &pos) { 00266 add_force_at_rel_pos(f[0], f[1], f[2], pos[0], pos[1], pos[2]); 00267 } 00268 00269 INLINE void OdeBody:: 00270 add_rel_force_at_pos(dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz) { 00271 dBodyAddRelForceAtPos(_id, fx, fy, fz, px, py, pz); 00272 } 00273 00274 INLINE void OdeBody:: 00275 add_rel_force_at_pos(const LVecBase3f &f, const LVecBase3f &pos) { 00276 add_rel_force_at_pos(f[0], f[1], f[2], pos[0], pos[1], pos[2]); 00277 } 00278 00279 INLINE void OdeBody:: 00280 add_rel_force_at_rel_pos(dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz) { 00281 dBodyAddRelForceAtRelPos(_id, fx, fy, fz, px, py, pz); 00282 } 00283 00284 INLINE void OdeBody:: 00285 add_rel_force_at_rel_pos(const LVecBase3f &f, const LVecBase3f &pos) { 00286 add_rel_force_at_rel_pos(f[0], f[1], f[2], pos[0], pos[1], pos[2]); 00287 } 00288 00289 INLINE void OdeBody:: 00290 set_force(dReal x, dReal y, dReal z) { 00291 dBodySetForce(_id, x, y, z); 00292 } 00293 00294 INLINE void OdeBody:: 00295 set_force(const LVecBase3f &f) { 00296 set_force(f[0], f[1], f[2]); 00297 } 00298 00299 INLINE void OdeBody:: 00300 set_torque(dReal x, dReal y, dReal z) { 00301 dBodySetTorque(_id, x, y, z); 00302 } 00303 00304 INLINE void OdeBody:: 00305 set_torque(const LVecBase3f &f) { 00306 set_torque(f[0], f[1], f[2]); 00307 } 00308 00309 INLINE LPoint3f OdeBody:: 00310 get_rel_point_pos(dReal px, dReal py, dReal pz) const { 00311 dVector3 result; 00312 dBodyGetRelPointPos(_id, px, py, pz, result); 00313 return LPoint3f(result[0], result[1], result[2]); 00314 } 00315 00316 INLINE LPoint3f OdeBody:: 00317 get_rel_point_pos(const LVecBase3f &pos) const { 00318 return get_rel_point_pos(pos[0], pos[1], pos[2]); 00319 } 00320 00321 INLINE LPoint3f OdeBody:: 00322 get_rel_point_vel(dReal px, dReal py, dReal pz) const { 00323 dVector3 result; 00324 dBodyGetRelPointVel(_id, px, py, pz, result); 00325 return LPoint3f(result[0], result[1], result[2]); 00326 } 00327 00328 INLINE LPoint3f OdeBody:: 00329 get_rel_point_vel(const LVecBase3f &pos) const { 00330 return get_rel_point_vel(pos[0], pos[1], pos[2]); 00331 } 00332 00333 INLINE LPoint3f OdeBody:: 00334 get_point_vel(dReal px, dReal py, dReal pz) const { 00335 dVector3 result; 00336 dBodyGetPointVel(_id, px, py, pz, result); 00337 return LPoint3f(result[0], result[1], result[2]); 00338 } 00339 00340 INLINE LPoint3f OdeBody:: 00341 get_point_vel(const LVecBase3f &pos) const { 00342 return get_point_vel(pos[0], pos[1], pos[2]); 00343 } 00344 00345 INLINE LPoint3f OdeBody:: 00346 get_pos_rel_point(dReal px, dReal py, dReal pz) const { 00347 dVector3 result; 00348 dBodyGetPosRelPoint(_id, px, py, pz, result); 00349 return LPoint3f(result[0], result[1], result[2]); 00350 } 00351 00352 INLINE LPoint3f OdeBody:: 00353 get_pos_rel_point(const LVecBase3f &pos) const { 00354 return get_pos_rel_point(pos[0], pos[1], pos[2]); 00355 } 00356 00357 INLINE LVecBase3f OdeBody:: 00358 vector_to_world(dReal px, dReal py, dReal pz) const { 00359 dVector3 result; 00360 dBodyVectorToWorld(_id, px, py, pz, result); 00361 return LVecBase3f(result[0], result[1], result[2]); 00362 } 00363 00364 INLINE LVecBase3f OdeBody:: 00365 vector_to_world(const LVecBase3f &pos) const { 00366 return vector_to_world(pos[0], pos[1], pos[2]); 00367 } 00368 00369 INLINE LVecBase3f OdeBody:: 00370 vector_from_world(dReal px, dReal py, dReal pz) const { 00371 dVector3 result; 00372 dBodyVectorFromWorld(_id, px, py, pz, result); 00373 return LVecBase3f(result[0], result[1], result[2]); 00374 } 00375 00376 INLINE LVecBase3f OdeBody:: 00377 vector_from_world(const LVecBase3f &pos) const { 00378 return vector_from_world(pos[0], pos[1], pos[2]); 00379 } 00380 00381 INLINE void OdeBody:: 00382 set_finite_rotation_mode(int mode) { 00383 dBodySetFiniteRotationMode(_id, mode); 00384 } 00385 00386 INLINE void OdeBody:: 00387 set_finite_rotation_axis(dReal x, dReal y, dReal z) { 00388 dBodySetFiniteRotationAxis(_id, x, y, z); 00389 } 00390 00391 INLINE void OdeBody:: 00392 set_finite_rotation_axis(const LVecBase3f &axis) { 00393 set_finite_rotation_axis(axis[0], axis[1], axis[2]); 00394 } 00395 00396 INLINE int OdeBody:: 00397 get_finite_rotation_mode() const { 00398 return dBodyGetFiniteRotationMode(_id); 00399 } 00400 00401 INLINE LVecBase3f OdeBody:: 00402 get_finite_rotation_axis() const { 00403 dVector3 result; 00404 dBodyGetFiniteRotationAxis(_id, result); 00405 return LVecBase3f(result[0], result[1], result[2]); 00406 } 00407 00408 INLINE int OdeBody:: 00409 get_num_joints() const { 00410 return dBodyGetNumJoints(_id); 00411 } 00412 00413 INLINE void OdeBody:: 00414 enable() { 00415 dBodyEnable(_id); 00416 } 00417 00418 INLINE void OdeBody:: 00419 disable() { 00420 dBodyDisable(_id); 00421 } 00422 00423 INLINE int OdeBody:: 00424 is_enabled() const { 00425 return dBodyIsEnabled(_id); 00426 } 00427 00428 INLINE void OdeBody:: 00429 set_gravity_mode(int mode) { 00430 dBodySetGravityMode(_id, mode); 00431 } 00432 00433 INLINE int OdeBody:: 00434 get_gravity_mode() const { 00435 return dBodyGetGravityMode(_id); 00436 } 00437 00438 INLINE int OdeBody:: 00439 compare_to(const OdeBody &other) const { 00440 if (_id != other._id) { 00441 return _id < other._id ? -1 : 1; 00442 } 00443 return 0; 00444 }