I want to test for collisions between two shapes. I have a semi-working method, but it misses sometimes. This is what I do:
I think the problem is that I do s1.TestPoint( ). The points might not be inside the rectangle, but there might still be collision. Is there a ready solution provided by the library? It seems too complex to use. I know that this project has been abandoned, but I need a solution because I am making a project and I can't change the physics library now.
Thank you.
Code: Select all
private static bool CollideA(Box2DX.Dynamics.Body b1, Box2DX.Dynamics.Body b2, bool testAll)
{
Box2DX.Collision.PolygonShape s1 = (Box2DX.Collision.PolygonShape)b1.GetShapeList();
Box2DX.Collision.PolygonShape s2 = (Box2DX.Collision.PolygonShape)b2.GetShapeList();
Box2DX.Common.XForm playerXForm = b1.GetXForm();
Box2DX.Common.XForm oForm = b2.GetXForm();
while (s1 != null)
{
s2 = (Box2DX.Collision.PolygonShape)b2.GetShapeList();
while (s2 != null)
{
Box2DX.Common.Vec2[] vertices = s2.GetVertices();
foreach (Box2DX.Common.Vec2 v in vertices)
{
if (s1.TestPoint(playerXForm, b2.GetWorldPoint(v)))
return true;
}
s2 = (Box2DX.Collision.PolygonShape)((Box2DX.Collision.PolygonShape)s2).GetNext();
}
s1 = (Box2DX.Collision.PolygonShape)((Box2DX.Collision.PolygonShape)s1).GetNext();
}
return false;
}
I think the problem is that I do s1.TestPoint( ). The points might not be inside the rectangle, but there might still be collision. Is there a ready solution provided by the library? It seems too complex to use. I know that this project has been abandoned, but I need a solution because I am making a project and I can't change the physics library now.
Thank you.