Example usage for com.badlogic.gdx.physics.box2d Body getType

List of usage examples for com.badlogic.gdx.physics.box2d Body getType

Introduction

In this page you can find the example usage for com.badlogic.gdx.physics.box2d Body getType.

Prototype

public BodyType getType() 

Source Link

Document

Get the type of this body.

Usage

From source file:com.altportalgames.colorrain.utils.Box2DDebugRenderer.java

License:Apache License

private void renderBodies(World world) {
    for (Iterator<Body> iter = world.getBodies(); iter.hasNext();) {
        Body body = iter.next();
        Transform transform = body.getTransform();
        int len = body.getFixtureList().size();
        List<Fixture> fixtures = body.getFixtureList();
        for (int i = 0; i < len; i++) {
            Fixture fixture = fixtures.get(i);
            if (body.isActive() == false)
                drawShape(fixture, transform, SHAPE_NOT_ACTIVE);
            else if (body.getType() == BodyType.StaticBody)
                drawShape(fixture, transform, SHAPE_STATIC);
            else if (body.getType() == BodyType.KinematicBody)
                drawShape(fixture, transform, SHAPE_KINEMATIC);
            else if (body.isAwake() == false)
                drawShape(fixture, transform, SHAPE_NOT_AWAKE);
            else/*from w w w.  j  a  v  a2  s  .  c  o  m*/
                drawShape(fixture, transform, SHAPE_AWAKE);
        }
    }

    for (Iterator<Joint> iter = world.getJoints(); iter.hasNext();) {
        Joint joint = iter.next();
        drawJoint(joint);
    }

    int len = world.getContactList().size();
    for (int i = 0; i < len; i++)
        drawContact(world.getContactList().get(i));
}

From source file:com.blindtigergames.werescrewed.debug.SBox2DDebugRenderer.java

License:Apache License

protected void renderBody(Body body) {
    Transform transform = body.getTransform();
    int len = body.getFixtureList().size();
    List<Fixture> fixtures = body.getFixtureList();
    for (int i = 0; i < len; i++) {
        Fixture fixture = fixtures.get(i);

        if (drawBodies) {
            if (body.isActive() == false)
                drawShape(fixture, transform, SHAPE_NOT_ACTIVE);
            else if (body.getType() == BodyType.StaticBody)
                drawShape(fixture, transform, SHAPE_STATIC);
            else if (body.getType() == BodyType.KinematicBody)
                drawShape(fixture, transform, SHAPE_KINEMATIC);
            else if (body.isAwake() == false)
                drawShape(fixture, transform, SHAPE_NOT_AWAKE);
            else//from   w ww .  j  a  v a 2 s .c om
                drawShape(fixture, transform, SHAPE_AWAKE);

            if (drawVelocities) {
                Vector2 position = body.getPosition();
                drawSegment(position, body.getLinearVelocity().add(position), VELOCITY_COLOR);
            }
        }

        if (drawAABBs) {
            drawAABB(fixture, transform);
        }
    }
}

From source file:com.me.mygdxgame.Entities.MydebugRenderer.java

License:Apache License

private Color getColorByBody(Body body) {
    if (body.isActive() == false)
        return SHAPE_NOT_ACTIVE;
    else if (body.getType() == BodyType.StaticBody)
        return SHAPE_STATIC;
    else if (body.getType() == BodyType.KinematicBody)
        return SHAPE_KINEMATIC;
    else if (body.isAwake() == false)
        return SHAPE_NOT_AWAKE;
    else/*w  ww.  j a v a 2 s.c o  m*/
        return SHAPE_AWAKE;
}

From source file:com.nebula2d.scene.SceneManager.java

License:Open Source License

public static void fixedUpdate() {

    if (currentScene == null)
        return;/*from www.  j ava2s .c o m*/

    World physicalWorld = currentScene.getPhysicalWorld();
    physicalWorld.step(1 / 45f, 6, 2);

    Array<Body> bodies = new Array<Body>();
    physicalWorld.getBodies(bodies);

    for (Body body : bodies) {
        if (body.getType() != BodyDef.BodyType.StaticBody) {
            GameObject go = (GameObject) body.getUserData();
            go.setPosition(body.getPosition().x, body.getPosition().y);
            go.setRotation((float) (body.getAngle() * 180.0f / Math.PI));
        }
    }
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DUtils.java

License:Apache License

/** @param body the body for which to setup a new {@link BodyDef}
 *  @return a new {@link BodyDef} instance that can be used to clone the given body */
public static BodyDef createDef(Body body) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.active = body.isActive();//from   w  ww .j a  v a 2  s. c  o m
    bodyDef.allowSleep = body.isSleepingAllowed();
    bodyDef.angle = body.getAngle();
    bodyDef.angularDamping = body.getAngularDamping();
    bodyDef.angularVelocity = body.getAngularVelocity();
    bodyDef.awake = body.isAwake();
    bodyDef.bullet = body.isBullet();
    bodyDef.fixedRotation = body.isFixedRotation();
    bodyDef.gravityScale = body.getGravityScale();
    bodyDef.linearDamping = body.getLinearDamping();
    bodyDef.linearVelocity.set(body.getLinearVelocity());
    bodyDef.position.set(body.getPosition());
    bodyDef.type = body.getType();
    return bodyDef;
}

From source file:edu.lehigh.cse.lol.Actor.java

License:Open Source License

/**
 * Change the size of an actor, and/or change its position
 *
 * @param x      The new X coordinate of its bottom left corner
 * @param y      The new Y coordinate of its bototm left corner
 * @param width  The new width of the actor
 * @param height The new height of the actor
 *///from  ww  w.  j av a2s . c om
public void resize(float x, float y, float width, float height) {
    // To scale a polygon, we'll need a scaling factor, so we can
    // manually scale each point
    float xscale = height / mSize.y;
    float yscale = width / mSize.x;
    // set new height and width
    mSize.x = width;
    mSize.y = height;
    // read old body information
    Body oldBody = mBody;
    // make a new body
    if (mIsCircleBody) {
        Fixture oldFix = oldBody.getFixtureList().get(0);
        setCirclePhysics(oldFix.getDensity(), oldFix.getRestitution(), oldFix.getFriction(), oldBody.getType(),
                oldBody.isBullet(), x, y, (width > height) ? width / 2 : height / 2);
    } else if (mIsBoxBody) {
        Fixture oldFix = oldBody.getFixtureList().get(0);
        setBoxPhysics(oldFix.getDensity(), oldFix.getRestitution(), oldFix.getFriction(), oldBody.getType(),
                oldBody.isBullet(), x, y);
    } else if (mIsPolygonBody) {
        Fixture oldFix = oldBody.getFixtureList().get(0);
        // we need to manually scale all the vertices
        PolygonShape ps = (PolygonShape) oldFix.getShape();
        float[] verts = new float[ps.getVertexCount() * 2];
        for (int i = 0; i < ps.getVertexCount(); ++i) {
            ps.getVertex(i, mTmpVert);
            verts[2 * i] = mTmpVert.x * xscale;
            verts[2 * i + 1] = mTmpVert.y * yscale;
        }
        setPolygonPhysics(oldFix.getDensity(), oldFix.getRestitution(), oldFix.getFriction(), oldBody.getType(),
                oldBody.isBullet(), x, y, verts);
    }
    // clone forces
    mBody.setAngularVelocity(oldBody.getAngularVelocity());
    mBody.setTransform(mBody.getPosition(), oldBody.getAngle());
    mBody.setGravityScale(oldBody.getGravityScale());
    mBody.setLinearDamping(oldBody.getLinearDamping());
    mBody.setLinearVelocity(oldBody.getLinearVelocity());
    // disable the old body
    oldBody.setActive(false);
}

From source file:net.dermetfan.utils.libgdx.box2d.Box2DUtils.java

License:Apache License

