Trouble with bounding box

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
VeTaL
Posts: 14
Joined: Mon Feb 21, 2011 8:39 am

Trouble with bounding box

Post by VeTaL »

Code: Select all

 // Load mesh
   _mesh = _scene->getMesh("../Assets/Barrel.3ds");
   _node = _scene->addMeshSceneNode(_mesh);
   _node->setMaterialFlag(EMF_LIGHTING, false);
   _node->setParent(_scene->getRootSceneNode());
   pos.Y += 10;
   _node->setPosition(pos);

   // Add selector
   scene::ITriangleSelector* selector = _scene->createTriangleSelector(_mesh,_node); 
   _node->setTriangleSelector(selector); 
   _node->setName("wall"); 
   
   // Add collision responder
   const core::aabbox3d<f32>& box = _node->getBoundingBox();
   core::vector3df radius = box.MaxEdge - box.getCenter();
   scene::ISceneNodeAnimatorCollisionResponse* anim = _scene->createCollisionResponseAnimator( 
      selector, SContainer.MC->_node,radius);  // idk, why this dont works: radius is (40,25,40), thus it must works properly
   anim->setGravity(core::vector3df(0,0,0)); 
   anim->setCollisionCallback(new CollisionBarrelAndActors()); 
   SContainer.MC->_node->addAnimator(anim); 

   anim->drop(); 
   selector->drop();

#ifdef SHOW_BOUNDING_BOXES
   _node->setDebugDataVisible(scene::EDS_BBOX);
#endif
CollisionBarrelAndActors - callback from tutorial, it just prints event to console
SContainer.MC - player

Looking like players bounding ellipse is about (1,1,1).
While moving, part of the player moves incide the barrel, but then stops.

But debug shows that ellipse is large enough: (40,25,40)
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Re: Trouble with bounding box

Post by shadowslair »

Too lazy to read or test, but this looks suspicious:
VeTaL wrote: // Add collision responder
const core::aabbox3d<f32>& box = _node->getBoundingBox();
core::vector3df radius = box.MaxEdge - box.getCenter();
Probably it should be sth. like:
VeTaL wrote: // Add collision responder
const core::aabbox3d<f32>& box = _node->getTransformedBoundingBox();
core::vector3df radius = box.MaxEdge - box.getCenter();
It should be even safer to update node abs position before getting the transformed box. Just in case.
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
VeTaL
Posts: 14
Joined: Mon Feb 21, 2011 8:39 am

Post by VeTaL »

Thanks for taking a look :)
Tried your variant- still the same problem.

Anyway, debugger shows that radius is (40,25,40). :shock:

Edit: well... maybe i need to update ellipse every frame, or something like that?
shadowslair
Posts: 758
Joined: Mon Mar 31, 2008 3:32 pm
Location: Bulgaria

Re: Trouble with bounding box

Post by shadowslair »

VeTaL wrote:

Code: Select all

 
#ifdef SHOW_BOUNDING_BOXES
   _node->setDebugDataVisible(scene::EDS_BBOX);
#endif
Just note that if you`re using this for debugging, it may mislead you, because in the render()-call the node sets the driver transformation with its own, then draws its bounding box, so the bbox drawn may not be exactly the one you get. Also, keep in mind that the ellipsoid center may not match the bbox center (in case your mesh is not symmetrical etc.), so this approach may not be very good as-is in the general case. I advise you to use the debugger and check those lines to see what exactly is going wrong. I`m sure it`s something very trivial...
"Although we walk on the ground and step in the mud... our dreams and endeavors reach the immense skies..."
VeTaL
Posts: 14
Joined: Mon Feb 21, 2011 8:39 am

Post by VeTaL »

I also think that i missed something simple, but bboxes shows that everything is ok 0_0
Post Reply