Domanda

I'm using Ogre and Bullet for a project and I currently have a first person camera set up with a Capsule Collision Shape. I've created a model of a cave (which will serve as the main part of the level) and imported it into my game. I'm now trying to create an OgreBulletCollisions::TriangleMeshCollisionShape of the cave.

The code I've got so far is this but it isn't working. It compiles but the Capsule shape passes straight through the cave shape. Also I have debug outlines on and there are none being drawn around the cave mesh.

Entity *cave = mSceneMgr->createEntity("Cave", "pCube1.mesh");

SceneNode *caveNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
caveNode->setPosition(0, 10, 250);
caveNode->setScale(10, 10, 10);
caveNode->rotate(Quaternion(0.5, 0.5, -0.5, 0.5));
caveNode->attachObject(cave);

OgreBulletCollisions::StaticMeshToShapeConverter *smtsc = new OgreBulletCollisions::StaticMeshToShapeConverter();
smtsc->addEntity(cave);

OgreBulletCollisions::TriangleMeshCollisionShape *tri = smtsc->createTrimesh();

OgreBulletDynamics::RigidBody *caveBody = new OgreBulletDynamics::RigidBody("cave", mWorld);
caveBody->setStaticShape(tri, 0.1, 0.8);

mShapes.push_back(tri);
mBodies.push_back(caveBody);

Any suggestions are welcome.

To clarify. It compiles but the Capsule shape passes straight through the cave shape. Also I have debug outlines on and there are none being drawn around the cave mesh

È stato utile?

Soluzione 2

In the end I had to use a btScaledBvhTriangleMeshShape. So my code now looks like

OgreBulletCollisions::StaticMeshToShapeConverter *smtsc = 
     new OgreBulletCollisions::StaticMeshToShapeConverter();
smtsc->addEntity(cave);

OgreBulletCollisions::TriangleMeshCollisionShape *tri = smtsc->createTrimesh();

OgreBulletDynamics::RigidBody *caveBody = new OgreBulletDynamics::RigidBody("cave", mWorld);

btScaledBvhTriangleMeshShape *triShape = new btScaledBvhTriangleMeshShape((btBvhTriangleMeshShape*)(tri->getBulletShape()), btVector3(150, 150, 150));

caveBody->setStaticShape(triShape, 0.0, 5, Vector3::ZERO, rotationQuaternion);
caveBody->setDebugDisplayEnabled(true);

Altri suggerimenti

I used your code and got exactly the same result - my vehicle passed right through the trimesh.

Looking at the examples in:

ogrebullet/Demos/src/OgreBulletListener.cpp

it would seem to be that instead of calling:

caveBody->setStaticShape(tri, 0.1, 0.8);

you instead need to invoke:

caveBody->setStaticShape(caveNode, tri, 0.1, 0.8, Ogre::Vector3( position_x, position_y, position_z ));`

When I made this change, the collisions work as expected

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top