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

physics/ODESliderJoint.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: ODESliderJoint.cpp 1031 2004-02-11 20:46:36Z jungd $
00019   $Revision: 1.2 $
00020   $Date: 2004-02-11 15:46:36 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #include <physics/ODESliderJoint>
00026 #include <physics/ODEConstraintGroup>
00027 
00028 using physics::ODESliderJoint;
00029 using physics::ODEConstraintGroup;
00030 
00031 
00032 ODESliderJoint::ODESliderJoint()
00033 {
00034 }
00035 
00036 ODESliderJoint::~ODESliderJoint() 
00037 {
00038 }
00039 
00040 void ODESliderJoint::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( dJointCreateSlider(ogroup->getWorldID(), ogroup->getJointGroupID()) );
00048 }
00049 
00050 
00051 
00052 void ODESliderJoint::setAxis(const Vector3& v)
00053 {
00054   checkAddedAndAttached();
00055   // transform direction vector to global frame for ODE
00056   Vector3 g(v);
00057   body1->getOrientation().rotatePoint(g);
00058   dJointSetSliderAxis(jointID, g.x, g.y, g.z);
00059 }
00060 
00061 base::Vector3 ODESliderJoint::getAxis() const
00062 {
00063   checkAddedAndAttached();
00064   dVector3 gaxis;
00065   dJointGetSliderAxis(jointID, gaxis);
00066   // transform into body1 frame
00067   Vector3 l(gaxis[0], gaxis[1], gaxis[2]);
00068   body1->getOrientation().invert().rotatePoint(l);
00069   return l;
00070 }
00071 
00072 Real ODESliderJoint::getPosition() const
00073 {
00074   checkAddedAndAttached();
00075   return dJointGetSliderPosition(jointID);
00076 }
00077 
00078 Real ODESliderJoint::getPositionRate() const
00079 {
00080   checkAddedAndAttached();
00081   return dJointGetSliderPositionRate(jointID);
00082 }
00083 
00084 
00085 void ODESliderJoint::setHighStop(Real pos)
00086 {
00087   checkAddedAndAttached();
00088   dJointSetSliderParam(jointID, dParamHiStop, pos);
00089 }
00090 
00091 void ODESliderJoint::setLowStop(Real pos)
00092 {
00093   checkAddedAndAttached();
00094   dJointSetSliderParam(jointID, dParamLoStop, pos);
00095 }
00096 
00097 void ODESliderJoint::setStopRestitution(Real r)
00098 {
00099   checkAddedAndAttached();
00100   Assertm( 0 <= r && r <= 1, "restitution within range");
00101   dJointSetSliderParam(jointID, dParamBounce, r);
00102 }
00103 
00104 
00105 void ODESliderJoint::setParameter(const String& name, Real value, Int dof)
00106 {
00107   Assert(dof==1);
00108   if (name == "CFM") 
00109     dJointSetSliderParam(jointID, dParamCFM, value);
00110   else if (name == "StopERP")
00111     dJointSetSliderParam(jointID, dParamStopERP, value);
00112   else if (name == "StopCFM")
00113     dJointSetSliderParam(jointID, dParamStopCFM, value);
00114   else if (name == "FudgeFactor")
00115     dJointSetSliderParam(jointID, dParamFudgeFactor, value);
00116   else
00117     SliderJoint::setParameter(name,value, dof); // pass it up to super
00118 }
00119 
00120 
00121 
00122 // protected
00123 
00124 bool ODESliderJoint::hasMotor(Int dof) const
00125 {
00126   return (dof==1);
00127 }
00128 
00129 void ODESliderJoint::setMotorTargetVel(Int dof, Real vel)
00130 {
00131   Assert(dof==1);
00132   dJointSetSliderParam(jointID, dParamVel, vel);
00133 }
00134 
00135 void ODESliderJoint::setMotorMaxForce(Int dof, Real force)
00136 {
00137   Assert(dof==1);
00138   dJointSetSliderParam(jointID, dParamFMax, force); 
00139 }

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