00001 /* **-*-c++-*-************************************************************** 00002 Copyright (C)1996 David Jung <opensim@pobox.com> 00003 00004 This program/file is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. (http://www.gnu.org) 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 $Id: ODESolid 1031 2004-02-11 20:46:36Z jungd $ 00019 $Revision: 1.8 $ 00020 $Date: 2004-02-11 15:46:36 -0500 (Wed, 11 Feb 2004) $ 00021 $Author: jungd $ 00022 00023 ****************************************************************************/ 00024 00025 #ifndef _PHYSICS_ODESOLID_ 00026 #define _PHYSICS_ODESOLID_ 00027 00028 #include <base/ref> 00029 #include <physics/physics> 00030 #include <physics/Solid> 00031 00032 #include <ode/ode.h> 00033 00034 00035 namespace physics { 00036 00037 00038 class ODESolid : public Solid 00039 { 00040 public: 00041 ODESolid(const Solid& s); 00042 virtual ~ODESolid(); 00043 00044 virtual String className() const { return String("ODESolid"); } 00045 00046 virtual MassProperties massProperties() const; 00047 00048 virtual Body& operator=(const Body& b); 00049 00050 virtual void setEnabled(bool enable); 00051 virtual bool isEnabled() const; 00052 00053 00054 virtual void setPosition(const Point3& x); 00055 virtual void setOrientation(const Orient& orient); 00056 virtual void setVelocity(const Vector3& v); 00057 virtual void setAngVelocity(const Vector3& w); 00058 00059 virtual Point3 getPosition() const; 00060 virtual Orient getOrientation() const; 00061 virtual Vector3 getVelocity() const; 00062 virtual Vector3 getAngVelocity() const; 00063 00064 virtual void saveState(); 00065 virtual void restoreState(); 00066 00067 virtual Point3 getSavedPosition() const; 00068 virtual Orient getSavedOrientation() const; 00069 virtual Vector3 getSavedVelocity() const; 00070 virtual Vector3 getSavedAngVelocity() const; 00071 00072 // Utility 00073 virtual Point3 getRelPointPos(const Point3& p); 00074 virtual Vector3 getRelPointVel(const Point3& p); 00075 virtual Point3 getGlobalPointRelPos(const Point3& p); 00076 00077 00078 // Force/Torque accumulator functions 00079 // (accumulated forces are zero'd before each step) 00080 virtual void addForce(const Vector3& f); 00081 virtual void addTorque(const Vector3& t); 00082 virtual void addRelForce(const Vector3& f); 00083 virtual void addRelTorque(const Vector3& t); 00084 virtual void addForceAtPos(const Vector3& f, const Point3& p); 00085 virtual void addForceAtRelPos(const Vector3& f, const Point3& p); 00086 virtual void addRelForceAtPos(const Vector3& f, const Point3& p); 00087 virtual void addRelForceAtRelPos(const Vector3& f, const Point3& p); 00088 00089 virtual Vector3 getForce() const; 00090 virtual Vector3 getTorque() const; 00091 00092 virtual ref<Collidable> createCollidable(ref<const Shape> collisionShape, CollidableFlags flags = 0); 00093 00094 virtual dBodyID getBodyID() const { return bodyID; } ///< get ODE's dBodyID 00095 00096 protected: 00097 ODESolid(ref<const Shape> shape, ref<const Material> material); 00098 void create(dWorldID worldID) const; ///< create ODE body etc. and add to worldID 00099 void destroy() const; ///< destroy the body and remove it from the world 00100 Vector3 AngVelToAngMomentum(const Quat4& orient, const Vector3& w) const; 00101 00102 virtual void updateVisual() { Solid::updateVisual(); } 00103 00104 // saved ODE body state 00105 dVector3 savedPos; 00106 dQuaternion savedOrient; 00107 dVector3 savedVel; 00108 dVector3 savedAngVel; 00109 00110 mutable bool created; ///< have ODE entities been created? (creation is delayed until call to create() ) 00111 mutable dWorldID worldID; ///< ODE's world ID (for world this is in) 00112 mutable dBodyID bodyID; ///< ODE's body ID 00113 00114 friend class ODESolidSystem; 00115 friend class ODEJoint; 00116 friend class ODECollisionResponseHandler; 00117 }; 00118 00119 00120 } // physics 00121 00122 #endif