Java 类com.badlogic.gdx.physics.box2d.joints.WeldJointDef 实例源码

项目:old48_30_game    文件:GameScreen.java   
private Player createPlayer(World world, Cable cable) {
    CircleShape playerShape = new CircleShape();
    playerShape.setRadius(Constants.PLAYER_WIDTH / 2);
    PhysicsModel playerModel = new PhysicsModel(world, 0, 5, playerShape,
            true, BodyDef.BodyType.DynamicBody, 0.1f);
    Player player = new Player(playerModel);

    RevoluteJointDef jointDef = new RevoluteJointDef();
    jointDef.bodyA = player.getBody();
    jointDef.bodyB = cable.getBodyList().get(0);
    world.createJoint(jointDef);

    WeldJointDef weldJointDef = new WeldJointDef();
    weldJointDef.bodyA = player.getBody();
    weldJointDef.bodyB = cable.getBodyList().get(
            cable.getBodyList().size() - 1);
    weldJointDef.localAnchorA.set(-30, 8);
    world.createJoint(weldJointDef);

    return player;
}
项目:GDX-Logic-Bricks    文件:FlyingDartTest.java   
@Override
public void render() {
    super.render();
    //game.getPhysics().clearForces();

    for (WeldJointDef jointDef : flyingDartCollisionRule.jointDefs) {
        Log.debug(tag, "CreateJoint");
        physics.createJoint(jointDef);

    }
    flyingDartCollisionRule.jointDefs.clear();

    for (Joint joint : flyingDartCollisionRule.destroyJoints) {
        Log.debug(tag, "DestroyJoint");
        physics.destroyJoint(joint);

    }
    flyingDartCollisionRule.destroyJoints.clear();

}
项目:RubeLoader    文件:JointSerializer.java   
public JointSerializer(RubeScene scene,Json _json)
{
    this.scene = scene;
    _json.setSerializer(RevoluteJointDef.class,     new RevoluteJointDefSerializer());
    _json.setSerializer(PrismaticJointDef.class,    new PrismaticJointDefSerializer());
    _json.setSerializer(PulleyJointDef.class,       new PulleyJointDefSerializer());
    _json.setSerializer(WeldJointDef.class,         new WeldJointDefSerializer());
    _json.setSerializer(FrictionJointDef.class,     new FrictionJointDefSerializer());
    _json.setSerializer(WheelJointDef.class,        new WheelJointDefSerializer());
    _json.setSerializer(RopeJointDef.class,         new RopeJointDefSerializer());
    _json.setSerializer(DistanceJointDef.class,     new DistanceJointDefSerializer());
    _json.setSerializer(GearJointDef.class,         new GearJointDefSerializer());

    mouseJointDefSerializer = new MouseJointDefSerializer();

    _json.setSerializer(MouseJointDef.class,        mouseJointDefSerializer);
}
项目:RubeLoader    文件:JointSerializer.java   
@SuppressWarnings("rawtypes")
@Override
public WeldJointDef read(Json json, JsonValue jsonData, Class type)
{   
    WeldJointDef defaults = RubeDefaults.Joint.weldDef;

    WeldJointDef def = new WeldJointDef();

    Vector2 anchorA = json.readValue("anchorA", Vector2.class, defaults.localAnchorA, jsonData);
    Vector2 anchorB = json.readValue("anchorB", Vector2.class, defaults.localAnchorB, jsonData);

    if(anchorA != null && anchorB != null)
    {
        def.localAnchorA.set(anchorA);
        def.localAnchorB.set(anchorB);
        def.referenceAngle  = json.readValue("refAngle", float.class, defaults.referenceAngle, jsonData);
    }

    return def; 
}
项目:cgc-game    文件:BodyFactory.java   
public Joint createWeldJoint(Body b1, Body b2, Vector2 anchor)
{
    WeldJointDef wjd = new WeldJointDef();

    wjd.bodyA = b1;
    wjd.bodyB = b2;
    wjd.collideConnected = false;
    wjd.localAnchorA.set(Vector2.Zero);
    wjd.localAnchorB.set(anchor);
    wjd.referenceAngle = 0.0f;

    return world.createJoint(wjd);
}
项目:flixel-gdx-box2d    文件:B2FlxWeldJoint.java   
/**
 * Creates the joint.
 * @return  This joint. Handy for chaining stuff together.
 */
