Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Box2DDebugRenderer draws incorrectly positioned AABBs for CircleShapes #2710

Closed
dermetfan opened this issue Jan 4, 2015 · 0 comments
Closed

Comments

@dermetfan
Copy link
Contributor

The Box2DDebugRenderer draws the AABBs for CircleShapes in the wrong place if they have a position set (other than 0:0) and their body is rotated. Here's a simple test:

b2bug

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.badlogic.gdx.tests.utils.GdxTest;

public class Box2DDebugRendererBug extends GdxTest implements Screen {

    World world;
    Viewport viewport;
    Box2DDebugRenderer renderer;

    public Box2DDebugRendererBug() {
        ScreenViewport sv = new ScreenViewport();
        sv.setUnitsPerPixel(1 / 32f);
        viewport = sv;
    }

    @Override
    public void create() {
        world = new World(Vector2.Zero, true);
        renderer = new Box2DDebugRenderer();
        renderer.setDrawAABBs(true);

        BodyDef bodyDef = new BodyDef();
        bodyDef.type = BodyType.DynamicBody;
        CircleShape shape = new CircleShape();
        shape.setRadius(1);
        shape.setPosition(new Vector2(0, 1)); // this causes the issue
        world.createBody(bodyDef).createFixture(shape, 1).getBody().applyTorque(200, true);
        shape.dispose();
    }

    @Override
    public void render() {
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        world.step(1 / 60f, 8, 3);
        renderer.render(world, viewport.getCamera().combined);
    }


    @Override
    public void resize(int width, int height) {
        viewport.update(width, height);
    }

    @Override
    public void dispose() {
        world.dispose();
        renderer.dispose();
    }

    // if used as Screen

    @Override
    public void show() {
        create();
    }

    @Override
    public void render(float delta) {
        render();
    }

    @Override
    public void hide() {}

}
tommyettinger pushed a commit to tommyettinger/gdx-utils that referenced this issue Sep 21, 2019
tommyettinger pushed a commit to tommyettinger/gdx-utils that referenced this issue Sep 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant