Collision only in the center of the object

luffy

07-03-2006 21:28:54

Hi, i am having some problems detecting collisions.

I have 2 objects in my world, the two have the same size, mesh, body, etc. This is the code of (one) them


Entidad::Entidad(OGR* ogre, NWT* newton, string nombre, string mesh, Vector3 tamanno, const OgreNewt::MaterialID* mat)
{
// OGRE Object creation
mEntidad = ogre->mSceneManager0->createEntity(nombre,mesh);
mNode = ogre->mSceneManager0->getRootSceneNode()->createChildSceneNode("n" + nombre);
mNode->attachObject(mEntidad);
mNode->setPosition(0,0,0);
mNode->yaw(Radian(90));
mNode->setScale(tamanno);
mEntidad->setNormaliseNormals(true);

// Newton object creation
mMat = mat;
mColision = new OgreNewt::CollisionPrimitives::Box(newton->mWorld,tamanno);
mBody = new OgreNewt::Body(newton->mWorld,mColision);
mBody->attachToNode(mNode);
mBody->setMaterialGroupID(mMat);

// Destoy collision object
delete mColision;

// Mass + inertia
Ogre::Vector3 inercia = OgreNewt::MomentOfInertia::CalcBoxSolid(10.0,tamanno);
mBody->setMassMatrix( 10.0, inercia );
mBody->setAutoFreeze(false);

// Position Orientation
mBody->setPositionOrientation(mNode->getWorldPosition(), mNode->getOrientation());

// Store a pointer to the Entidad object
this->mBody->setUserData(this);
}


My problem is that the collision ONLY start when the center of the objects collide. ¿What i am doing wrong?

walaber

07-03-2006 22:47:08

probably your newton collision shapes are smaller than your visual objects, to it looks like they overlap before they collide.

luffy

07-03-2006 23:43:50

Does not this lines make the objects with the same size?


mNode->setScale(tamanno);
mColision = new OgreNewt::CollisionPrimitives::Box(newton->mWorld,tamanno);

walaber

08-03-2006 00:42:43

only if the visual object has a size of (1,1,1), so that scaling it results in that size. that is what I did for the OgreNewt demos because it's simple.

for more complex objects, you need to determine the size (like by getting the bounding box), and make the Collision shape that size.

try implementing the debug display (OgreNewt::Debugger) to examine the difference. you can see how to use the debugger from the OgreNewt::BasicFrameListener class. or if you are using that clas, just press F3 to see the debug lines.

luffy

09-03-2006 18:07:42

Ok, thanks. It works fine!