@Override public void interpolate(float f) { interpolatedPositionA.x = lastPhysicsPosA.x * f; interpolatedPositionA.x += joint.getAnchorA().x * (1 - f); interpolatedPositionA.y = lastPhysicsPosA.y * f; interpolatedPositionA.y += joint.getAnchorA().y * (1 - f); interpolatedPositionB.x = lastPhysicsPosB.x * f; interpolatedPositionB.x += joint.getAnchorB().x * (1 - f); interpolatedPositionB.y = lastPhysicsPosB.y * f; interpolatedPositionB.y += joint.getAnchorB().y * (1 - f); }
@Override public void dispose() { body.setActive(false); body.setAwake(false); Iterator<Joint> joints = world.getJoints(); while (joints.hasNext()) { Joint joint = joints.next(); if (joint.getBodyA() == body || joint.getBodyB() == body) { world.destroyJoint(joint); } } world.destroyBody(body); body = 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. */ public Joint createJoint(JointDef def) { long jointAddr = createProperJoint(def); Joint joint = null; if (def.type == JointType.DistanceJoint) joint = new DistanceJoint(this, jointAddr); if (def.type == JointType.FrictionJoint) joint = new FrictionJoint(this, jointAddr); if (def.type == JointType.GearJoint) joint = new GearJoint(this, jointAddr); if (def.type == JointType.LineJoint) joint = new LineJoint(this, jointAddr); if (def.type == JointType.MouseJoint) joint = new MouseJoint(this, jointAddr); if (def.type == JointType.PrismaticJoint) joint = new PrismaticJoint(this, jointAddr); if (def.type == JointType.PulleyJoint) joint = new PulleyJoint(this, jointAddr); if (def.type == JointType.RevoluteJoint) joint = new RevoluteJoint(this, jointAddr); if (def.type == JointType.WeldJoint) joint = new WeldJoint(this, jointAddr); if (joint != null) joints.put(joint.addr, joint); JointEdge jointEdgeA = new JointEdge(def.bodyB, joint); JointEdge jointEdgeB = new JointEdge(def.bodyA, joint); joint.jointEdgeA = jointEdgeA; joint.jointEdgeB = jointEdgeB; def.bodyA.joints.add(jointEdgeA); def.bodyB.joints.add(jointEdgeB); return joint; }
@Override public void storeCurrentState() { lastPhysicsPosA.set(joint.getAnchorA()); lastPhysicsPosB.set(joint.getAnchorB()); }
@Override public Vector2 getAnchorB() { return joint.getAnchorB(); }