I want to use TriMeshs in my game, but if I use them, I will get a strange Leak. Seems that something is not deleted correctly, but with any other shapes it worked fine.
So here is some code.
Code: Select all
btVector3& inertia_new = btVector3(0, 0, 0);
entity_ = game_env_.smgr->createEntity( id_ + "entity", mesh_filename_ );
scene_node_ = game_env_.smgr->getRootSceneNode()->createChildSceneNode( position_, rotation_ );
scene_node_->attachObject( entity_ );
entity_->setCastShadows(true);
BtOgre::StaticMeshToShapeConverter converter( entity_ );
if( shape_type == ST_BOX )
shape_ = converter.createBox();
else if( shape_type == ST_SPHERE )
shape_ = converter.createSphere();
else if( shape_type == ST_CYLINDER )
shape_ = converter.createCylinder();
else if( shape_type == ST_CONVEX )
shape_ = converter.createConvex();
else if( shape_type == ST_TRIMESH )
shape_ = converter.createTrimesh();
if(state == 0)
state_ = new BtOgre::RigidBodyState(scene_node_, btTransform( BtOgre::Convert::toBullet( rotation_ ), BtOgre::Convert::toBullet( position_ + Ogre::Vector3(0, 0, 0) ) ));
else
state_ = state;
if(mass < 0 )
mass = mass_;
else
mass_ = mass;
if(inertia.x < 0 )
{
if( mass > 0)
{
shape_->calculateLocalInertia(mass, inertia_new);
inertia_ = inertia_new;
}
else
{
inertia_ = btVector3(0,0,0);
}
}
else
{
inertia_ = BtOgre::Convert::toBullet(inertia);
}
body_ = new btRigidBody( mass_, state_, shape_, inertia_ );
level_.get_physics_world()->addRigidBody( body_ );
// Wenn auch äußerst unschön -> Dem Physikobjekt wird ein String als Userobjekt übergeben, um das Physikobjekt an das Objekt zu binden
body_->setUserPointer( this );
body_->setRestitution( 0.3 );
Code: Select all
assert(mVertexCount && (mIndexCount >= 6) &&
("Mesh must have some vertices and at least 6 indices (2 triangles)"));
unsigned int numFaces = mIndexCount / 3;
btTriangleMesh *trimesh = new btTriangleMesh();
unsigned int *indices = mIndexBuffer;
Vector3 *vertices = mVertexBuffer;
btVector3 vertexPos[3];
for (unsigned int n = 0; n < numFaces; ++n)
{
{
const Vector3 &vec = vertices[*indices];
vertexPos[0][0] = vec.x;
vertexPos[0][1] = vec.y;
vertexPos[0][2] = vec.z;
}
{
const Vector3 &vec = vertices[*(indices + 1)];
vertexPos[1][0] = vec.x;
vertexPos[1][1] = vec.y;
vertexPos[1][2] = vec.z;
}
{
const Vector3 &vec = vertices[*(indices + 2)];
vertexPos[2][0] = vec.x;
vertexPos[2][1] = vec.y;
vertexPos[2][2] = vec.z;
}
indices += 3;
trimesh->addTriangle(vertexPos[0], vertexPos[1], vertexPos[2]);
}
const bool useQuantizedAABB = true;
btBvhTriangleMeshShape *shape = new btBvhTriangleMeshShape(trimesh, useQuantizedAABB);
return shape;
Code: Select all
if(body_)
{
body_->forceActivationState( DISABLE_SIMULATION );
level_.get_physics_world()->removeRigidBody( body_ );
}
delete body_;
delete state_;
delete shape_;
I hope you can help me and tell me what I forgot to do.
Thanks in advance!
Fred_FS