00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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) );
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
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
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
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
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);
00162 }
00163
00164
00165
00166
00167
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