Example usage for com.badlogic.gdx.physics.box2d Transform getRotation

List of usage examples for com.badlogic.gdx.physics.box2d Transform getRotation

Introduction

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

Prototype

public float getRotation() 

Source Link

Usage

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

License:Apache License

private void drawAABB(Fixture fixture, Transform transform) {
    if (fixture.getType() == Type.Circle) {

        CircleShape shape = (CircleShape) fixture.getShape();
        float radius = shape.getRadius();
        vertices[0].set(shape.getPosition());
        vertices[0].rotate(transform.getRotation()).add(transform.getPosition());
        lower.set(vertices[0].x - radius, vertices[0].y - radius);
        upper.set(vertices[0].x + radius, vertices[0].y + radius);

        // define vertices in ccw fashion...
        vertices[0].set(lower.x, lower.y);
        vertices[1].set(upper.x, lower.y);
        vertices[2].set(upper.x, upper.y);
        vertices[3].set(lower.x, upper.y);

        drawSolidPolygon(vertices, 4, AABB_COLOR);
    } else if (fixture.getType() == Type.Polygon) {
        PolygonShape shape = (PolygonShape) fixture.getShape();
        int vertexCount = shape.getVertexCount();

        shape.getVertex(0, vertices[0]);
        lower.set(transform.mul(vertices[0]));
        upper.set(lower);/*from   w w  w. ja va  2  s. c  o  m*/
        for (int i = 1; i < vertexCount; i++) {
            shape.getVertex(i, vertices[i]);
            transform.mul(vertices[i]);
            lower.x = Math.min(lower.x, vertices[i].x);
            lower.y = Math.min(lower.y, vertices[i].y);
            upper.x = Math.max(upper.x, vertices[i].x);
            upper.y = Math.max(upper.y, vertices[i].y);
        }

        // define vertices in ccw fashion...
        vertices[0].set(lower.x, lower.y);
        vertices[1].set(upper.x, lower.y);
        vertices[2].set(upper.x, upper.y);
        vertices[3].set(lower.x, upper.y);

        drawSolidPolygon(vertices, 4, AABB_COLOR);
    }
}

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

License:Apache License

private void drawAABB(Fixture fixture, Transform transform) {
    if (fixture.getType() == Type.Circle) {

        CircleShape shape = (CircleShape) fixture.getShape();
        float radius = shape.getRadius();
        vertices[0].set(shape.getPosition());
        vertices[0].rotate(transform.getRotation()).add(transform.getPosition());
        lower.set(vertices[0].x - radius, vertices[0].y - radius);
        upper.set(vertices[0].x + radius, vertices[0].y + radius);

        // define vertices in ccw fashion...
        vertices[0].set(lower.x, lower.y);
        vertices[1].set(upper.x, lower.y);
        vertices[2].set(upper.x, upper.y);
        vertices[3].set(lower.x, upper.y);

        drawSolidPolygon(vertices, 4, AABB_COLOR, true);
    } else if (fixture.getType() == Type.Polygon) {
        PolygonShape shape = (PolygonShape) fixture.getShape();
        int vertexCount = shape.getVertexCount();

        shape.getVertex(0, vertices[0]);
        lower.set(transform.mul(vertices[0]));
        upper.set(lower);/*from   ww  w .j  a v a2 s .  co  m*/
        for (int i = 1; i < vertexCount; i++) {
            shape.getVertex(i, vertices[i]);
            transform.mul(vertices[i]);
            lower.x = Math.min(lower.x, vertices[i].x);
            lower.y = Math.min(lower.y, vertices[i].y);
            upper.x = Math.max(upper.x, vertices[i].x);
            upper.y = Math.max(upper.y, vertices[i].y);
        }

        // define vertices in ccw fashion...
        vertices[0].set(lower.x, lower.y);
        vertices[1].set(upper.x, lower.y);
        vertices[2].set(upper.x, upper.y);
        vertices[3].set(lower.x, upper.y);

        drawSolidPolygon(vertices, 4, AABB_COLOR, true);
    }
}

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

License:Apache License

private void drawAABB(final Fixture fixture, final Transform transform) {
    if (fixture.getType() == Type.Circle) {

        final CircleShape shape = (CircleShape) fixture.getShape();
        final float radius = shape.getRadius();
        vertices[0].set(shape.getPosition());
        vertices[0].rotate(transform.getRotation()).add(transform.getPosition());
        lower.set(vertices[0].x - radius, vertices[0].y - radius);
        upper.set(vertices[0].x + radius, vertices[0].y + radius);

        // define vertices in ccw fashion...
        vertices[0].set(lower.x, lower.y);
        vertices[1].set(upper.x, lower.y);
        vertices[2].set(upper.x, upper.y);
        vertices[3].set(lower.x, upper.y);

        this.drawSolidPolygon(vertices, 4, this.AABB_COLOR, true);
    } else if (fixture.getType() == Type.Polygon) {
        final PolygonShape shape = (PolygonShape) fixture.getShape();
        final int vertexCount = shape.getVertexCount();

        shape.getVertex(0, vertices[0]);
        lower.set(transform.mul(vertices[0]));
        upper.set(lower);/*from w ww. ja va2s.c  o  m*/
        for (int i = 1; i < vertexCount; i++) {
            shape.getVertex(i, vertices[i]);
            transform.mul(vertices[i]);
            lower.x = Math.min(lower.x, vertices[i].x);
            lower.y = Math.min(lower.y, vertices[i].y);
            upper.x = Math.max(upper.x, vertices[i].x);
            upper.y = Math.max(upper.y, vertices[i].y);
        }

        // define vertices in ccw fashion...
        vertices[0].set(lower.x, lower.y);
        vertices[1].set(upper.x, lower.y);
        vertices[2].set(upper.x, upper.y);
        vertices[3].set(lower.x, upper.y);

        this.drawSolidPolygon(vertices, 4, this.AABB_COLOR, true);
    }
}

From source file:org.catrobat.catroid.physics.PhysicsObject.java

License:Open Source License

private void calculateAabb(Fixture fixture, Transform transform) {
    fixtureAabbLowerLeft = new Vector2(Integer.MAX_VALUE, Integer.MAX_VALUE);
    fixtureAabbUpperRight = new Vector2(Integer.MIN_VALUE, Integer.MIN_VALUE);
    if (fixture.getType() == Shape.Type.Circle) {
        CircleShape shape = (CircleShape) fixture.getShape();
        float radius = shape.getRadius();
        tmpVertice.set(shape.getPosition());
        tmpVertice.rotate(transform.getRotation()).add(transform.getPosition());
        fixtureAabbLowerLeft.set(tmpVertice.x - radius, tmpVertice.y - radius);
        fixtureAabbUpperRight.set(tmpVertice.x + radius, tmpVertice.y + radius);
    } else if (fixture.getType() == Shape.Type.Polygon) {
        PolygonShape shape = (PolygonShape) fixture.getShape();
        int vertexCount = shape.getVertexCount();

        shape.getVertex(0, tmpVertice);//from w w  w  .  j  a v  a  2s .  co  m
        fixtureAabbLowerLeft.set(transform.mul(tmpVertice));
        fixtureAabbUpperRight.set(fixtureAabbLowerLeft);
        for (int i = 1; i < vertexCount; i++) {
            shape.getVertex(i, tmpVertice);
            transform.mul(tmpVertice);
            fixtureAabbLowerLeft.x = Math.min(fixtureAabbLowerLeft.x, tmpVertice.x);
            fixtureAabbLowerLeft.y = Math.min(fixtureAabbLowerLeft.y, tmpVertice.y);
            fixtureAabbUpperRight.x = Math.max(fixtureAabbUpperRight.x, tmpVertice.x);
            fixtureAabbUpperRight.y = Math.max(fixtureAabbUpperRight.y, tmpVertice.y);
        }
    }

    bodyAabbLowerLeft.x = Math.min(fixtureAabbLowerLeft.x, bodyAabbLowerLeft.x);
    bodyAabbLowerLeft.y = Math.min(fixtureAabbLowerLeft.y, bodyAabbLowerLeft.y);
    bodyAabbUpperRight.x = Math.max(fixtureAabbUpperRight.x, bodyAabbUpperRight.x);
    bodyAabbUpperRight.y = Math.max(fixtureAabbUpperRight.y, bodyAabbUpperRight.y);
}