// Cache here per time step to reduce cache misses. // Vec2 m_localCenterA, m_localCenterB; // float m_invMassA, m_invIA; // float m_invMassB, m_invIB; protected Joint(IWorldPool worldPool, JointDef def) { Debug.Assert(def.bodyA != def.bodyB); pool = worldPool; m_type = def.type; m_prev = null; m_next = null; m_bodyA = def.bodyA; m_bodyB = def.bodyB; m_collideConnected = def.collideConnected; m_islandFlag = false; m_userData = def.userData; m_edgeA = new JointEdge(); m_edgeA.joint = null; m_edgeA.other = null; m_edgeA.prev = null; m_edgeA.next = null; m_edgeB = new JointEdge(); m_edgeB.joint = null; m_edgeB.other = null; m_edgeB.prev = null; m_edgeB.next = null; // m_localCenterA = new Vec2(); // m_localCenterB = new Vec2(); }
public static Joint create(World world, JointDef def) { switch (def.type) { case JointType.MOUSE: return new MouseJoint(world.getPool(), (MouseJointDef)def); case JointType.DISTANCE: return new DistanceJoint(world.getPool(), (DistanceJointDef)def); case JointType.PRISMATIC: return new PrismaticJoint(world.getPool(), (PrismaticJointDef)def); case JointType.REVOLUTE: return new RevoluteJoint(world.getPool(), (RevoluteJointDef)def); case JointType.WELD: return new WeldJoint(world.getPool(), (WeldJointDef)def); case JointType.FRICTION: return new FrictionJoint(world.getPool(), (FrictionJointDef)def); case JointType.WHEEL: return new WheelJoint(world.getPool(), (WheelJointDef)def); case JointType.GEAR: return new GearJoint(world.getPool(), (GearJointDef)def); case JointType.PULLEY: return new PulleyJoint(world.getPool(), (PulleyJointDef) def); case JointType.CONSTANT_VOLUME: return new ConstantVolumeJoint(world, (ConstantVolumeJointDef)def); case JointType.ROPE: return new RopeJoint(world.getPool(), (RopeJointDef)def); case JointType.MOTOR: return new MotorJoint(world.getPool(), (MotorJointDef)def); case JointType.UNKNOWN: return null; default: return null; } }
/** * create a joint to constrain bodies together. No reference to the definition is retained. This * may cause the connected bodies to cease colliding. * * @warning This function is locked during callbacks. * @param def * @return */ public Joint createJoint(JointDef def) { Debug.Assert(isLocked() == false); if (isLocked()) { return null; } Joint j = Joint.create(this, def); // Connect to the world list. j.m_prev = null; j.m_next = m_jointList; if (m_jointList != null) { m_jointList.m_prev = j; } m_jointList = j; ++m_jointCount; // Connect to the bodies' doubly linked lists. j.m_edgeA.joint = j; j.m_edgeA.other = j.getBodyB(); j.m_edgeA.prev = null; j.m_edgeA.next = j.getBodyA().m_jointList; if (j.getBodyA().m_jointList != null) { j.getBodyA().m_jointList.prev = j.m_edgeA; } j.getBodyA().m_jointList = j.m_edgeA; j.m_edgeB.joint = j; j.m_edgeB.other = j.getBodyA(); j.m_edgeB.prev = null; j.m_edgeB.next = j.getBodyB().m_jointList; if (j.getBodyB().m_jointList != null) { j.getBodyB().m_jointList.prev = j.m_edgeB; } j.getBodyB().m_jointList = j.m_edgeB; Body bodyA = def.bodyA; Body bodyB = def.bodyB; // If the joint prevents collisions, then flag any contacts for filtering. if (def.collideConnected == false) { ContactEdge edge = bodyB.getContactList(); while (edge != null) { if (edge.other == bodyA) { // Flag the contact for filtering at the next time step (where either // body is awake). edge.contact.flagForFiltering(); } edge = edge.next; } } // Note: creating a joint doesn't wake the bodies. return j; }