MATHS. Finding the exact intersection point (m_world.Query)

Hi -

I'm using the code below to return which body has been touched by the mouse

if (!Input.mouseDown && Input.isKeyPressed(68/*D*/)){

var aabb:b2AABB = new b2AABB();
aabb.lowerBound.Set((Input.mouseX-1.0)/30, (Input.mouseY-1.0)/30);
aabb.upperBound.Set((Input.mouseX+1.0)/30, (Input.mouseY+1.0)/30);

// Query the world for overlapping shapes.
var k_maxCount:int = 1;
var shapes:Array = new Array();
var count:int = m_world.Query(aabb, shapes, k_maxCount);
for(var i:int = 0; i < count; ++i){

m_world.DestroyBody(shapes{i}.m_body);
}
}



all of the bodys are basically lines (polygons with 2 vertices).

The code works fine, but what I want to know is exactly where on the body the b2AABB has intersected.

Diagram below:

Image

I want to get 4 new x and y to create two new bodys.

So the result would be two bodies instead of one like you are deleting a part of the body and not the whole body.

Any ideas??

- M
Your current code doesn't do quite what you thing, as world.Query can (and does) return objects that are not overlapping the AABB in question. It is intended that you use query as a quick way to filter objects, and then to further processing.
That is ok, as you do intend to do so. In the new 2.0 code, every shape type has a function called TestSegment, which produces the calculation you want (you might need call it twice to get both points).

However, the 2.0 code is a bit more fussy about polygons, so you might find your technique of polygons with 2 vertices doesn't work any more, or at least is incompatible with CCD.
Hi,

Thanks for getting back to me, if i'm still using a 2 vertices polygon. how to I find the x,y of the vertices once a body has been created?

The m_world.query returns the body im working with but I dont know which property holds each vertices's x,y

I know how to do what I want now but just need to find these x and y's.

-M
You need to get the poly shape from the body with shape=body.GetShapeList();
Then cast shape to a b2PolygonShape, and then call GetVertices and GetVertexCount on that.
Thanks I've got that info now.
Im getting closer now but could someone please explain how to use the TestSegment() to return the 2 vectors I need in the original post

Image

Image

Image

Image
no one knows how the test segiment could be implemented to get the x y values I need?
bump!

This is still a problem.

Original thread: https://box2d.org/forum/viewtopic.php?t=815