RayCast and StaticTriangleGroup

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
J2T
Posts: 48
Joined: Sat Sep 20, 2008 6:20 pm
Contact:

RayCast and StaticTriangleGroup

Post by J2T »

Hi norbo,

i looked at your sample with the smart camera and how you do that. I've tooked this as an really good start and changed it a bit to make it common with our needs. Now there is one problem and one question :)

First the question: Is it somehow possible to get the meshpart which gets hit by the ray nativ with BEPU?If not to you know another way maybe picking because i have the hitposition?Never used picking befor and i only know that i can get the mesh/meshpart from screencoordinates(mouseclick) with that method. But maybe also with 'normal' positions/vectors.

Now the problem: What could be reason that a raycast can't find a hitposition/hitentitie when there is clearly ones(visible)?Please look at this picture. When i walk under this terrace there is no hit recognized. When i walk direkt under the house there is. Btw on all other walls/ramps(i think you can remember :wink:) , houses etc. it works also wonderfull. Maybe a triangulation problem again?

Thanks for continous help!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: RayCast and StaticTriangleGroup

Post by Norbo »

Currently, the StaticTriangleGroup has no internal separation between different loaded meshes. If you need to know if a particular hit comes from a particular mesh, you would need to have multiple StaticTriangleGroups (one representing each mesh). Then, you would need to use a StaticTriangleGroup raycast for each of these to check for hits rather than using space.raycast.

For the problem, note that the hitEntity for a StaticTriangleGroup will be null since there is generally no entity where a raycast is hitting, just the internal representation which isn't composed of entities. I believe it should always put a null entry in the hitEntities for any StaticTriangleGroup hit, even if a triangle is present. It should still have a valid position, though. Does the raycast find any entries at all in the cases where it doesn't appear to work?
doggan
Posts: 20
Joined: Fri Jan 09, 2009 9:26 pm

Re: RayCast and StaticTriangleGroup

Post by doggan »

Not to hijack this thread, but where is this 'smart camera' implementation you speak of located? Thanks.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: RayCast and StaticTriangleGroup

Post by Norbo »

If I'm not mistaken, he is referring to the chase camera system used by the vehicle and such implemented within the Camera update method itself. It is the block surrounded by the if (isChaseCameraMode).
J2T
Posts: 48
Joined: Sat Sep 20, 2008 6:20 pm
Contact:

Re: RayCast and StaticTriangleGroup

Post by J2T »

doggan, yes norbo is right i'm talking about the chase camera used by the vehicle.

Norbo, there are no entries at all. It's really strange. When i jump with the character under the terrace and the character it self hit the terrace there will be the rayintersect. But it must also before because the character is fully covered by the terracemesh.
Our artist will do some different version of the terrace with different triangulations. Maybe this solves the problem at all.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: RayCast and StaticTriangleGroup

Post by Norbo »

Are you currently using v0.8.0? There was a bug in previous versions that could be causing what you're describing. A ray that started outside of the the bounding box of a StaticTriangleGroup would fail to detect anything. This bug would also require that you have multiple StaticTriangleGroups, since otherwise it looks like the situation that you have there would have the character fully within the AABB of the whole map if it was a single Group.
J2T
Posts: 48
Joined: Sat Sep 20, 2008 6:20 pm
Contact:

Re: RayCast and StaticTriangleGroup

Post by J2T »

Yes im using the current version 0.8.0...
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: RayCast and StaticTriangleGroup

Post by Norbo »

I can't really think of anything else right now; could I get a reproduction case perhaps? Some mesh that does it with some associated sample code would help a lot in diagnosing the issue.
J2T
Posts: 48
Joined: Sat Sep 20, 2008 6:20 pm
Contact:

Re: RayCast and StaticTriangleGroup

Post by J2T »

Thanks for this offer!

But befor we'll change the triangulation and i hope this would solve the problem because putting a reproduction sample out of the game and engine would be much more work.
J2T
Posts: 48
Joined: Sat Sep 20, 2008 6:20 pm
Contact:

Re: RayCast and StaticTriangleGroup

Post by J2T »

Hi Norbo,

after some days of vacation i started today again to solve this problem. After we tested a lot of different meshes there was no solution through this. So i began testing a lot again in the source. And yeahh i got it. It was just a 'false' raydestination which i changed befor but maybe with bad values for this case.

Btw thanks for new version. The new broadphase system gives me around five frames extra now. Very well done :)

edit: Norbo btw you said the is no seperation of the meshparts in StaticTriangleGroup. But as i mentioned it could be very usefull when i get the meshpart(the name) which gets hitted by a ray. Is something in your mind for further version?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: RayCast and StaticTriangleGroup

Post by Norbo »

I will probably be revising the way the raycast framework works at some point (but not in v0.10.0, I'm leaving that fairly sparse so I can focus on implementing multithreading).

However, in the immediate term, v0.9.0 includes some changes that should make it possible for you to identify the mesh that you hit, if in a roundabout way. Basically, the StaticTriangleGroup now uses a TriangleMesh for queries and storage. It uses the type TriangleMeshVertex for vertices within it. The StaticTriangleGroupVertex is a subclass of that type which the StaticTriangleGroup uses (it stores additional optional information about per-vertex friction and bounciness).

You could create your own subclass of StaticTriangleGroupVertex which includes an object 'tag' or simply a string name for each vertex. In a content processor, you can assign these names/tags to their meshPart or whatever other identification you'd like. Now when you create your TriangleMesh, give it an array of these custom vertex types that are a subclass of StaticTriangleGroupVertex. There is a StaticTriangleGroup.rayCast method that returns the indices of the hit vertices; grab these and access the TriangleMesh.vertices list. Cast them to your type and look at the tag/name.
J2T
Posts: 48
Joined: Sat Sep 20, 2008 6:20 pm
Contact:

Re: RayCast and StaticTriangleGroup

Post by J2T »

Thanks for this suggestion. I'll take a closer look the next few days.
Post Reply