Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

physics/ODEDoubleHingeJoint.cpp

Go to the documentation of this file.
00001 /****************************************************************************
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: ODEDoubleHingeJoint.cpp 1031 2004-02-11 20:46:36Z jungd $
00019   $Revision: 1.4 $
00020   $Date: 2004-02-11 15:46:36 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #include <physics/ODEDoubleHingeJoint>
00026 #include <physics/ODEConstraintGroup>
00027 
00028 using physics::ODEDoubleHingeJoint;
00029 using physics::ODEConstraintGroup;
00030 
00031 
00032 ODEDoubleHingeJoint::ODEDoubleHingeJoint()
00033 {
00034 }
00035 
00036 ODEDoubleHingeJoint::~ODEDoubleHingeJoint() 
00037 {
00038 }
00039 
00040 void ODEDoubleHingeJoint::onConstraintGroupAdd(ref<ConstraintGroup> g)
00041 {
00042   Assert(g != 0);
00043   Assert(instanceof(*g,ODEConstraintGroup));
00044   group = g;
00045 
00046   ref<ODEConstraintGroup> ogroup = narrow_ref<ODEConstraintGroup>(group);
00047   setJointID( dJointCreateHinge2(ogroup->getWorldID(), ogroup->getJointGroupID()) );
00048 }
00049 
00050 
00051 void ODEDoubleHingeJoint::setAnchor(const Point3& p)
00052 {
00053   checkAddedAndAttached();
00054   Point3 gp( body1->getRelPointPos(p) ); // to global frame
00055   dJointSetHinge2Anchor(jointID, gp.x, gp.y, gp.z);
00056 }
00057 
00058 base::Point3 ODEDoubleHingeJoint::getAnchor() const
00059 {
00060   checkAddedAndAttached();
00061   dVector3 ogp;
00062   dJointGetHinge2Anchor(jointID, ogp);
00063   Point3 gp(ogp[0], ogp[1], ogp[2]);
00064   return body1->getGlobalPointRelPos(gp);
00065 }
00066 
00067 void ODEDoubleHingeJoint::setAxis1(const Vector3& v)
00068 {
00069   checkAddedAndAttached();
00070   // transform direction vector to global frame for ODE
00071   Vector3 g(v);
00072   body1->getOrientation().rotatePoint(g);
00073   dJointSetHinge2Axis1(jointID, g.x, g.y, g.z);
00074 }
00075 
00076 base::Vector3 ODEDoubleHingeJoint::getAxis1() const
00077 {
00078   checkAddedAndAttached();
00079   dVector3 gaxis;
00080   dJointGetHinge2Axis1(jointID, gaxis);
00081   // transform into body1 frame
00082   Vector3 l(gaxis[0], gaxis[1], gaxis[2]);
00083   body1->getOrientation().invert().rotatePoint(l);
00084   return l;
00085 }
00086   
00087 void ODEDoubleHingeJoint::setAxis2(const Vector3& v)
00088 {
00089   checkAddedAndAttached();
00090   // transform direction vector to global frame for ODE
00091   Vector3 g(v);
00092   body2->getOrientation().rotatePoint(g);
00093   dJointSetHinge2Axis2(jointID, g.x, g.y, g.z);
00094 }
00095 
00096 base::Vector3 ODEDoubleHingeJoint::getAxis2() const
00097 {
00098   checkAddedAndAttached();
00099   dVector3 gaxis;
00100   dJointGetHinge2Axis2(jointID, gaxis);
00101   // transform into body1 frame
00102   Vector3 l(gaxis[0], gaxis[1], gaxis[2]);
00103   body2->getOrientation().invert().rotatePoint(l);
00104   return l;
00105 }
00106   
00107 Real ODEDoubleHingeJoint::getAngle1() const
00108 {
00109   return dJointGetHinge2Angle1(jointID);
00110 }
00111 
00112 Real ODEDoubleHingeJoint::getAngle1Rate() const
00113 {
00114   return dJointGetHinge2Angle1Rate(jointID);
00115 }
00116 
00117 Real ODEDoubleHingeJoint::getAngle2Rate() const
00118 {
00119   return dJointGetHinge2Angle2Rate(jointID);
00120 }
00121 
00122 
00123 void ODEDoubleHingeJoint::setHighStop(Int dof, Real angle)
00124 {
00125   Assert((dof==1)||(dof==2));
00126   Assertm( -consts::Pi <= angle && angle <= consts::Pi, "angle within range");
00127   checkAddedAndAttached();
00128   dJointSetHinge2Param(jointID, (dof==1)?dParamHiStop:dParamHiStop2, angle);
00129 }
00130 
00131 void ODEDoubleHingeJoint::setLowStop(Int dof, Real angle)
00132 {
00133   Assert((dof==1)||(dof==2));
00134   Assertm( -consts::Pi <= angle && angle <= consts::Pi, "angle within range");
00135   checkAddedAndAttached();
00136   dJointSetHinge2Param(jointID, (dof==1)?dParamLoStop:dParamLoStop2, angle);
00137 }
00138 
00139 
00140 void ODEDoubleHingeJoint::setStopRestitution(Int dof, Real r)
00141 {
00142   checkAddedAndAttached();
00143   Assert((dof==1)||(dof==2));
00144   Assertm( (0 <= r) && (r <= 1), "restitution within range");
00145   dJointSetHinge2Param(jointID, (dof==1)?dParamBounce:dParamBounce2, r);
00146 }
00147 
00148 void ODEDoubleHingeJoint::setParameter(const String& name, Real value, Int dof)
00149 {
00150   checkAddedAndAttached();
00151   Assert((dof==1)||(dof==2));
00152   if (name == "CFM") 
00153     dJointSetHinge2Param(jointID, dParamCFM, value);
00154   else if (name == "StopERP")
00155     dJointSetHinge2Param(jointID, (dof==1)?dParamStopERP:dParamStopERP2, value);
00156   else if (name == "StopCFM")
00157     dJointSetHinge2Param(jointID, (dof==1)?dParamStopCFM:dParamStopCFM2, value);
00158   else if (name == "FudgeFactor")
00159     dJointSetHinge2Param(jointID, (dof==1)?dParamFudgeFactor:dParamFudgeFactor2, value);
00160   else
00161     DoubleHingeJoint::setParameter(name,value, dof); // pass it up to super
00162 }
00163 
00164 
00165 
00166 
00167 // protected
00168 
00169 bool ODEDoubleHingeJoint::hasMotor(Int dof) const
00170 {
00171   return ((dof==1)||(dof==2));
00172 }
00173 
00174 void ODEDoubleHingeJoint::setMotorTargetVel(Int dof, Real vel)
00175 {
00176   Assert((dof==1)||(dof==2));
00177   checkAddedAndAttached();
00178   if (dof==1)
00179     dJointSetHinge2Param(jointID, dParamVel, vel);
00180   else
00181     dJointSetHinge2Param(jointID, dParamVel2, vel);
00182 }
00183 
00184 void ODEDoubleHingeJoint::setMotorMaxForce(Int dof, Real force)
00185 {
00186   Assert((dof==1)||(dof==2));
00187   checkAddedAndAttached();
00188   if (dof==1)
00189     dJointSetHinge2Param(jointID, dParamFMax, force); 
00190   else
00191     dJointSetHinge2Param(jointID, dParamFMax2, force); 
00192 }
00193 
00194 

Generated on Thu Jul 29 15:56:26 2004 for OpenSim by doxygen 1.3.6