detect contact bone boundingbox

dreamig

23-05-2013 10:00:37

Hi,
i have skeleton , that has of course bones

i create cylinder with ogreprocedural

Procedural::CylinderGenerator().setRadius(35).setHeight(116).realizeMesh("sphereMesh1");
Ogre::Entity* entitySphere1 = mSceneMgr->createEntity("sphereMesh1");
nodde1=mSceneMgr->getRootSceneNode()->createChildSceneNode("iam1");
nodde1->attachObject(entitySphere1);
material = Ogre::MaterialManager::getSingleton().create( "entobst1","General");

material->getTechnique( 0 )->getPass( 0 )->setAmbient(1,1,0);

entitySphere1->setMaterial(material);
nodde1->setPosition(-160,10,101);
entitySphere1->getBoundingBox();
nodde1->showBoundingBox(true);


and i want to detect if the hands boen touch the node or no
[attachment=0]boun.jpg[/attachment]

i calculate the distance between the hand bone and the nodes
like that
Ogre::Vector3 dd= skel1->getBone("RightHand_1")->_getDerivedPosition()-(nodde1->getPosition());
but it seem do not work

have you another idea to test if the hand are in contact with the cylinder ?

i don't want use physics just test approximately

mikachu

23-05-2013 10:29:09

Hi,
First, for anything related to collision detection, using a dedicated physics engine is always the best solution, unless you want to learn how to do this by yourself, because collision detection code can quickly become very complex.
Now, supposing you just want to learn :
In your code sample, you're calculating the distance between the bone and the position of the cylinder.
Let's call ddp the projection of dd onto the cylinder's axis.
The length of (dd-ddp) is equal to the distance between the bone and the cylinder's axis.
If it's greater than the cylinder's radius, you already know there's no contact.
If smaller, have a look at x = ddp scalar (cylinder's axis unit vector) :
- x<0 : no contact
- 0<x<height of cylinder : contact
- x>height of cylinder : no contact

Side note : those are the basics of 3d math, I'm sure you can find good resource online about dot product, cross product, projections, etc which would have helped you find by yourself :wink:

dreamig

23-05-2013 12:16:44

In fact i had another solution (but it does not worked :roll: )
1- create tagpoint and i attach it to the bone hand
ent_obstacle = mSceneMgr->createEntity(Ogre::SceneManager:: PT_SPHERE);
Ogre::Quaternion rot = Ogre::Quaternion::IDENTITY;
Ogre::TagPoint* pTagPoint=entcharacter->attachObjectToBone("RightHand_1",ent_obstacle,rot,Ogre::Vector3::ZERO);

2-and i make like that: i calculate the boundingboxaxix of the cylinder and the tagpoint
BoundingBoxCV = ent_obstacle->getBoundingBox();
BoundingBoxSol = entitySphere1 ->getBoundingBox();

BUT when i make like that
if( BoundingBoxCV.intersects(BoundingBoxSol )==true)

cout <<"it work";


it give me trur all the time even if there is not intersection

dreamig

23-05-2013 13:02:57

i tried to in place this lines

BoundingBoxCV = ent_obstacle->getBoundingBox();
BoundingBoxSol = entitySphere1 ->getBoundingBox();

i make like that

BoundingBoxCV = ent_obstacle->getWorldBoundingBox();
BoundingBoxSol = entitySphere1 ->getWorldBoundingBox();

in this case the intersection is all the time false even if there is intersection!!