patch for trimesh side getter on contacts

ekt

07-11-2006 19:17:00

actually in ode is implemented only for trimesh. it gives you the triangle index collided. if you map the tri index with your mesh material you can take different actions based on materials

changes are in OgreOdeCollision.cpp


@@ -56,16 +60,6 @@
return (Geometry*)dGeomGetData(g);
}

-int Contact::getFirstSide()
-{
- return _contact->geom.side1;
-}
-
-int Contact::getSecondSide()
-{
- return _contact->geom.side2;
-}
-
void Contact::setFirstFrictionDirection(const Ogre::Vector3& vector)
{
_contact->fdir1[0] = (dReal)vector.x;
@@ -177,32 +171,32 @@


patch is incomplete. let me know if you would consider applying this patch, i can generate a correct one. also, shall i have to post it here or there is a patch tracker somewher?

cheers
Ettore

Anonymous

17-11-2006 17:12:52

Just wanted to say that I think this sounds very interesting! I have not yet encountered a situation where I would need it, but it seems like a very good feature.

ekt

18-11-2006 09:08:10

it's in ode since an year or so, and in my ogreode since then. i'm waiting for a sign from tuan ;)

tuan kuranes

29-11-2006 14:55:26

It's in CVS. Next Released version will then have it.
Thanks.

ekt

06-12-2006 00:42:18

while we are at this, i'll explain how i'm using it.

in EntityInformer::addEntity, nearly at the end, while looping through subentites, i've added this:


// store the highest tri-index of this material
String s = sub_mesh->getMaterialName();
addMaterialData(s, _index_count/3 );


basically it populates this structure

// key is the highest tri-index used by the material id stored in the value
typedef std::map<int, int> MaterialRange;


in this way

void EntityInformer::addMaterialData(String materialName, int lastTriangleIndex)
{
...
int material_id=_materials.size()+1;
_materials[lastTriangleIndex]=material_id;
}



finally, i use it in this way (kPhysicalTrimesh it's a class deriving from OgreOde::TriangleMeshGeometry, and receives a MaterialRange when built from an EntityInformer.


// returns the material-id of the triangle passed
int kPhysicalTrimesh::getTriangleMaterial(int triangle)
{
MaterialRange::iterator pos;
int range_lower;
int range_upper;

// each succesive key in MaterialRange defines a range
// tri-indexs contained in the range shares the same material

// first range starts from -1 in order to include triangle index==0
range_upper=-1;

for (pos = _materials.begin(); pos!=_materials.end(); ++pos) {

// key is the index of the last triangle of a material
// hence, we can think of it as the right limit of the range
range_lower=range_upper;
range_upper=pos->first;

// if the tri-index is between the current range
// return the map value, which is the material id
if ((triangle<=range_upper) && (triangle>range_lower))
return pos->second;

}

// if we are here, something went wrong
assert(0);
return -1;
}


i then can query my trimesh and know if my contact is over sand, grass, etc. contact side gets usefull for this obviously.

i doubt it's clear, but it works well. if you think it could make any sense porting this to OgreODE, let's talk about it

cheers

tuan kuranes

06-12-2006 14:12:08

I'm all for it.
Can you provide a Patch ?
(and if possible add necessary demo code in zombie simples_scene)

ekt

06-12-2006 15:01:04

sure for the patch :) i was thinking of an additional demo scene. i'll see what i can do but i don't promise nothing

tuan kuranes

14-12-2006 14:39:19

Keep in mind that most 3D real time models would use a single texture/material per model for GPU batching reasons, so getting index would be the best bet. User will make the "physic material" match client side, surely using a "physic material map" getting texture coordinates using the index of triangles under contacts.