public override void initTest(bool argDeserialized) { Body ground = null; { BodyDef bd = new BodyDef(); ground = getWorld().createBody(bd); EdgeShape shape = new EdgeShape(); shape.set(new Vec2(50.0f, 0.0f), new Vec2(-50.0f, 0.0f)); ground.createFixture(shape, 0.0f); } { CircleShape circle1 = new CircleShape(); circle1.m_radius = 1.0f; PolygonShape box = new PolygonShape(); box.setAsBox(0.5f, 5.0f); CircleShape circle2 = new CircleShape(); circle2.m_radius = 2.0f; BodyDef bd1 = new BodyDef(); bd1.type = BodyType.STATIC; bd1.position.set(10.0f, 9.0f); Body body1 = m_world.createBody(bd1); body1.createFixture(circle1, 5.0f); BodyDef bd2 = new BodyDef(); bd2.type = BodyType.DYNAMIC; bd2.position.set(10.0f, 8.0f); Body body2 = m_world.createBody(bd2); body2.createFixture(box, 5.0f); BodyDef bd3 = new BodyDef(); bd3.type = BodyType.DYNAMIC; bd3.position.set(10.0f, 6.0f); Body body3 = m_world.createBody(bd3); body3.createFixture(circle2, 5.0f); RevoluteJointDef jd1 = new RevoluteJointDef(); jd1.initialize(body2, body1, bd1.position); Joint joint1 = m_world.createJoint(jd1); RevoluteJointDef jd2 = new RevoluteJointDef(); jd2.initialize(body2, body3, bd3.position); Joint joint2 = m_world.createJoint(jd2); GearJointDef jd4 = new GearJointDef(); jd4.bodyA = body1; jd4.bodyB = body3; jd4.joint1 = joint1; jd4.joint2 = joint2; jd4.ratio = circle2.m_radius/circle1.m_radius; m_world.createJoint(jd4); } { CircleShape circle1 = new CircleShape(); circle1.m_radius = 1.0f; CircleShape circle2 = new CircleShape(); circle2.m_radius = 2.0f; PolygonShape box = new PolygonShape(); box.setAsBox(0.5f, 5.0f); BodyDef bd1 = new BodyDef(); bd1.type = BodyType.DYNAMIC; bd1.position.set(-3.0f, 12.0f); Body body1 = m_world.createBody(bd1); body1.createFixture(circle1, 5.0f); RevoluteJointDef jd1 = new RevoluteJointDef(); jd1.bodyA = ground; jd1.bodyB = body1; ground.getLocalPointToOut(bd1.position, ref jd1.localAnchorA); body1.getLocalPointToOut(bd1.position, ref jd1.localAnchorB); jd1.referenceAngle = body1.getAngle() - ground.getAngle(); m_joint1 = (RevoluteJoint) m_world.createJoint(jd1); BodyDef bd2 = new BodyDef(); bd2.type = BodyType.DYNAMIC; bd2.position.set(0.0f, 12.0f); Body body2 = m_world.createBody(bd2); body2.createFixture(circle2, 5.0f); RevoluteJointDef jd2 = new RevoluteJointDef(); jd2.initialize(ground, body2, bd2.position); m_joint2 = (RevoluteJoint) m_world.createJoint(jd2); BodyDef bd3 = new BodyDef(); bd3.type = BodyType.DYNAMIC; bd3.position.set(2.5f, 12.0f); Body body3 = m_world.createBody(bd3); body3.createFixture(box, 5.0f); PrismaticJointDef jd3 = new PrismaticJointDef(); jd3.initialize(ground, body3, bd3.position, new Vec2(0.0f, 1.0f)); jd3.lowerTranslation = -5.0f; jd3.upperTranslation = 5.0f; jd3.enableLimit = true; m_joint3 = (PrismaticJoint) m_world.createJoint(jd3); GearJointDef jd4 = new GearJointDef(); jd4.bodyA = body1; jd4.bodyB = body2; jd4.joint1 = m_joint1; jd4.joint2 = m_joint2; jd4.ratio = circle2.m_radius/circle1.m_radius; m_joint4 = (GearJoint) m_world.createJoint(jd4); GearJointDef jd5 = new GearJointDef(); jd5.bodyA = body2; jd5.bodyB = body3; jd5.joint1 = m_joint2; jd5.joint2 = m_joint3; jd5.ratio = 1f/circle2.m_radius; m_joint5 = (GearJoint) m_world.createJoint(jd5); } }
public override void processJoint(Joint joint, long tag) { if (tag == JOINT_TAG) { m_joint = (PrismaticJoint) joint; } else { base.processJoint(joint, tag); } }
public override void initTest(bool deserialized) { if (deserialized) { return; } Body ground = null; { BodyDef bd = new BodyDef(); ground = getWorld().createBody(bd); EdgeShape shape = new EdgeShape(); shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); ground.createFixture(shape, 0.0f); } { PolygonShape shape = new PolygonShape(); shape.setAsBox(2.0f, 0.5f); BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position.set(-10.0f, 10.0f); bd.angle = 0.5f*MathUtils.PI; bd.allowSleep = false; Body body = getWorld().createBody(bd); body.createFixture(shape, 5.0f); PrismaticJointDef pjd = new PrismaticJointDef(); // Bouncy limit Vec2 axis = new Vec2(2.0f, 1.0f); axis.normalize(); pjd.initialize(ground, body, new Vec2(0.0f, 0.0f), axis); // Non-bouncy limit // pjd.Initialize(ground, body, Vec2(-10.0f, 10.0f), Vec2(1.0f, 0.0f)); pjd.motorSpeed = 10.0f; pjd.maxMotorForce = 10000.0f; pjd.enableMotor = true; pjd.lowerTranslation = 0.0f; pjd.upperTranslation = 20.0f; pjd.enableLimit = true; m_joint = (PrismaticJoint) getWorld().createJoint(pjd); } }
public override void initTest(bool argDeserialized) { Body ground = null; { BodyDef bd = new BodyDef(); ground = getWorld().createBody(bd); EdgeShape shape = new EdgeShape(); shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f)); ground.createFixture(shape, 0.0f); } { Body prevBody = ground; // Define crank. { PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 2.0f); BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position.set(0.0f, 7.0f); Body body = getWorld().createBody(bd); body.createFixture(shape, 2.0f); RevoluteJointDef rjd = new RevoluteJointDef(); rjd.initialize(prevBody, body, new Vec2(0.0f, 5.0f)); rjd.motorSpeed = 1.0f*MathUtils.PI; rjd.maxMotorTorque = 10000.0f; rjd.enableMotor = true; m_joint1 = (RevoluteJoint) getWorld().createJoint(rjd); prevBody = body; } // Define follower. { PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 4.0f); BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position.set(0.0f, 13.0f); Body body = getWorld().createBody(bd); body.createFixture(shape, 2.0f); RevoluteJointDef rjd = new RevoluteJointDef(); rjd.initialize(prevBody, body, new Vec2(0.0f, 9.0f)); rjd.enableMotor = false; getWorld().createJoint(rjd); prevBody = body; } // Define piston { PolygonShape shape = new PolygonShape(); shape.setAsBox(1.5f, 1.5f); BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.fixedRotation = true; bd.position.set(0.0f, 17.0f); Body body = getWorld().createBody(bd); body.createFixture(shape, 2.0f); RevoluteJointDef rjd = new RevoluteJointDef(); rjd.initialize(prevBody, body, new Vec2(0.0f, 17.0f)); getWorld().createJoint(rjd); PrismaticJointDef pjd = new PrismaticJointDef(); pjd.initialize(ground, body, new Vec2(0.0f, 17.0f), new Vec2(0.0f, 1.0f)); pjd.maxMotorForce = 1000.0f; pjd.enableMotor = false; m_joint2 = (PrismaticJoint) getWorld().createJoint(pjd); } // Create a payload { PolygonShape shape = new PolygonShape(); shape.setAsBox(1.5f, 1.5f); BodyDef bd = new BodyDef(); bd.type = BodyType.DYNAMIC; bd.position.set(0.0f, 23.0f); Body body = getWorld().createBody(bd); body.createFixture(shape, 2.0f); } } }