Shape:getPoints() behaves weird with multiple fixtures/shapes in a body [SOLVED]
Posted: Wed Feb 12, 2020 10:33 pm
This is somewhat related to my last two posts because it's about making two box2d bodies act like one, but this is a separate issue so I thought it deserved its own thread.
Since there is no getPosition() function for shapes, I've had to get their x/y positions using the points provided by Fixture:getBoundingBox() and some math. (I need to get x/y positions so I can draw an image at the object's position.) However, the bounding box returned by Fixture:getBoundingBox doesn't actually represent where the points of the shape would really be, especially in the case of rotation. Instead, I've opted to use Shape:getPoints() converted to world coordinates, so Body:getWorldPoints(Shape:getPoints()) - but it seems like this dosen't accurately show where points are when two fixtures are in one body. When one fixture gets added to a body already containing another fixture, the former just falls as if it were an independent shape that can't collide with anything - but only when drawn! In the box2d simulation, it still behaves like it's been "glued" to the former shape.
Here is a demo showing what I just described. (You can see it easier if you connect the two bodies while they're still airborne.)
Here is a version that uses Fixture:getBoundingBox() to draw the bodies. It works as intended, but only when angles aren't considered.
You may find some fragments of unused code in the demos, that's because I hastily scrapped the code for drawing and creating bodies from another project.
Also, angles aren't considered at all in both examples.
Since there is no getPosition() function for shapes, I've had to get their x/y positions using the points provided by Fixture:getBoundingBox() and some math. (I need to get x/y positions so I can draw an image at the object's position.) However, the bounding box returned by Fixture:getBoundingBox doesn't actually represent where the points of the shape would really be, especially in the case of rotation. Instead, I've opted to use Shape:getPoints() converted to world coordinates, so Body:getWorldPoints(Shape:getPoints()) - but it seems like this dosen't accurately show where points are when two fixtures are in one body. When one fixture gets added to a body already containing another fixture, the former just falls as if it were an independent shape that can't collide with anything - but only when drawn! In the box2d simulation, it still behaves like it's been "glued" to the former shape.
Here is a demo showing what I just described. (You can see it easier if you connect the two bodies while they're still airborne.)
Here is a version that uses Fixture:getBoundingBox() to draw the bodies. It works as intended, but only when angles aren't considered.
You may find some fragments of unused code in the demos, that's because I hastily scrapped the code for drawing and creating bodies from another project.
Also, angles aren't considered at all in both examples.