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

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

Introduction

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

Prototype

public Transform getTransform() 

Source Link

Document

Get the body transform for the body's origin.

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  ww w .jav  a 2  s.co  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.altportalgames.colorrain.utils.Box2DDebugRenderer.java

License:Apache License

private void drawJoint(Joint joint) {
    Body bodyA = joint.getBodyA();
    Body bodyB = joint.getBodyB();//from   w w w  . j a v a  2  s  . c  o m
    Transform xf1 = bodyA.getTransform();
    Transform xf2 = bodyB.getTransform();

    Vector2 x1 = xf1.getPosition();
    Vector2 x2 = xf2.getPosition();
    Vector2 p1 = joint.getAnchorA();
    Vector2 p2 = joint.getAnchorB();

    if (joint.getType() == JointType.DistanceJoint) {
        drawSegment(p1, p2, JOINT_COLOR);
    } else if (joint.getType() == JointType.PulleyJoint) {
        PulleyJoint pulley = (PulleyJoint) joint;
        Vector2 s1 = pulley.getGroundAnchorA();
        Vector2 s2 = pulley.getGroundAnchorB();
        drawSegment(s1, p1, JOINT_COLOR);
        drawSegment(s2, p2, JOINT_COLOR);
        drawSegment(s1, s2, JOINT_COLOR);
    } else if (joint.getType() == JointType.MouseJoint) {
    } else {
        drawSegment(x1, p1, JOINT_COLOR);
        drawSegment(p1, p2, JOINT_COLOR);
        drawSegment(x2, p2, JOINT_COLOR);
    }
}

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// w  w w.  ja  va  2s  .c o  m
                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.blindtigergames.werescrewed.debug.SBox2DDebugRenderer.java

License:Apache License

private void drawJoint(Joint joint) {
    Body bodyA = joint.getBodyA();
    Body bodyB = joint.getBodyB();//  ww  w. j  ava2  s.  c  o m
    Transform xf1 = bodyA.getTransform();
    Transform xf2 = bodyB.getTransform();

    Vector2 x1 = xf1.getPosition();
    Vector2 x2 = xf2.getPosition();
    Vector2 p1 = joint.getAnchorA();
    Vector2 p2 = joint.getAnchorB();

    if (joint.getType() == JointType.DistanceJoint) {
        drawSegment(p1, p2, JOINT_COLOR);
    } else if (joint.getType() == JointType.PulleyJoint) {
        PulleyJoint pulley = (PulleyJoint) joint;
        Vector2 s1 = pulley.getGroundAnchorA();
        Vector2 s2 = pulley.getGroundAnchorB();
        drawSegment(s1, p1, JOINT_COLOR);
        drawSegment(s2, p2, JOINT_COLOR);
        drawSegment(s1, s2, JOINT_COLOR);
    } else if (joint.getType() == JointType.MouseJoint) {
        drawSegment(joint.getAnchorA(), joint.getAnchorB(), JOINT_COLOR);
    } else {
        drawSegment(x1, p1, JOINT_COLOR);
        drawSegment(p1, p2, JOINT_COLOR);
        drawSegment(x2, p2, JOINT_COLOR);
    }
}

From source file:com.laex.cg2d.render.impl.ScreenManagerImpl.java

License:Open Source License

@Override
public Body switchAnimation(final String id, final String animationName) {
    Body switchedBody = null;/*from w w  w  .  j a va  2  s  . c om*/
    Array<Body> bodies = new Array<Body>();
    world.getBodies(bodies);

    for (Body bod : bodies) {
        CGShape shape = (CGShape) bod.getUserData();

        if (id.equals(shape.getId())) {
            try {
                Vector2 positionToCopy = new Vector2(bod.getTransform().getPosition());
                float rotation = bod.getTransform().getRotation();

                world.destroyBody(bod);
                entityManager.removeEntity(shape);

                switchedBody = entityManager.createEntity(shape, animationName);

                if (switchedBody != null) {
                    switchedBody.setTransform(positionToCopy, rotation);
                }

            } catch (IOException e) {
                AppExceptionUtil.handle(e);
            }
        }

    }

    return switchedBody;
}

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

License:Apache License

protected void renderBody(Body body) {
    Transform transform = body.getTransform();
    for (Fixture fixture : body.getFixtureList()) {
        if (drawBodies) {
            drawShape(fixture, transform, getColorByBody(body));
            if (drawVelocities) {
                Vector2 position = body.getPosition();
                drawSegment(position, body.getLinearVelocity().add(position), VELOCITY_COLOR);
            }/*from  w ww.  j a  v  a 2  s  .  c o  m*/
        }

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

From source file:com.nuliy.example.Car.java

public void KillOrthoVelocity(Body body) {
    Vector2 localP = new Vector2(0, 0);
    Vector2 velocity = body.getLinearVelocityFromLocalPoint(localP);

    float r = body.getTransform().getRotation();
    Vector2 sideways = new Vector2((float) -Math.sin(r), (float) Math.cos(r));
    sideways.scl(velocity.dot(sideways));

    body.setLinearVelocity(sideways);/*from   w w  w . j  ava2 s  .c o  m*/
}

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

License:Apache License

/** @param wake if the body should be woken up if its sleeping
 *  @see #calculateTorque(Vector2, float, float, float, float, float) */
public void rotate(Body body, Vector2 target, float angle, float force, float delta, boolean wake) {
    body.applyTorque(/*from www.  j a v a2s  . com*/
            calculateTorque(rotateRelative ? target : vec2_0.set(positionAccessor.apply(body)).sub(target),
                    body.getTransform().getRotation() + angle, body.getAngularVelocity(), body.getInertia(),
                    adaptForceToMass ? force * body.getMass() : force, delta),
            wake);
}

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

License:Apache License

/** @param wake if the body should be woken up if its sleeping
 *  @see #calculateTorque(Vector2, float, float, float, float, float) */
public void rotate(Body body, Vector2 target, float angle, float force, float delta, boolean wake) {
    body.applyTorque(/*  w  ww  .  ja  v a  2  s  .  c o m*/
            calculateTorque(rotateRelative ? target : vec2_0.set(positionAccessor.access(body)).sub(target),
                    body.getTransform().getRotation() + angle, body.getAngularVelocity(), body.getInertia(),
                    adaptForceToMass ? force * body.getMass() : force, delta),
            wake);
}

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

License:Apache License

protected void renderBody(final Body body) {
    final Transform transform = body.getTransform();
    for (final Fixture fixture : body.getFixtureList()) {
        if (this.drawBodies) {
            this.drawShape(fixture, transform, this.getColorByBody(body));
            if (this.drawVelocities) {
                final Vector2 position = body.getPosition();
                this.drawSegment(position, body.getLinearVelocity().add(position), this.VELOCITY_COLOR);
            }/*ww  w  .j a v  a 2  s.c om*/
        }

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