@Override
public B2FlxWeldJoint create()
{
    ((WeldJointDef)jointDef).initialize(bodyA, bodyB, anchorA);
    joint = B2FlxB.world.createJoint(jointDef);
    return this;
}
项目:liblol    文件:WorldActor.java   
/**
 * Create a weld joint between this actor and some other actor, to force the actors to stick
 * together.
 *
 * @param other  The actor that will be fused to this actor
 * @param otherX The X coordinate (relative to center) where joint fuses to the other actor
 * @param otherY The Y coordinate (relative to center) where joint fuses to the other actor
 * @param localX The X coordinate (relative to center) where joint fuses to this actor
 * @param localY The Y coordinate (relative to center) where joint fuses to this actor
 * @param angle  The angle between the actors
 */
public void setWeldJoint(WorldActor other, float otherX, float otherY, float localX,
                         float localY, float angle) {
    WeldJointDef w = new WeldJointDef();
    w.bodyA = mBody;
    w.bodyB = other.mBody;
    w.localAnchorA.set(localX, localY);
    w.localAnchorB.set(otherX, otherY);
    w.referenceAngle = angle;
    w.collideConnected = false;
    mExplicitWeldJoint = (WeldJoint) mScene.mWorld.createJoint(w);
}
项目:liblol    文件:MainScene.java   
/**
 * When a hero collides with a "sticky" obstacle, this figures out what to do
 *
 * @param sticky  The sticky actor... it should always be an obstacle for now
 * @param other   The other actor... it should always be a hero for now
 * @param contact A description of the contact event
 */
