Search in sources :

Example 1 with MouseJoint

use of com.badlogic.gdx.physics.box2d.joints.MouseJoint in project libgdx by libgdx.

the class World method createJoint.

/*
		b2World* world = (b2World*)(addr);
		b2Body* body = (b2Body*)(bodyAddr);	
		CustomContactFilter contactFilter(env, object);
		CustomContactListener contactListener(env, object);
		world->SetContactFilter(&contactFilter);
		world->SetContactListener(&contactListener);
		body->SetActive(false);
		world->SetContactFilter(&defaultFilter);
		world->SetContactListener(0);
	*/
/** 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, ((GearJointDef) def).joint1, ((GearJointDef) def).joint2);
    if (def.type == JointType.MotorJoint)
        joint = new MotorJoint(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.RopeJoint)
        joint = new RopeJoint(this, jointAddr);
    if (def.type == JointType.WeldJoint)
        joint = new WeldJoint(this, jointAddr);
    if (def.type == JointType.WheelJoint)
        joint = new WheelJoint(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;
}
Also used : FrictionJoint(com.badlogic.gdx.physics.box2d.joints.FrictionJoint) WeldJoint(com.badlogic.gdx.physics.box2d.joints.WeldJoint) GearJoint(com.badlogic.gdx.physics.box2d.joints.GearJoint) RevoluteJoint(com.badlogic.gdx.physics.box2d.joints.RevoluteJoint) GearJoint(com.badlogic.gdx.physics.box2d.joints.GearJoint) RopeJoint(com.badlogic.gdx.physics.box2d.joints.RopeJoint) PulleyJoint(com.badlogic.gdx.physics.box2d.joints.PulleyJoint) WheelJoint(com.badlogic.gdx.physics.box2d.joints.WheelJoint) FrictionJoint(com.badlogic.gdx.physics.box2d.joints.FrictionJoint) MotorJoint(com.badlogic.gdx.physics.box2d.joints.MotorJoint) MouseJoint(com.badlogic.gdx.physics.box2d.joints.MouseJoint) RevoluteJoint(com.badlogic.gdx.physics.box2d.joints.RevoluteJoint) PrismaticJoint(com.badlogic.gdx.physics.box2d.joints.PrismaticJoint) WeldJoint(com.badlogic.gdx.physics.box2d.joints.WeldJoint) DistanceJoint(com.badlogic.gdx.physics.box2d.joints.DistanceJoint) PulleyJoint(com.badlogic.gdx.physics.box2d.joints.PulleyJoint) WheelJoint(com.badlogic.gdx.physics.box2d.joints.WheelJoint) RopeJoint(com.badlogic.gdx.physics.box2d.joints.RopeJoint) DistanceJoint(com.badlogic.gdx.physics.box2d.joints.DistanceJoint) MotorJoint(com.badlogic.gdx.physics.box2d.joints.MotorJoint) MouseJoint(com.badlogic.gdx.physics.box2d.joints.MouseJoint) PrismaticJoint(com.badlogic.gdx.physics.box2d.joints.PrismaticJoint)

Example 2 with MouseJoint

use of com.badlogic.gdx.physics.box2d.joints.MouseJoint in project RubeLoader by tescott.

the class JointSerializer method read.

@SuppressWarnings("rawtypes")
@Override
public Joint read(Json json, JsonValue jsonData, Class type) {
    if (bodies == null || world == null)
        return null;
    int indexA = json.readValue("bodyA", int.class, bodies.size, jsonData);
    int indexB = json.readValue("bodyB", int.class, bodies.size, jsonData);
    if (indexA >= bodies.size || indexB >= bodies.size)
        return null;
    Joint joint = null;
    JointDef jointDef = null;
    String jointType = json.readValue("type", String.class, jsonData);
    if (jointType == null)
        return null;
    // First pass
    if (joints == null && !jointType.equals("gear")) {
        if (jointType.equals("revolute")) {
            jointDef = json.readValue(RevoluteJointDef.class, jsonData);
        } else if (jointType.equals("prismatic")) {
            jointDef = json.readValue(PrismaticJointDef.class, jsonData);
        } else if (jointType.equals("distance")) {
            jointDef = json.readValue(DistanceJointDef.class, jsonData);
        } else if (jointType.equals("pulley")) {
            jointDef = json.readValue(PulleyJointDef.class, jsonData);
        } else if (jointType.equals("mouse")) {
            jointDef = json.readValue(MouseJointDef.class, jsonData);
        } else if (jointType.equals("wheel")) {
            jointDef = json.readValue(WheelJointDef.class, jsonData);
        } else if (jointType.equals("weld")) {
            jointDef = json.readValue(WeldJointDef.class, jsonData);
        } else if (jointType.equals("friction")) {
            jointDef = json.readValue(FrictionJointDef.class, jsonData);
        } else if (jointType.equals("rope")) {
            jointDef = json.readValue(RopeJointDef.class, jsonData);
        }
    } else if (// Second pass
    joints != null && jointType.equals("gear")) {
        jointDef = json.readValue(GearJointDef.class, jsonData);
    }
    if (jointDef != null) {
        jointDef.bodyA = bodies.get(indexA);
        jointDef.bodyB = bodies.get(indexB);
        jointDef.collideConnected = json.readValue("collideConnected", boolean.class, RubeDefaults.Joint.collideConnected, jsonData);
        joint = world.createJoint(jointDef);
        if (jointType.equals("mouse")) {
            ((MouseJoint) joint).setTarget(mouseJointDefSerializer.target);
        }
    }
    scene.parseCustomProperties(json, joint, jsonData);
    String name = json.readValue("name", String.class, jsonData);
    if (name != null) {
        scene.putNamed(name, joint);
    }
    return joint;
}
Also used : PrismaticJointDef(com.badlogic.gdx.physics.box2d.joints.PrismaticJointDef) PulleyJointDef(com.badlogic.gdx.physics.box2d.joints.PulleyJointDef) FrictionJointDef(com.badlogic.gdx.physics.box2d.joints.FrictionJointDef) MouseJointDef(com.badlogic.gdx.physics.box2d.joints.MouseJointDef) RevoluteJointDef(com.badlogic.gdx.physics.box2d.joints.RevoluteJointDef) RopeJointDef(com.badlogic.gdx.physics.box2d.joints.RopeJointDef) GearJointDef(com.badlogic.gdx.physics.box2d.joints.GearJointDef) WeldJointDef(com.badlogic.gdx.physics.box2d.joints.WeldJointDef) DistanceJointDef(com.badlogic.gdx.physics.box2d.joints.DistanceJointDef) WheelJointDef(com.badlogic.gdx.physics.box2d.joints.WheelJointDef) JointDef(com.badlogic.gdx.physics.box2d.JointDef) RopeJointDef(com.badlogic.gdx.physics.box2d.joints.RopeJointDef) DistanceJointDef(com.badlogic.gdx.physics.box2d.joints.DistanceJointDef) Joint(com.badlogic.gdx.physics.box2d.Joint) MouseJoint(com.badlogic.gdx.physics.box2d.joints.MouseJoint) MouseJoint(com.badlogic.gdx.physics.box2d.joints.MouseJoint) WeldJointDef(com.badlogic.gdx.physics.box2d.joints.WeldJointDef) Joint(com.badlogic.gdx.physics.box2d.Joint) MouseJoint(com.badlogic.gdx.physics.box2d.joints.MouseJoint) MouseJointDef(com.badlogic.gdx.physics.box2d.joints.MouseJointDef) RevoluteJointDef(com.badlogic.gdx.physics.box2d.joints.RevoluteJointDef)

Aggregations

MouseJoint (com.badlogic.gdx.physics.box2d.joints.MouseJoint)2 Joint (com.badlogic.gdx.physics.box2d.Joint)1 JointDef (com.badlogic.gdx.physics.box2d.JointDef)1 DistanceJoint (com.badlogic.gdx.physics.box2d.joints.DistanceJoint)1 DistanceJointDef (com.badlogic.gdx.physics.box2d.joints.DistanceJointDef)1 FrictionJoint (com.badlogic.gdx.physics.box2d.joints.FrictionJoint)1 FrictionJointDef (com.badlogic.gdx.physics.box2d.joints.FrictionJointDef)1 GearJoint (com.badlogic.gdx.physics.box2d.joints.GearJoint)1 GearJointDef (com.badlogic.gdx.physics.box2d.joints.GearJointDef)1 MotorJoint (com.badlogic.gdx.physics.box2d.joints.MotorJoint)1 MouseJointDef (com.badlogic.gdx.physics.box2d.joints.MouseJointDef)1 PrismaticJoint (com.badlogic.gdx.physics.box2d.joints.PrismaticJoint)1 PrismaticJointDef (com.badlogic.gdx.physics.box2d.joints.PrismaticJointDef)1 PulleyJoint (com.badlogic.gdx.physics.box2d.joints.PulleyJoint)1 PulleyJointDef (com.badlogic.gdx.physics.box2d.joints.PulleyJointDef)1 RevoluteJoint (com.badlogic.gdx.physics.box2d.joints.RevoluteJoint)1 RevoluteJointDef (com.badlogic.gdx.physics.box2d.joints.RevoluteJointDef)1 RopeJoint (com.badlogic.gdx.physics.box2d.joints.RopeJoint)1 RopeJointDef (com.badlogic.gdx.physics.box2d.joints.RopeJointDef)1 WeldJoint (com.badlogic.gdx.physics.box2d.joints.WeldJoint)1