Java LibGDX:BoundsInfrum和BoundingBox未按预期工作
我正在从json文件加载一个box2d场景。此场景包含一个固定装置,用于标记允许摄影机在其中移动的边界框。使用这种机制可以很好地处理左下界,但完全无法处理右上界,这很奇怪 以下是从文件加载边界框的零件:Java LibGDX:BoundsInfrum和BoundingBox未按预期工作,java,math,libgdx,collision-detection,Java,Math,Libgdx,Collision Detection,我正在从json文件加载一个box2d场景。此场景包含一个固定装置,用于标记允许摄影机在其中移动的边界框。使用这种机制可以很好地处理左下界,但完全无法处理右上界,这很奇怪 以下是从文件加载边界框的零件: PolygonShape shape = ((PolygonShape) fixture.getShape()); Vector2 vertex = new Vector2(); float boundLeft = world.startX, boundRight = world.startX,
PolygonShape shape = ((PolygonShape) fixture.getShape());
Vector2 vertex = new Vector2();
float boundLeft = world.startX, boundRight = world.startX, boundUp = world.startY, boundLow = world.startY; // The location of the camera as initial value
for (int i = 0; i < shape.getVertexCount(); i++) { // Itarate over each vertex in the fixture and set the boundary values
shape.getVertex(i, vertex);
vertex.add(body.getPosition());
boundLeft = Math.min(vertex.x, boundLeft);
boundLow = Math.min(vertex.y, boundLow);
boundRight = Math.max(vertex.x, boundRight);
boundUp = Math.max(vertex.y, boundUp);
}
// Build the bounding boxes with enough thickness to prevent tunneling on fast pans
world.boundLeft = new BoundingBox(new Vector3(boundLeft - 5, boundLow - 5, 0).scl(RenderingSystem.PPM), new Vector3(boundLeft, boundUp + 5, 0).scl(RenderingSystem.PPM));
world.boundRight = new BoundingBox(new Vector3(boundRight, boundLow - 5, 0).scl(RenderingSystem.PPM), new Vector3(boundRight + 5, boundUp + 5, 0).scl(RenderingSystem.PPM));
world.boundUp = new BoundingBox(new Vector3(boundLeft - 5, boundUp, 0).scl(RenderingSystem.PPM), new Vector3(boundRight + 5, boundUp + 5, 0).scl(RenderingSystem.PPM));
world.boundLow = new BoundingBox(new Vector3(boundLeft - 5, boundLow - 5, 0).scl(RenderingSystem.PPM), new Vector3(boundRight + 5, boundLow, 0).scl(RenderingSystem.PPM));
// world is a class containing some properties, including these BoundingBoxes
// RenderingSystem.PPM is the amount of pixels per metre, in this case 64
嗯,我知道了。猜猜我的world.startx和world.startY的定义是什么?没错,它们在屏幕坐标中:
world.startX = start.getPosition().x * RenderingSystem.PPM;
world.startY = start.getPosition().y * RenderingSystem.PPM;
这导致Math.max总是选择world.startX和world.startY,因为相比之下,这些值绝对是巨大的。为什么不跟libdx的家伙谈谈呢?有很多人抱怨这个库!哦,我不是在抱怨。LibGDX是我一生的挚爱,我随时都会嫁给它,只是我经常不如LibGDX的人聪明。
world.startX = start.getPosition().x * RenderingSystem.PPM;
world.startY = start.getPosition().y * RenderingSystem.PPM;