Get Texture Name from a triangle Entity?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
dweeb
Posts: 14
Joined: Tue Jul 15, 2008 11:17 pm

Get Texture Name from a triangle Entity?

Post by dweeb »

Hi

I've got yet another question :D

I'm using the default display system and load a model in the same way as the Playground sample.

Now in my game I want to play a certain sound when an object collides with a certain part of my terrain. However the sound should be assiociate with the material (texture) that it currently collides with. So if it hits a metal texture I want to play a metallic type of sound file.

I'm using the event system to figure out when a collision occurs but how do I get the texture (that is used by the default display system) from the physics triangle entity?

Any suggestions how I can achive this or is there a better solution?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Get Texture Name from a triangle Entity?

Post by Norbo »

There's no connection between the physics entity and the display system, so it may not be best to try to go that route.

Getting identification from triangles in StaticTriangleGroup (either from collisions or raycasts) has historically been a pretty annoying task. I want and plan to remedy this, but in v0.9.0 there's not a lot of options. One possible option is to create a dictionary of triangles and their materials. The keys would be some sort of structure that takes into account the triangle's vertex positions; taking a triangle's three vertex positions and forming a hashcode from them should be sufficient. You could convert each component into an integer and multiply it by a large prime number and then sum the 9 different components (3 from each vertex). The equals method for the key would need to be overridden as well to make sure that the triangle vertex positions were compared.

The values contained in the dictionary would be triangle material types, amongst whatever else you'd like to store. The dictionary could be populated at load time and the controller created event callback could reference it later.
Post Reply