Panda3D

odeBody.I

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._m.data[0], r._m.data[1], r._m.data[2], 0,
00133                    r._m.data[3], r._m.data[4], r._m.data[5], 0,
00134                    r._m.data[6], r._m.data[7], r._m.data[8], 0};
00135   
00136   dBodySetRotation(_id, mat3);
00137 }
00138 
00139 INLINE void OdeBody::
00140 set_quaternion(const LQuaternionf q) {
00141   dQuaternion quat = {q._v.data[0], 
00142                       q._v.data[1], 
00143                       q._v.data[2], 
00144                       q._v.data[3]};
00145   dBodySetQuaternion(_id, quat);
00146 }
00147 
00148 INLINE void OdeBody::
00149 set_linear_vel(dReal x, dReal y, dReal z) {
00150   dBodySetLinearVel(_id, x, y, z);
00151 }
00152 
00153 INLINE void OdeBody::
00154 set_linear_vel(const LVecBase3f &vel) {
00155   set_linear_vel(vel[0], vel[1], vel[2]);
00156 }
00157 
00158 INLINE void OdeBody::
00159 set_angular_vel(dReal x, dReal y, dReal z) {
00160   dBodySetAngularVel(_id, x, y, z);
00161 }
00162 
00163 INLINE void OdeBody::
00164 set_angular_vel(const LVecBase3f &vel) {
00165   set_angular_vel(vel[0], vel[1], vel[2]);
00166 }
00167 
00168 INLINE LVecBase3f OdeBody::
00169 get_position() const {
00170   const dReal *res = dBodyGetPosition(_id);
00171   return LVecBase3f(res[0], res[1], res[2]);
00172 }
00173 
00174 INLINE LMatrix3f OdeBody::
00175 get_rotation() const {
00176   const dReal *rot = dBodyGetRotation(_id);
00177   return LMatrix3f(rot[0], rot[1], rot[2],
00178                    rot[4], rot[5], rot[6],
00179                    rot[8], rot[9], rot[10]);
00180 }
00181 
00182 INLINE LVecBase4f OdeBody::
00183 get_quaternion() const {
00184   const dReal *res = dBodyGetQuaternion(_id);
00185   return LVecBase4f(res[0], res[1], res[2], res[3]);
00186 }
00187 
00188 INLINE LVecBase3f OdeBody::
00189 get_linear_vel() const {
00190   const dReal *res = dBodyGetLinearVel(_id);
00191   return LVecBase3f(res[0], res[1], res[2]);
00192 }
00193 
00194 INLINE LVecBase3f OdeBody::
00195 get_angular_vel() const {
00196   const dReal *res = dBodyGetAngularVel(_id);
00197   return LVecBase3f(res[0], res[1], res[2]);
00198 }
00199 
00200 INLINE void OdeBody::
00201 set_mass(OdeMass &mass) {
00202   dBodySetMass(_id, mass.get_mass_ptr());
00203 }
00204 
00205 INLINE OdeMass OdeBody::
00206 get_mass() const {
00207   OdeMass mass;
00208   dBodyGetMass(_id, mass.get_mass_ptr());
00209   return mass;
00210 }
00211 
00212 INLINE void OdeBody::
00213 add_force(dReal fx, dReal fy, dReal fz) {
00214   dBodyAddForce(_id, fx, fy, fz);
00215 }
00216 
00217 INLINE void OdeBody::
00218 add_force(const LVecBase3f &f) {
00219   add_force(f[0], f[1], f[2]);
00220 }
00221 
00222 INLINE void OdeBody::
00223 add_torque(dReal fx, dReal fy, dReal fz) {
00224   dBodyAddTorque(_id, fx, fy, fz);
00225 }
00226 
00227 INLINE void OdeBody::
00228 add_torque(const LVecBase3f &f) {
00229   add_torque(f[0], f[1], f[2]);
00230 }
00231 
00232 INLINE void OdeBody::
00233 add_rel_force(dReal fx, dReal fy, dReal fz) {
00234   dBodyAddRelForce(_id, fx, fy, fz);
00235 }
00236 
00237 INLINE void OdeBody::
00238 add_rel_force(const LVecBase3f &f) {
00239   add_rel_force(f[0], f[1], f[2]);
00240 }
00241 
00242 INLINE void OdeBody::
00243 add_rel_torque(dReal fx, dReal fy, dReal fz) {
00244   dBodyAddRelTorque(_id, fx, fy, fz);
00245 }
00246 
00247 INLINE void OdeBody::
00248 add_rel_torque(const LVecBase3f &f) {
00249   add_rel_torque(f[0], f[1], f[2]);
00250 }
00251 
00252 INLINE void OdeBody::
00253 add_force_at_pos(dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz) {
00254   dBodyAddForceAtPos(_id, fx, fy, fz, px, py, pz);
00255 }
00256 
00257 INLINE void OdeBody::
00258 add_force_at_pos(const LVecBase3f &f, const LVecBase3f &pos) {
00259   add_force_at_pos(f[0], f[1], f[2], pos[0], pos[1], pos[2]);
00260 }
00261 
00262 INLINE void OdeBody::
00263 add_force_at_rel_pos(dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz) {
00264   dBodyAddForceAtRelPos(_id, fx, fy, fz, px, py, pz);
00265 }
00266 
00267 INLINE void OdeBody::
00268 add_force_at_rel_pos(const LVecBase3f &f, const LVecBase3f &pos) {
00269   add_force_at_rel_pos(f[0], f[1], f[2], pos[0], pos[1], pos[2]);
00270 }
00271 
00272 INLINE void OdeBody::
00273 add_rel_force_at_pos(dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz) {
00274   dBodyAddRelForceAtPos(_id, fx, fy, fz, px, py, pz);
00275 }
00276 
00277 INLINE void OdeBody::
00278 add_rel_force_at_pos(const LVecBase3f &f, const LVecBase3f &pos) {
00279   add_rel_force_at_pos(f[0], f[1], f[2], pos[0], pos[1], pos[2]);
00280 }
00281 
00282 INLINE void OdeBody::
00283 add_rel_force_at_rel_pos(dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz) {
00284   dBodyAddRelForceAtRelPos(_id, fx, fy, fz, px, py, pz);
00285 }
00286 
00287 INLINE void OdeBody::
00288 add_rel_force_at_rel_pos(const LVecBase3f &f, const LVecBase3f &pos) {
00289   add_rel_force_at_rel_pos(f[0], f[1], f[2], pos[0], pos[1], pos[2]);
00290 }
00291 
00292 INLINE void OdeBody::
00293 set_force(dReal x, dReal y, dReal z) {
00294   dBodySetForce(_id, x, y, z);
00295 }
00296 
00297 INLINE void OdeBody::
00298 set_force(const LVecBase3f &f) {
00299   set_force(f[0], f[1], f[2]);
00300 }
00301 
00302 INLINE void OdeBody::
00303 set_torque(dReal x, dReal y, dReal z) {
00304   dBodySetTorque(_id, x, y, z);
00305 }
00306 
00307 INLINE void OdeBody::
00308 set_torque(const LVecBase3f &f) {
00309   set_torque(f[0], f[1], f[2]);
00310 }
00311 
00312 INLINE LPoint3f OdeBody::
00313 get_rel_point_pos(dReal px, dReal py, dReal pz) const {
00314   dVector3 result;
00315   dBodyGetRelPointPos(_id, px, py, pz, result);
00316   return LPoint3f(result[0], result[1], result[2]);
00317 }
00318 
00319 INLINE LPoint3f OdeBody::
00320 get_rel_point_pos(const LVecBase3f &pos) const {
00321   return get_rel_point_pos(pos[0], pos[1], pos[2]);
00322 }
00323 
00324 INLINE LPoint3f OdeBody::
00325 get_rel_point_vel(dReal px, dReal py, dReal pz) const {
00326   dVector3 result;
00327   dBodyGetRelPointVel(_id, px, py, pz, result);
00328   return LPoint3f(result[0], result[1], result[2]);
00329 }
00330 
00331 INLINE LPoint3f OdeBody::
00332 get_rel_point_vel(const LVecBase3f &pos) const {
00333   return get_rel_point_vel(pos[0], pos[1], pos[2]);
00334 }
00335 
00336 INLINE LPoint3f OdeBody::
00337 get_point_vel(dReal px, dReal py, dReal pz) const {
00338   dVector3 result;
00339   dBodyGetPointVel(_id, px, py, pz, result);
00340   return LPoint3f(result[0], result[1], result[2]);
00341 }
00342 
00343 INLINE LPoint3f OdeBody::
00344 get_point_vel(const LVecBase3f &pos) const {
00345   return get_point_vel(pos[0], pos[1], pos[2]);
00346 }
00347 
00348 INLINE LPoint3f OdeBody::
00349 get_pos_rel_point(dReal px, dReal py, dReal pz) const {
00350   dVector3 result;
00351   dBodyGetPosRelPoint(_id, px, py, pz, result);
00352   return LPoint3f(result[0], result[1], result[2]);
00353 }
00354 
00355 INLINE LPoint3f OdeBody::
00356 get_pos_rel_point(const LVecBase3f &pos) const {
00357   return get_pos_rel_point(pos[0], pos[1], pos[2]);
00358 }
00359 
00360 INLINE LVecBase3f OdeBody::
00361 vector_to_world(dReal px, dReal py, dReal pz) const {
00362   dVector3 result;
00363   dBodyVectorToWorld(_id, px, py, pz, result);
00364   return LVecBase3f(result[0], result[1], result[2]);
00365 }
00366 
00367 INLINE LVecBase3f OdeBody::
00368 vector_to_world(const LVecBase3f &pos) const {
00369   return vector_to_world(pos[0], pos[1], pos[2]);
00370 }
00371 
00372 INLINE LVecBase3f OdeBody::
00373 vector_from_world(dReal px, dReal py, dReal pz) const {
00374   dVector3 result;
00375   dBodyVectorFromWorld(_id, px, py, pz, result);
00376   return LVecBase3f(result[0], result[1], result[2]);
00377 }
00378 
00379 INLINE LVecBase3f OdeBody::
00380 vector_from_world(const LVecBase3f &pos) const {
00381   return vector_from_world(pos[0], pos[1], pos[2]);
00382 }
00383 
00384 INLINE void OdeBody::
00385 set_finite_rotation_mode(int mode) {
00386   dBodySetFiniteRotationMode(_id, mode);
00387 }
00388 
00389 INLINE void OdeBody::
00390 set_finite_rotation_axis(dReal x, dReal y, dReal z) {
00391   dBodySetFiniteRotationAxis(_id, x, y, z);
00392 }
00393 
00394 INLINE void OdeBody::
00395 set_finite_rotation_axis(const LVecBase3f &axis) {
00396   set_finite_rotation_axis(axis[0], axis[1], axis[2]);
00397 }
00398 
00399 INLINE int OdeBody::
00400 get_finite_rotation_mode() const {
00401   return dBodyGetFiniteRotationMode(_id);
00402 }
00403 
00404 INLINE LVecBase3f OdeBody::
00405 get_finite_rotation_axis() const {
00406   dVector3 result;
00407   dBodyGetFiniteRotationAxis(_id, result);
00408   return LVecBase3f(result[0], result[1], result[2]);
00409 }
00410 
00411 INLINE int OdeBody::
00412 get_num_joints() const {
00413   return dBodyGetNumJoints(_id);
00414 }
00415 
00416 INLINE void OdeBody::
00417 enable() {
00418   dBodyEnable(_id);
00419 }
00420 
00421 INLINE void OdeBody::
00422 disable() {
00423   dBodyDisable(_id);
00424 }
00425 
00426 INLINE int OdeBody::
00427 is_enabled() const {
00428   return dBodyIsEnabled(_id);
00429 }
00430 
00431 INLINE void OdeBody::
00432 set_gravity_mode(int mode) {
00433   dBodySetGravityMode(_id, mode);
00434 }
00435 
00436 INLINE int OdeBody::
00437 get_gravity_mode() const {
00438   return dBodyGetGravityMode(_id);
00439 }
00440 
00441 INLINE int OdeBody::
00442 compare_to(const OdeBody &other) const {
00443   if (_id != other._id) {
00444     return _id < other._id ? -1 : 1;
00445   }
00446   return 0;
00447 }
 All Classes Functions Variables Enumerations