private void handleSticky(final WorldActor sticky, final WorldActor other, Contact contact) {
    // don't create a joint if we've already got one
    if (other.mDJoint != null)
        return;
    // don't create a joint if we're supposed to wait
    if (System.currentTimeMillis() < other.mStickyDelay)
        return;
    // go sticky obstacles... only do something if we're hitting the
    // obstacle from the correct direction
    if ((sticky.mIsSticky[0] && other.getYPosition() >= sticky.getYPosition() + sticky.mSize.y)
            || (sticky.mIsSticky[1] && other.getXPosition() + other.mSize.x <= sticky.getXPosition())
            || (sticky.mIsSticky[3] && other.getXPosition() >= sticky.getXPosition() + sticky.mSize.x)
            || (sticky.mIsSticky[2] && other.getYPosition() + other.mSize.y <= sticky.getYPosition())) {
        // create distance and weld joints... somehow, the combination is needed to get this to
        // work. Note that this function runs during the box2d step, so we need to make the
        // joint in a callback that runs later
        final Vector2 v = contact.getWorldManifold().getPoints()[0];
        mOneTimeEvents.add(new LolAction() {
            @Override
            public void go() {
                other.mBody.setLinearVelocity(0, 0);
                DistanceJointDef d = new DistanceJointDef();
                d.initialize(sticky.mBody, other.mBody, v, v);
                d.collideConnected = true;
                other.mDJoint = (DistanceJoint) mWorld.createJoint(d);
                WeldJointDef w = new WeldJointDef();
                w.initialize(sticky.mBody, other.mBody, v);
                w.collideConnected = true;
                other.mWJoint = (WeldJoint) mWorld.createJoint(w);
            }
        });
    }
}
项目:ZombieCopter    文件:PhysicsSystem.java   
@Override
protected void processEntity(Entity entity, float deltaTime) {
    PhysicsComponent physics = App.engine.mappers.physics.get(entity);
    HealthComponent health = App.engine.mappers.health.get(entity);
    StickyComponent sticky = App.engine.mappers.sticky.get(entity);

    float collisionForce = physics.getCollisionNormal();

    //Sticky projectiles
    if (sticky != null && sticky.enabled){
        Fixture stickyFixture = physics.getFixture(sticky.fixtureName);
        if (stickyFixture != null){

            boolean colliding = getContactCount(stickyFixture) > 0;

            Array<Fixture> touchingFixtures = getFixturesTouching(stickyFixture);
            for (Fixture f : touchingFixtures){
                if (f.isSensor()) colliding = false;
                else {
                    WeldJointDef jd = new WeldJointDef();
                    Body b1 = f.getBody(),
                         b2 = stickyFixture.getBody();
                    jd.initialize(b1,b2,b2.getWorldCenter());
                    world.createJoint(jd);
                    sticky.enabled = false;
                    break;
                }
            }

            if (!colliding) physics.setRotation(physics.getLinearVelocity().angle());

        }
    }

    //Collision Damage
    if (health != null && collisionForce >= health.collisionDamageThreshold){
        float dmg = collisionForce - health.collisionDamageThreshold;
        App.engine.systems.damage.dealDamage(entity,dmg);
        logger.debug(String.format("Collision damage: Entity#%d ; Force=%f ; Dmg=%f",
                                    entity.getId(),collisionForce,dmg));
    }
    physics.clearCollisionNormal();

    /*
    //Anything outside of the world bounds is destroyed
    if (!App.engine.entityBounds.contains(physics.getPosition()) &&
            entity != App.engine.getLevel().getEntity()){
        logger.debug("Destroy Entity #" + entity.getId() + ": outside of world bounds.");
        App.engine.removeEntity(physics.ownerEntity);
    }
    */

}
项目:GDX-Logic-Bricks    文件:WeldJointBuilder.java   
@Override
public void reset() {
    jointDef = new WeldJointDef();

}
项目:ingress-indonesia-dev    文件:World.java   
private long createProperJoint(JointDef paramJointDef)
{
  if (paramJointDef.type == JointDef.JointType.DistanceJoint)
  {
    DistanceJointDef localDistanceJointDef = (DistanceJointDef)paramJointDef;
    return jniCreateDistanceJoint(this.addr, localDistanceJointDef.bodyA.addr, localDistanceJointDef.bodyB.addr, localDistanceJointDef.collideConnected, localDistanceJointDef.localAnchorA.x, localDistanceJointDef.localAnchorA.y, localDistanceJointDef.localAnchorB.x, localDistanceJointDef.localAnchorB.y, localDistanceJointDef.length, localDistanceJointDef.frequencyHz, localDistanceJointDef.dampingRatio);
  }
  if (paramJointDef.type == JointDef.JointType.FrictionJoint)
  {
    FrictionJointDef localFrictionJointDef = (FrictionJointDef)paramJointDef;
    return jniCreateFrictionJoint(this.addr, localFrictionJointDef.bodyA.addr, localFrictionJointDef.bodyB.addr, localFrictionJointDef.collideConnected, localFrictionJointDef.localAnchorA.x, localFrictionJointDef.localAnchorA.y, localFrictionJointDef.localAnchorB.x, localFrictionJointDef.localAnchorB.y, localFrictionJointDef.maxForce, localFrictionJointDef.maxTorque);
  }
  if (paramJointDef.type == JointDef.JointType.GearJoint)
  {
    GearJointDef localGearJointDef = (GearJointDef)paramJointDef;
    return jniCreateGearJoint(this.addr, localGearJointDef.bodyA.addr, localGearJointDef.bodyB.addr, localGearJointDef.collideConnected, localGearJointDef.joint1.addr, localGearJointDef.joint2.addr, localGearJointDef.ratio);
  }
  if (paramJointDef.type == JointDef.JointType.MouseJoint)
  {
    MouseJointDef localMouseJointDef = (MouseJointDef)paramJointDef;
    return jniCreateMouseJoint(this.addr, localMouseJointDef.bodyA.addr, localMouseJointDef.bodyB.addr, localMouseJointDef.collideConnected, localMouseJointDef.target.x, localMouseJointDef.target.y, localMouseJointDef.maxForce, localMouseJointDef.frequencyHz, localMouseJointDef.dampingRatio);
  }
  if (paramJointDef.type == JointDef.JointType.PrismaticJoint)
  {
    PrismaticJointDef localPrismaticJointDef = (PrismaticJointDef)paramJointDef;
    return jniCreatePrismaticJoint(this.addr, localPrismaticJointDef.bodyA.addr, localPrismaticJointDef.bodyB.addr, localPrismaticJointDef.collideConnected, localPrismaticJointDef.localAnchorA.x, localPrismaticJointDef.localAnchorA.y, localPrismaticJointDef.localAnchorB.x, localPrismaticJointDef.localAnchorB.y, localPrismaticJointDef.localAxisA.x, localPrismaticJointDef.localAxisA.y, localPrismaticJointDef.referenceAngle, localPrismaticJointDef.enableLimit, localPrismaticJointDef.lowerTranslation, localPrismaticJointDef.upperTranslation, localPrismaticJointDef.enableMotor, localPrismaticJointDef.maxMotorForce, localPrismaticJointDef.motorSpeed);
  }
  if (paramJointDef.type == JointDef.JointType.PulleyJoint)
  {
    PulleyJointDef localPulleyJointDef = (PulleyJointDef)paramJointDef;
    return jniCreatePulleyJoint(this.addr, localPulleyJointDef.bodyA.addr, localPulleyJointDef.bodyB.addr, localPulleyJointDef.collideConnected, localPulleyJointDef.groundAnchorA.x, localPulleyJointDef.groundAnchorA.y, localPulleyJointDef.groundAnchorB.x, localPulleyJointDef.groundAnchorB.y, localPulleyJointDef.localAnchorA.x, localPulleyJointDef.localAnchorA.y, localPulleyJointDef.localAnchorB.x, localPulleyJointDef.localAnchorB.y, localPulleyJointDef.lengthA, localPulleyJointDef.lengthB, localPulleyJointDef.ratio);
  }
  if (paramJointDef.type == JointDef.JointType.RevoluteJoint)
  {
    RevoluteJointDef localRevoluteJointDef = (RevoluteJointDef)paramJointDef;
    return jniCreateRevoluteJoint(this.addr, localRevoluteJointDef.bodyA.addr, localRevoluteJointDef.bodyB.addr, localRevoluteJointDef.collideConnected, localRevoluteJointDef.localAnchorA.x, localRevoluteJointDef.localAnchorA.y, localRevoluteJointDef.localAnchorB.x, localRevoluteJointDef.localAnchorB.y, localRevoluteJointDef.referenceAngle, localRevoluteJointDef.enableLimit, localRevoluteJointDef.lowerAngle, localRevoluteJointDef.upperAngle, localRevoluteJointDef.enableMotor, localRevoluteJointDef.motorSpeed, localRevoluteJointDef.maxMotorTorque);
  }
  if (paramJointDef.type == JointDef.JointType.WeldJoint)
  {
    WeldJointDef localWeldJointDef = (WeldJointDef)paramJointDef;
    return jniCreateWeldJoint(this.addr, localWeldJointDef.bodyA.addr, localWeldJointDef.bodyB.addr, localWeldJointDef.collideConnected, localWeldJointDef.localAnchorA.x, localWeldJointDef.localAnchorA.y, localWeldJointDef.localAnchorB.x, localWeldJointDef.localAnchorB.y, localWeldJointDef.referenceAngle);
  }
  if (paramJointDef.type == JointDef.JointType.RopeJoint)
  {
    RopeJointDef localRopeJointDef = (RopeJointDef)paramJointDef;
    return jniCreateRopeJoint(this.addr, localRopeJointDef.bodyA.addr, localRopeJointDef.bodyB.addr, localRopeJointDef.collideConnected, localRopeJointDef.localAnchorA.x, localRopeJointDef.localAnchorA.y, localRopeJointDef.localAnchorB.x, localRopeJointDef.localAnchorB.y, localRopeJointDef.maxLength);
  }
  if (paramJointDef.type == JointDef.JointType.WheelJoint)
  {
    WheelJointDef localWheelJointDef = (WheelJointDef)paramJointDef;
    return jniCreateWheelJoint(this.addr, localWheelJointDef.bodyA.addr, localWheelJointDef.bodyB.addr, localWheelJointDef.collideConnected, localWheelJointDef.localAnchorA.x, localWheelJointDef.localAnchorA.y, localWheelJointDef.localAnchorB.x, localWheelJointDef.localAnchorB.y, localWheelJointDef.localAxisA.x, localWheelJointDef.localAxisA.y, localWheelJointDef.enableMotor, localWheelJointDef.maxMotorTorque, localWheelJointDef.motorSpeed, localWheelJointDef.frequencyHz, localWheelJointDef.dampingRatio);
  }
  return 0L;
}
项目:flixel-gdx-box2d    文件:B2FlxWeldJoint.java   
/**
 * Creates a weld joint.
 * @param spriteA
 * @param spriteB
 * @param jointDef
 */
public B2FlxWeldJoint(B2FlxShape spriteA, B2FlxShape spriteB, WeldJointDef jointDef)
{
    super(spriteA, spriteB, jointDef);
}