I'm trying to import a grayscale terrain but my meshs didn't collide with the terrain.
This is my Terrain Code
Code: Select all
if(this->$Enabled)
{
// Get the collision mesh
this->$CollisionMesh = new btTriangleMesh();
Engine::PhysicEngine::Instance()->ConvertCollisionMeshBuffer((IMeshBuffer *)(&$MeshBuffer), this->$CollisionMesh, this->$Scale);
this->$Shape = new btBvhTriangleMeshShape(this->$CollisionMesh, true);
// Orientation
btTransform Transform;
btVector3 $Bullet_Position = btVector3(this->$TPosition.X, this->$TPosition.Y, this->$TPosition.Z);
this->$MotionState = Engine::PhysicEngine::Instance()->GetBulletTransform(Transform, $Bullet_Position);
// Body
this->$RigidBody = new btRigidBody(this->$Mass, this->$MotionState, this->$Shape);
this->$RigidBody->setUserPointer((void *)(this->$Node));
Engine::PhysicEngine::Instance()->Get_World()->addRigidBody(this->$RigidBody);
}
Code: Select all
// ira calcular fisica se Massa for diferente de 0
bool isDynamic = (this->$Mass != 0.0f);
// Get the collision mesh
btTriangleMesh* $CollisionMesh = new btTriangleMesh();
Engine::PhysicEngine::Instance()->ConvertCollisionMesh(this->$Mesh->getMesh(0),
$CollisionMesh,
this->$Scale);
this->$Shape = new btBvhTriangleMeshShape($CollisionMesh, true);
btVector3 LocalInertia(0,0,0);
if(isDynamic)
{
this->$Shape->calculateLocalInertia(this->$Mass, LocalInertia);
}
// calculate value for ccdThreshold
core::aabbox3d<f32> box = this->$Node->getBoundingBox();
core::vector3df ext = box.getExtent();
f32 ret=0;
if (ext.X>ret)
{
ret=ext.X;
}
if (ext.Y>ret)
{
ret=ext.Y;
}
if (ext.Z>ret)
{
ret=ext.Z;
}
this->$Threshold = ret/2;
// Orientation
btTransform $Transform;
this->$MotionState = Engine::PhysicEngine::Instance()->GetBulletTransform($Transform, this->$TPosition);
// Body
this->$RigidBody = new btRigidBody(this->$Mass,
this->$MotionState,
this->$Shape,
LocalInertia);
this->$RigidBody->setUserPointer((void *)(this->$Node));
Engine::PhysicEngine::Instance()->Get_World()->addRigidBody(this->$RigidBody);
$Objects.push_back(this->$RigidBody);
this->$RigidBody->setCcdSquareMotionThreshold(this->$Threshold);
//Experimental: better estimation of CCD Time of Impact:
this->$RigidBody->setCcdSweptSphereRadius(0.2*this->$Threshold);
Code: Select all
this->$Shape = new btBvhTriangleMeshShape(this->$CollisionMesh, true);
Code: Select all
this->$Shape = new btConvexTriangleMeshShape(this->$CollisionMesh);
Some one can help me...