Weird collision reaction

Larles

14-08-2008 14:42:23

Hi there (again :)),

I tried some basics with ogreBullet and I have a problem. if you look at my code, I have a static box on {0,0,0} coordinate with a size of {100,100,100}. Then I have a second box (the same but not static) on {0,300,0} coordinate.
When I run my program the second box correctly fall on the first one, but stops 100Y unit before really touching it (so on coordinate 0,200,0 instead of 0,100,0 expected). It's like if my first box was 100Y unit higher.
This give me something like that :


Here is the interesting parts of the code:

void cApplication::createScene()
{
mSceneMgr = mRoot->createSceneManager(ST_GENERIC);
Ogre::Camera *camera = mSceneMgr->createCamera("Cam");
camera->setNearClipDistance(0.1);
camera->setFarClipDistance(5000);
camera->lookAt(Ogre::Vector3::ZERO);
mCameraNode = mSceneMgr->createSceneNode("CamNode");
mCameraNode->attachObject(camera);
mCameraNode->setPosition(Ogre::Vector3(0, 5, 100));

mWindow->removeAllViewports();
Ogre::Viewport *vp = mWindow->addViewport(camera);
vp->setBackgroundColour(ColourValue(0,0,0));

camera->setAspectRatio(
Real(vp->getActualWidth()) / Real(vp->getActualHeight()));

camera->setPosition(Ogre::Vector3::ZERO);

this->_createLights();
this->_initPhysics();
this->_createFrameListener();


//---> The falling BOX


Ogre::Entity *e = mSceneMgr->createEntity("cube", "cube.mesh");
e->setQueryFlags(GEOMETRY_QUERY_MASK);
e->setNormaliseNormals(true);
Ogre::Vector3 pos;

Ogre::SceneNode *n = mSceneMgr->getRootSceneNode()->createChildSceneNode("cubeNode");
n->attachObject(e);
n->setPosition(Ogre::Vector3(0, 300, 0));
pos = n->getPosition();
n->showBoundingBox(false);

OgreBulletCollisions::StaticMeshToShapeConverter converter(e);
OgreBulletCollisions::CollisionShape *bshape = converter.createBox();
OgreBulletDynamics::RigidBody *defaultBody = new OgreBulletDynamics::RigidBody("cubebody", mworld);
defaultBody->setShape(n, bshape, 0.6f, 0.8f, 1.0f, pos, Quaternion::IDENTITY);
//<---

//---> the static BOX
e = mSceneMgr->createEntity("cube2", "cube.mesh");
e->setQueryFlags(GEOMETRY_QUERY_MASK);
e->setNormaliseNormals(true);

n = mSceneMgr->getRootSceneNode()->createChildSceneNode("cubeNode2");
n->attachObject(e);
n->setPosition(Ogre::Vector3(0, 10, 0));
pos = n->getPosition();


OgreBulletCollisions::StaticMeshToShapeConverter converter2(e);
bshape = converter2.createBox();
defaultBody = new OgreBulletDynamics::RigidBody("cubebody2", mworld);
defaultBody->setStaticShape(n, bshape, 0.6f, 0.8f, pos, Quaternion::IDENTITY);
//<---
}

void cApplication::_initPhysics()
{
Ogre::Vector3 gravity(0,-9.81,0);
Ogre::AxisAlignedBox bounds(Ogre::Vector3(-10000, -10000, -10000), Ogre::Vector3(10000, 10000, 10000));
mworld = new OgreBulletDynamics::DynamicsWorld(mSceneMgr, bounds, gravity);
}


a noob problem I guess...

nikki

15-08-2008 06:30:55

Actually, it would perhaps be much better to create your own box shape with hand written sizes, rather than use the converters.

Also, make sure that the origin of your SceneNode is in the center of the box.

seroom

31-08-2008 12:31:03

When creating bullet box shape( btboxshape ) you give box half extents so either change you're code from:


OgreBulletCollisions::CollisionShape *bshape = converter.createBox();


to:


Ogre::Vector3 size = converter.getSize()/2;
OgreBulletCollisions::CollisionShape *bshape = new BoxCollisionShape( size );


or modify line 292 in OgreBullet/Collisions/src/Utils/OgreBulletCollisionsMeshToShapeConverter.cpp to:

const Ogre::Vector3 sz = getSize()/2;