How to obtain a hitted triangle from CollisionTree-for decal

Gucman

05-01-2007 11:43:32

I am writing a decal system. What I need is to know the triagle that was hitted with the bullet. The bullet is one physical object (it is an ellipsoid collision shape as it is a good approximation of a garlic - don't laugh we are hunting vampires ;) ) and the level geometry is a CollisionTree. I need some way to know the triangle that was hitted with the garlic. Is it possible to get this information in CollisionCallback or should i use Ray querry or something. I have found that there is a getContactFaceAttribute() which gives me the ID of a triangle but I don't know how to use this info with collisiontree to get correct face. How are you guys writting a decal systems?
Best wishes
Gucman

BergBoy

06-01-2007 03:22:37

Do a raycast (where info is your collision info):

//Bullet hole decal...

//info.mNormal;
qDir = Ogre::Vector3::UNIT_Z.getRotationTo((info.mNormal));
//pos *= 0.99;
Vector3 dPos = camray.getPoint(info.mDistance*99.9);
decalManager::instance().createDecal(decalManager::WALL_HOLE,dPos,qDir);


I use that code to extract the position and direction of the decal. The 'Create Decal' code works like:

void decalManager::createDecal(decalTypes type, Ogre::Vector3 pos, Ogre::Quaternion dir)
{
decal * holdDecal = _getAvailableDecal(type);
holdDecal->getNode()->setPosition(pos);
holdDecal->getNode()->setOrientation(dir);

Vector3 upVector;
Vector3 foo1;
Vector3 dirVec;
dir.ToAxes(foo1,upVector,dirVec);

//holdDecal->m_decalObjectSet->setCommonUpVector(upVector);
//holdDecal->m_decalObjectSet->setCommonDirection(dirVec);

holdDecal->m_alive = true;
holdDecal->m_life = 20.0f;
holdDecal->m_decalObjectSet->setVisible(true);
}


Of course you will need to make your own recycler system and storage class for your decals. This relates to http://www.ogre3d.org/phpBB2/viewtopic.php?p=195969#195969 .

Gucman

06-01-2007 11:53:48

I know this technique but it produces bad effect when decals are large. They sometimes are drawn outside the geometry when they are near the edge or on some small objects. Thus I need a triangle/face information to make the cull the decal properly so it will be entirely on geometry and no part of it sticks out.