Raycasts on StaticTriangleGroups

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
doggan
Posts: 20
Joined: Fri Jan 09, 2009 9:26 pm

Raycasts on StaticTriangleGroups

Post by doggan »

- Calling PhysicsSpace.rayCast() will return a list of entities that have been intersected by the ray.
- An intersection with a StaticTriangleGroup will create a null entry in the entity list.
- Since the entry is null, we have no data about the entity that was intersected, which makes it difficult to do a look-up.

My question: If a scene has many StaticTriangleGroups in it, what is the best way to determine WHICH StaticTriangleGroup has been intersected?

One (ugly) solution would be to perform a raycast on each of the StaticTriangleGroups in the scene, and see which one returns true... However, this won't really work if a single ray intersects multiple StaticTriangleGroups, as we will be left with multiple possibilities.

Any ideas? Thanks.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Raycasts on StaticTriangleGroups

Post by Norbo »

The most straightforward solution is to raycast against each individual StaticTriangleGroup and then pick the group with the smallest time of impact. This is essentially what the Space.rayCast does for the one-hit version of the method.

I'm not a real big fan of the way I've got the rayCast system set up since it's fairly inflexible, so it might go through some significant changes in the future.
doggan
Posts: 20
Joined: Fri Jan 09, 2009 9:26 pm

Re: Raycasts on StaticTriangleGroups

Post by doggan »

Thanks. Yeah, that method would work for now.

On a slightly separate topic... Not sure if this is a bug or there is a setting somewhere that I don't see: raycasts on a StaticTriangleGroup fail if the origin of the raycast is outside of the convex hull of the triangle mesh.

As an example, you can take a simple cube mesh. Create a StaticTriangleGroup for it to process the vertices, then add it to the space. If you do a raycast from the origin of the camera outwards, you will never get an intersection until you position the camera 'inside' the cube.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Raycasts on StaticTriangleGroups

Post by Norbo »

That is indeed a bug and is fixed in the next version.
Post Reply