Jump to content

Material info from collision?


Digiverse
 Share

Recommended Posts

Hi,

 

I'm loving Leadwerks, just wonder if someone can point me in the right direction with this problem...

 

Is there a way of obtaining the texture name that has been hit in a collision (in C++)?

 

I'm using the collision callback function and I'm aware this can identify the entities involved in a collision as well as the collision point.

 

However, I need to be able to find out which material has been hit in the collision, but I can't find a way of obtaining this info from the collision callback.

 

At the moment my level is essentially one large entity (one gmf) comprised of many submeshes with different materials. One non-programming solution would be to break down my geometry into seperate entities, so I'd know which material would be being hit because each entity would only have one material.

 

But before I resort to that, I was hoping to be able to get the necessary info from code. Is the only way to get such info to perform a raycast after a collision has been found, perhaps from the point of collision in the direction of the collision normal, or something? I could get surface info from a TPick then, but it doesnt sound like an ideal of doing it. Maybe there's an easier way?

 

Alternatively, is there a way of breaking up a large entity in Leadwerks into seperate entities in code, rather than manually exporting seperate ones in a 3D modelling app? In other words, can Leadwerks distinguish between submeshes within an entity and create new entities from them?

 

Thanks in advance for your help with this!

Link to comment
Share on other sites

Hi Roland, thanks for your reply.

Maybe I'm misunderstanding what constitutes as an Entity in the engine.

 

My understanding up to now is that if I create a 6-sided cube and texture each side of the cube a different material and export it as a single gmf, I can then load this in game as a single Entity.

 

So how does GetEntityMaterial(entity) know which side of the cube I'm talking about as they all have different textures?

Link to comment
Share on other sites

Yes. You can have several materials on a single entity.

In your case 6 materials. Then the Entity (which is a Mesh) will contain 6 surfaces.

Each surface has its own material.

 

TSurface GetSurface(TMesh mesh, long index=1) gives the surface you want to access

TMaterial GetSurfaceMaterial(TSurface surface) gives the material for that surface.

 

The problem then in your case is to know which surface was hit. To get that information

you will have to make some clever code to find that out. Maybe by using some raycasting function.

Roland Strålberg
Website: https://rstralberg.com

Link to comment
Share on other sites

The problem is with polygonal geometry, the physical geometry has nothing to do with the visible geometry. With BSP geometry, the physical geometry always equals the visible geometry, so that makes things a bit simpler.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Thanks for your feedback.

Adding a raycast into the collision callback actually seems to give pretty good results, as follows:

 

const float raycast_length = 0.1f;

TPick pick;

LinePick( &pick, collision_pos + ( collision_normal * raycast_length ), collision_pos - ( collision_normal * raycast_length ) );

 

Using the known collision coords and the collision normal, I apply a raycast from just before to just after the collision point.

This seems to fill a TPick with the required info from which I can get the surface and texture name.

It may not be a solution that suits every project, but it seems to be working quite well for me at the moment in determining whether my vehicle is on the road, grass or in a wall :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...