internal static Joint Create(JointDef def){ Joint joint = null; switch (def.type) { case JointType.e_distanceJoint: { joint = new DistanceJoint((DistanceJointDef)def); } break; case JointType.e_mouseJoint: { joint = new MouseJoint((MouseJointDef)def); } break; case JointType.e_prismaticJoint: { joint = new PrismaticJoint((PrismaticJointDef)def); } break; case JointType.e_revoluteJoint: { joint = new RevoluteJoint((RevoluteJointDef)def); } break; case JointType.e_pulleyJoint: { joint = new PulleyJoint((PulleyJointDef)def); } break; case JointType.e_gearJoint: { joint = new GearJoint((GearJointDef)def); } break; case JointType.e_wheelJoint: { joint = new WheelJoint((WheelJointDef)def); } break; case JointType.e_weldJoint: { joint = new WeldJoint((WeldJointDef)def); } break; case JointType.e_frictionJoint: { joint = new FrictionJoint((FrictionJointDef)def); } break; case JointType.e_ropeJoint: { throw new NotImplementedException(); //joint = new RopeJoint((RopeJointDef)def); } break; case JointType.e_motorJoint: { joint = new MotorJoint((MotorJointDef)def); } break; default: Utilities.Assert(false); break; } return joint; }
internal GearJoint(GearJointDef def) : base(def) { m_joint1 = def.joint1; m_joint2 = def.joint2; m_typeA = m_joint1.GetJointType(); m_typeB = m_joint2.GetJointType(); Utilities.Assert(m_typeA == JointType.e_revoluteJoint || m_typeA == JointType.e_prismaticJoint); Utilities.Assert(m_typeB == JointType.e_revoluteJoint || m_typeB == JointType.e_prismaticJoint); float coordinateA, coordinateB; // TODO_ERIN there might be some problem with the joint edges in Joint. m_bodyC = m_joint1.GetBodyA(); m_bodyA = m_joint1.GetBodyB(); // Get geometry of joint1 Transform xfA = m_bodyA.m_xf; float aA = m_bodyA.m_sweep.a; Transform xfC = m_bodyC.m_xf; float aC = m_bodyC.m_sweep.a; if (m_typeA == JointType.e_revoluteJoint) { RevoluteJoint revolute = (RevoluteJoint)def.joint1; m_localAnchorC = revolute.m_localAnchorA; m_localAnchorA = revolute.m_localAnchorB; m_referenceAngleA = revolute.m_referenceAngle; m_localAxisC.SetZero(); coordinateA = aA - aC - m_referenceAngleA; } else { PrismaticJoint prismatic = (PrismaticJoint)def.joint1; m_localAnchorC = prismatic.m_localAnchorA; m_localAnchorA = prismatic.m_localAnchorB; m_referenceAngleA = prismatic.m_referenceAngle; m_localAxisC = prismatic.m_localXAxisA; Vec2 pC = m_localAnchorC; Vec2 pA = Utilities.MulT(xfC.q, Utilities.Mul(xfA.q, m_localAnchorA) + (xfA.p - xfC.p)); coordinateA = Utilities.Dot(pA - pC, m_localAxisC); } m_bodyD = m_joint2.GetBodyA(); m_bodyB = m_joint2.GetBodyB(); // Get geometry of joint2 Transform xfB = m_bodyB.m_xf; float aB = m_bodyB.m_sweep.a; Transform xfD = m_bodyD.m_xf; float aD = m_bodyD.m_sweep.a; if (m_typeB == JointType.e_revoluteJoint) { RevoluteJoint revolute = (RevoluteJoint)def.joint2; m_localAnchorD = revolute.m_localAnchorA; m_localAnchorB = revolute.m_localAnchorB; m_referenceAngleB = revolute.m_referenceAngle; m_localAxisD.SetZero(); coordinateB = aB - aD - m_referenceAngleB; } else { PrismaticJoint prismatic = (PrismaticJoint)def.joint2; m_localAnchorD = prismatic.m_localAnchorA; m_localAnchorB = prismatic.m_localAnchorB; m_referenceAngleB = prismatic.m_referenceAngle; m_localAxisD = prismatic.m_localXAxisA; Vec2 pD = m_localAnchorD; Vec2 pB = Utilities.MulT(xfD.q, Utilities.Mul(xfB.q, m_localAnchorB) + (xfB.p - xfD.p)); coordinateB = Utilities.Dot(pB - pD, m_localAxisD); } m_ratio = def.ratio; m_constant = coordinateA + m_ratio * coordinateB; m_impulse = 0.0f; }