Beginner's trouble with OgreBulletDynamics::setShape

Larles

11-08-2008 20:33:22

hi there... I'm an OgreBullet beginner and I have small troubles with OgreBulletDynamics::setShape.
Actually I've copied the code that I found in the examples sourcecode for world creation :


Ogre::SceneManager *scene = QCore->getModule<cRenderer>(RENDERER)->getSceneManager("Main"); //getting my main sceneManager.
Ogre::AxisAlignedBox bounds = Ogre::AxisAlignedBox(Ogre::Vector3 (-10000, -10000, -10000),Ogre::Vector3 (10000, 10000, 10000));
Ogre::Vector3 gravity = Ogre::Vector3(0,-9.81,0);
this->mWorld = new OgreBulletDynamics::DynamicsWorld(scene, bounds, gravity);


and the object creation :
Ogre::Entity *e = mgr->createEntity("cube", "Cube.mesh");
e->setQueryFlags(QueryFlags::GEOMETRY_QUERY_MASK);
Ogre::SceneNode *n = mgr->getRootSceneNode()->createChildSceneNode();
n->attachObject(e);

Ogre::Vector3 bBoxSize = e->getBoundingBox().getSize();
OgreBulletCollisions::BoxCollisionShape *s = new OgreBulletCollisions::BoxCollisionShape(bBoxSize);
OgreBulletDynamics::RigidBody *body = new OgreBulletDynamics::RigidBody("cubeBody", this->mWorld);
Ogre::Vector3 pos = n->getPosition();
Ogre::Quaternion or = n->getOrientation();


but when I try my code, I have some troubles with an unhandlerd exception (reading violation) in Object::_notifyAttached from the ogreBulletCollisionsObject.cpp.

Really, I can't found what I've done wrong.
Any suggestion ?

nikki

12-08-2008 07:45:42

Try creating your rigid body like this (after 'n->attachObject(e)'):-
OgreBulletCollisions::StaticMeshToShapeConverter converter(e);
OgreBulletCollisions::CollisionShape shape = converter.createBox(); //Better than bounding box method.

OgreBulletDynamics::RigidBody *body = new OgreBulletDynamics::RigidBody("cubeBody", mWorld); //No need for 'this->'.

body->setShape(n, shape, 0.1, 0.8, 5, Vector3::ZERO, Quaternion::IDENTITY); //You created SceneNode with default position and orientation, which is this, no need to get.


Also, its generally a good idea to name your SceneNodes.

Larles

12-08-2008 10:09:24

Thanks for your answer.
the problem is, with your code I have this :
Unhandled exception at 0x004067e5 in TestCode.exe: 0xC0000005: Access violation reading location 0xf4df99d7.
on that line:
const Ogre::VertexElement* posElem = data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
from ogrebulletcollisionsmeshtoshapeconverter.cpp in the addStaticVertexData function.

Maybe I missed a world configuration or application configuration :|
Damn :|