I am confused about pixels and meters in Box2D. I know that Box2D work only in mters so I need SCALING FACTOR. How big I need it? For example I want that from my mouse coordinates position X and Y for example(1527, 30) throw an Box2D object how I need to do that?
if my scaling factor is private final static float PPM = 1/100f;
so my
x = 152,7, y = 3meters
Here is my code
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);
}
and here in a draw method I want to coin position set to my mouse position
public void draw(){
c.setPosition(new Vector2(Gdx.input.getX()*PPM, Gdx.input.getY()*PPM)); // mouse coordinates * PPM
rend.render(world, cam.combined);
}
But I don't see anything in my screen. Whats wrong? How I need to choose My scaling factor(PPM)?
here's my main
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);
}
}