Box2D选择缩放因子

时间:2014-11-29 10:11:04

标签: box2d

我对Box2D中的像素和米感到困惑。我知道Box2D只能在mters中工作,所以我需要SCALING FACTOR。我有多大需要它?例如,我想从我的鼠标坐标位置X和Y例如(1527,30)抛出一个Box2D对象我需要怎么做?如果我的缩放系数是private final static float PPM = 1/100f;那么我的x = 152,7, y = 3meters 这是我的代码

private void setBox2DFigures(){
        world = new World(new Vector2(0,-9.81f), true);
        rend = new Box2DDebugRenderer();
        cam = new OrthographicCamera(); // Camera 
        body = new BodyDef();
        bodyPhysics = new FixtureDef();

        CircleShape c = new CircleShape();
        body.type = BodyType.DynamicBody;
        c = new CircleShape();
        c.setRadius(20*PPM);
        c.setPosition(new Vector2(Gdx.input.getX()*PPM, Gdx.input.getY()*PPM));
        bodyPhysics.shape = c;
        world.createBody(body).createFixture(bodyPhysics);
}

这里的绘图方法我想将位置设置为我的鼠标位置

public void draw(){
    c.setPosition(new Vector2(Gdx.input.getX()*PPM, Gdx.input.getY()*PPM)); // mouse coordinates * PPM
    rend.render(world, cam.combined);
}

但我在屏幕上看不到任何内容。怎么了?我如何选择我的比例因子(PPM)?

这是我的主要

public class DesktopLauncher {
    public static void main (String[] arg) {
        LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();

        cfg.title = "Catch Me!";
        cfg.width = 1800; //1800
        cfg.height = 900; //900

        new LwjglApplication(new Game(), cfg);
    }
}

0 个答案:

没有答案