Take a look at the Fixtures
class in org.jbox2d.dynamics
. It's used to attach collision shapes to bodies.
Just by looking at the source code I guess you can use Shape shape = body.m_fixtureList.m_shape
to get the first Shape of a body. You'll likely want to use a loop though unless you're absolutely sure that you will newer combine two shapes into a single body.
How do I get JBox2d Body size
-
30-06-2022 - |
Question
I can easily get the position of the body but assuming it is a box, how do I determine the coordinates of the box so I can display it?
Just to get it to display, I hard-coded it to a 10 x 10 but if I'm drawing a wall, it should be tall while a moving platform should be much smaller and wider.
public void draw() {
if (bodySocket.isConnected()) {
world = JSONObject.parse(getWorld());
} else { System.exit(1); }
background(100);
Iterator<?> keys = world.keyIterator();
String key;
JSONObject body;
while (keys.hasNext()) {
key = (String)keys.next();
body = world.getJSONObject(key);
rectMode(PApplet.RADIUS);
fill(255, 100);
rect(body.getFloat("x"), fieldBottom - body.getFloat("y"), 10, 10);
}
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow