Raycast - Get vertices from body with multiple fixtures

Discuss issues specific to using Box2D on the iPhone
betece
Posts: 5
Joined: Fri Oct 04, 2013 2:23 am

Raycast - Get vertices from body with multiple fixtures

Postby betece » Thu Oct 10, 2013 10:45 am

Hi Box2D forum,

i have a question about a body with multiple fixtures (all fixtures are polygons). I want to split the body. For this i use a raycastcallback to figure out if the line hits the body.

The raycastcallback works fine. I make a raycast in both directions, so from startpoint to endpoint and from endpoint to startpoint.

The Problem is that the start and endpoint of the raycast not always interest the whole body. So the exitpoint (a property of my class) is always the last interection of the raycast. Because the line is the startpoint from

Code: Select all

cctouchbegan
event and the endpoint is the last location from

Code: Select all

cctouchmoved
.

To save the current states of the body a have a class with properties like sliceExit, sliceEntry etc. The property sliceExit (

Code: Select all

BOOL
) represent the final exit of the interection. I don't know how i figure out if the line exit the body, because the body has multiple figures.

You can trust me that i tried many things before posting this post. But all failed ):

My next idea would be figure out all vertices from body (not the vertices in the body, only the border of the body). But i have no idea how can i do this.

Sorry for my bad english. I hope everyone understands me. If there any questions or ambiguities about this post, ask me.

Thank you in advanced (:

Greetings Alex

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Raycast - Get vertices from body with multiple fixtures

Postby irresistible force » Fri Oct 11, 2013 6:57 am

Could you show a diagram of the problem case?

betece
Posts: 5
Joined: Fri Oct 04, 2013 2:23 am

Re: Raycast - Get vertices from body with multiple fixtures

Postby betece » Fri Oct 11, 2013 8:42 am

Here is a picture for demonstration:

Image

betece
Posts: 5
Joined: Fri Oct 04, 2013 2:23 am

Re: Raycast - Get vertices from body with multiple fixtures

Postby betece » Fri Oct 11, 2013 8:43 am

Here is a picture for demonstration:

Image

so here is the body with multiple fixtures. The line goes not always complete through the body like in this picture.

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Raycast - Get vertices from body with multiple fixtures

Postby irresistible force » Sat Oct 12, 2013 11:26 am

Ok, so that diagram is not the problem case then...

The simplest way to check one of the end points is inside a fixture is to use b2Fixture::TestPoint.

You could also cast the ray in both directions against all of the fixtures, and if you get an intersection from one direction but not the other, you'll know that one end is inside the fixture.


Return to “iPhone”



Who is online

Users browsing this forum: No registered users and 1 guest