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/ODEFixedConstraint>
00026 #include <physics/ODEConstraintGroup>
00027 #include <physics/ODESolid>
00028
00029 using physics::ODEFixedConstraint;
00030 using physics::FixedConstraint;
00031 using physics::Body;
00032 using physics::ODESolid;
00033
00034
00035 ODEFixedConstraint::ODEFixedConstraint()
00036 {
00037 }
00038
00039 ODEFixedConstraint::~ODEFixedConstraint()
00040 {
00041 }
00042
00043
00044 void ODEFixedConstraint::attach(ref<Body> body1, ref<Body> body2)
00045 {
00046 Assert(body1 != 0);
00047 Assert(body2 != 0);
00048 Assertm(body1 != body2, "body1 is not body2");
00049
00050 if (jointID == 0)
00051 throw std::runtime_error(Exception("Constraint must be added to a ConstraintGroup before being attached to bodies"));
00052
00053 this->body1 = body1;
00054 this->body2 = body2;
00055
00056 ref<ODESolid> solid1 = narrow_ref<ODESolid>(body1);
00057 ref<ODESolid> solid2 = narrow_ref<ODESolid>(body2);
00058
00059 dJointAttach(jointID, solid1->getBodyID(), solid2->getBodyID());
00060 dJointSetHingeAnchor(jointID, 0,0,0);
00061 dJointSetHingeAxis(jointID, 0,0,1 );
00062 dJointSetHingeParam(jointID, dParamLoStop, -consts::epsilon);
00063 dJointSetHingeParam(jointID, dParamHiStop, consts::epsilon);
00064 dJointSetHingeParam(jointID, dParamBounce, 0);
00065 }
00066
00067 ref<Body> ODEFixedConstraint::getBody(Int index)
00068 {
00069 Assert(index < 2);
00070 return (index==0)?body1:body2;
00071 }
00072
00073 ref<const Body> ODEFixedConstraint::getBody(Int index) const
00074 {
00075 Assert(index < 2);
00076 return (index==0)?body1:body2;
00077 }
00078
00079
00080 void ODEFixedConstraint::onConstraintGroupAdd(ref<ConstraintGroup> g)
00081 {
00082 Assert(g != 0);
00083 Assert(instanceof(*g,ODEConstraintGroup));
00084 group = g;
00085
00086 ref<ODEConstraintGroup> ogroup = narrow_ref<ODEConstraintGroup>(group);
00087 Assert(ogroup->getWorldID());
00088
00089
00090
00091
00092 setJointID ( dJointCreateHinge(ogroup->getWorldID(), ogroup->getJointGroupID()) );
00093 }
00094