/** creates a deep copy of a {@link Body}
 *  @param body the {@link Body} to copy
 *  @param shapes if the {@link Shape Shapes} of the {@link Fixture Fixures} of the given {@code body} should be {@link #copy(Shape) copied} as well
 *  @return a deep copy of the given {@code body} */
public static Body copy(Body body, boolean shapes) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.active = body.isActive();/*from   w w w  .ja  v a 2 s. co m*/
    bodyDef.allowSleep = body.isSleepingAllowed();
    bodyDef.angle = body.getAngle();
    bodyDef.angularDamping = body.getAngularDamping();
    bodyDef.angularVelocity = body.getAngularVelocity();
    bodyDef.awake = body.isAwake();
    bodyDef.bullet = body.isBullet();
    bodyDef.fixedRotation = body.isFixedRotation();
    bodyDef.gravityScale = body.getGravityScale();
    bodyDef.linearDamping = body.getLinearDamping();
    bodyDef.linearVelocity.set(body.getLinearVelocity());
    bodyDef.position.set(body.getPosition());
    bodyDef.type = body.getType();
    Body copy = body.getWorld().createBody(bodyDef);
    copy.setUserData(body.getUserData());
    for (Fixture fixture : body.getFixtureList())
        copy(fixture, copy, shapes);
    return copy;
}

From source file:org.ams.physics.things.def.DefParser.java

License:Open Source License

public static void thingWithBodyToDefinition(ThingWithBody thingWithBody, ThingWithBodyDef def) {
    Body body = thingWithBody.getBody();
    Fixture firstFixture = body.getFixtureList().first();

    thingToDefinition(thingWithBody, def);

    def.active = body.isActive();//from  ww  w . j  a v  a 2s.  c o  m
    def.angle = body.getAngle();
    def.angularDamping = body.getAngularDamping();
    def.antiCollisionGroup = thingWithBody.getAntiCollisionGroup();
    def.awake = body.isAwake();
    def.bullet = body.isBullet();
    def.categoryBits = firstFixture.getFilterData().categoryBits;
    def.density = firstFixture.getDensity();
    def.fixedRotation = body.isFixedRotation();
    def.friction = firstFixture.getFriction();
    def.groupIndex = firstFixture.getFilterData().groupIndex;
    def.linearDamping = body.getLinearDamping();
    def.maskBits = firstFixture.getFilterData().maskBits;
    def.position.set(body.getPosition());
    def.restitution = firstFixture.getRestitution();
    def.type = body.getType();

}

From source file:org.ams.testapps.paintandphysics.cardhouse.CardHouse.java

License:Open Source License

/** Get the highest free(no joints) card. */
public Body getHighestCard() {
    float top = cardHouseDef.groundY;
    Body highestBody = null;/*from  w w w.  ja v a2s. c  o m*/

    float hh = cardHouseDef.cardHeight * 0.5f;
    float hw = cardHouseDef.cardWidth * 0.5f;

    for (Thing thing : world.boxWorld.things) {
        Body body = thing.getBody();

        boolean isCard = body.isActive() && body.getType() != BodyDef.BodyType.StaticBody;
        if (!isCard)
            continue;

        boolean isFreeCard = body.getJointList().size == 0;
        if (!isFreeCard)
            continue;

        float y = body.getPosition().y;
        y += Math.max(Math.abs(Math.cos(body.getAngle()) * hh), hw);

        if (y > top) {
            top = y;
            highestBody = body;
        }

    }

    return highestBody;
}

From source file:org.box2d.r3.gdx.GDXBox2DDebugRenderer.java

License:Apache License

private Color getColorByBody(final Body body) {
    if (body.isActive() == false) {
        return this.SHAPE_NOT_ACTIVE;
    } else if (body.getType() == BodyType.StaticBody) {
        return this.SHAPE_STATIC;
    } else if (body.getType() == BodyType.KinematicBody) {
        return this.SHAPE_KINEMATIC;
    } else if (body.isAwake() == false) {
        return this.SHAPE_NOT_AWAKE;
    } else {/*from  w w  w.j a v  a  2  s . co m*/
        return this.SHAPE_AWAKE;
    }
}