00001 /**************************************************************************** 00002 * Copyright 2005 Evan Drumwright 00003 * This library is distributed under the terms of the GNU General Public 00004 * License (found in COPYING). 00005 ****************************************************************************/ 00006 00007 #ifndef _CONSTRAINT_H 00008 #define _CONSTRAINT_H 00009 00010 #include <string> 00011 #include <Physsim/Base.h> 00012 #include <Physsim/Vector3.h> 00013 #include <Physsim/MatrixN.h> 00014 #include <Physsim/VectorN.h> 00015 00016 namespace Physsim { 00017 00018 class RigidBody; 00019 00021 00026 class Constraint : public Base 00027 { 00028 public: 00029 virtual ~Constraint() {} 00030 virtual void read(const char* filename) = 0; 00031 virtual void write(const char* filename) = 0; 00032 00034 00037 int getBodyIndex(const RigidBody* body) const; 00038 00040 bool isEnabled() const { return _enabled; } 00041 00043 void setEnabled(bool flag); 00044 00046 virtual std::string getJointType() const = 0; 00047 00049 RigidBody* getBodyFirst() const; 00050 00052 RigidBody* getBodySecond() const; 00053 00055 00060 void setBodies(const RigidBody* body1, const RigidBody* body2); 00061 00063 Vector3 getBodyFirstTorque() const { return _t1; } 00064 00066 Vector3 getBodyFirstForce() const { return _f1; } 00067 00069 Vector3 getBodySecondTorque() const { return _t2; } 00070 00072 Vector3 getBodySecondForce() const { return _f2; } 00073 00075 void setBodyFirstTorque(const Vector3& torque) { _t1 = torque; } 00076 00078 void setBodyFirstForce(const Vector3& force) { _f1 = force; } 00079 00081 void setBodySecondTorque(const Vector3& torque) { _t2 = torque; } 00082 00084 void setBodySecondForce(const Vector3& force) { _f2 = force; } 00085 00087 Real getMaxForce() const { return _maxforce; } 00088 00090 Real getMaxTorque() const { return _maxtorque; } 00091 00093 void setMaxForce(Real maxforce) { _maxforce = maxforce; } 00094 00096 void setMaxTorque(Real maxtorque) { _maxtorque = maxtorque; } 00097 00099 00104 virtual Real getImplicit(const std::vector<RigidBody*> body_list) const = 0; 00105 00107 00112 virtual Real getImplicitD(const std::vector<RigidBody*> body_list) const = 0; 00113 00115 00118 virtual VectorN getJacobian(const std::vector<RigidBody*> body_list) const = 0; 00119 00121 00124 virtual VectorN getJacobianD(const std::vector<RigidBody*> body_list) const = 0; 00125 00127 Real getKP() const { return _kp; } 00128 00130 void setKP(Real kp) { _kp = kp; } 00131 00133 Real getKD() const { return _kd; } 00134 00136 void setKD(Real kd) { _kd = kd; } 00137 00138 protected: 00140 RigidBody* _body1; 00141 00143 RigidBody* _body2; 00144 00146 Vector3 _f1; 00147 00149 Vector3 _t1; 00150 00152 Vector3 _f2; 00153 00155 Vector3 _t2; 00156 00158 Real _kp; 00159 00161 Real _kd; 00162 00164 Real _maxforce; 00165 00167 Real _maxtorque; 00168 00169 private: 00170 std::string _joint_type; 00171 bool _enabled; 00172 }; 00173 } 00174 00175 #endif
1.5.1