Trimesh to trimesh collision -- New shape

BundesWehr4

20-02-2008 18:40:57

I create a new shape using GImpact ( Bullet_Root\Extras )

Sources:

OgreBulletCollisionsGImpactShape.h

#ifndef _OGREBULLETCOLLISIONS_GImpact_Shapes_H
#define _OGREBULLETCOLLISIONS_GImpact_Shapes_H
#include "OgreBulletCollisionsPreRequisites.h"

#include "Extras/GIMPACT/include/GIMPACT/Bullet/btGImpactShape.h"
#include "Extras/GIMPACT/include/GIMPACT/Bullet/btGImpactCollisionAlgorithm.h"

#include "OgreBulletCollisionsShape.h"

namespace OgreBulletCollisions
{
class __declspec( dllexport ) GImpactConcaveShape : public CollisionShape
{
public:
GImpactConcaveShape(Ogre::Vector3 *_vertices, unsigned int _vertex_count, unsigned int *_indices, unsigned int_index_count);
virtual ~GImpactConcaveShape();

bool drawWireFrame(DebugLines *wire) const;
private:
btTriangleMesh* mTriMesh;
};
}
#endif



OgreBulletCollisionsGImpactShape.cpp


#include "OgreBulletCollisions.h"
#include "OgreBulletCollisionsGImpactShape.h"

using namespace Ogre;
using namespace OgreBulletCollisions;

namespace OgreBulletCollisions
{
GImpactConcaveShape::GImpactConcaveShape(
Ogre::Vector3 *_vertices,
unsigned int _vertex_count,
unsigned int *_indices,
unsigned int int_index_count) : CollisionShape(), mTriMesh(0)
{
mTriMesh = new btTriangleMesh();

unsigned int numFaces = int_index_count / 3;

btVector3 vertexPos[3];
for (size_t n = 0; n < numFaces; ++n)
{
for (unsigned int i = 0; i < 3; ++i)
{
const Vector3 &vec = _vertices[*_indices];
vertexPos[i][0] = vec.x;
vertexPos[i][1] = vec.y;
vertexPos[i][2] = vec.z;
*_indices++;
}

mTriMesh->addTriangle(vertexPos[0], vertexPos[1], vertexPos[2]);
}

btGImpactMeshShape * trimesh = new btGImpactMeshShape(mTriMesh);
trimesh->setLocalScaling(btVector3(1, 1, 1));
trimesh->updateBound();
mShape = trimesh;
}

GImpactConcaveShape::~GImpactConcaveShape()
{
}

bool GImpactConcaveShape::drawWireFrame(OgreBulletCollisions::DebugLines *wire) const
{
return false;
}
}



You need to add this into OgreBulletDynamics::DynamicsWorld


btCollisionDispatcher * dispatcher = static_cast<btCollisionDispatcher *>(mWorld->getDispatcher());
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);


like this:

DynamicsWorld::DynamicsWorld(Ogre::SceneManager *mgr,
const Ogre::AxisAlignedBox &bounds,
const Ogre::Vector3 &gravity,
bool init) :
CollisionsWorld(mgr, bounds, false),
mDebugDrawer(0)
{
//btSequentialImpulseConstraintSolver
//btSequentialImpulseConstraintSolver3
mConstraintsolver = new btSequentialImpulseConstraintSolver();

//only if init is true, otherwise you have to create mWorld manually later on
if (init) {
mWorld = new btDiscreteDynamicsWorld(mDispatcher, mBroadphase, mConstraintsolver, &mDefaultCollisionConfiguration);
static_cast <btDiscreteDynamicsWorld *> (mWorld)->setGravity(btVector3(gravity.x,gravity.y,gravity.z));
btCollisionDispatcher * dispatcher = static_cast<btCollisionDispatcher *>(mWorld->getDispatcher());
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);
}

}


You also need to add libGIMPACT.lib in Linker settings

tuan kuranes

16-04-2008 17:55:10

Thanks a lot, added into CVS.