Hiya,
so I tried substituting the btTriangleIndexVertexArray for the btTriangleMesh and still the same result. Once again my other models work fine but the tracks collision is still going wrong.
I used this thread as a guide
http://www.bulletphysics.org/Bullet/php ... f=9&t=2961
This is the code I now have to build the static collision model btBvhTriangleMeshShape:
Code: Select all
bool StaticEntity::Create( D3DXVECTOR3 position, float mass, LPD3DXMESH mesh )
{
TriMeshData *data = new TriMeshData;
DWORD numVertices = mesh->GetNumVertices();
DWORD numFaces = mesh->GetNumFaces();
Vertex *v = 0;
mesh->LockVertexBuffer(0, (void**)&v);
// Extract vertices
data->vertices = new btScalar[numVertices * 3];
for(DWORD i = 0; i < numVertices; i++)
{
data->vertices[i*3+0] = v[i].position.x;
data->vertices[i*3+1] = v[i].position.y;
data->vertices[i*3+2] = v[i].position.z;
}
mesh->UnlockVertexBuffer();
// Extract indices
data->indices = new int[numFaces * 3];
WORD* ind = 0;
mesh->LockIndexBuffer(0,(void**)&ind);
//memcpy( &indices, &ind, sizeof(ind));
for(DWORD i = 0; i < numFaces; i++)
{
data->indices[i*3+0] = ind[i*3+0];
data->indices[i*3+1] = ind[i*3+1];
data->indices[i*3+2] = ind[i*3+2];
}
mesh->UnlockIndexBuffer();
int indexStride = 3 * sizeof(int);
int vertStride = sizeof(btVector3);
data->indexVertexArrays = new btTriangleIndexVertexArray(numFaces, data->indices, indexStride,
numVertices, (btScalar*) &data->vertices[0], sizeof(btScalar) * 3);
//----------------------NEW CODE HERE------------------
btTriangleMesh* trimesh = new btTriangleMesh();
for( DWORD i = 0; i < numFaces; i++ )
{
int index0 = data->indices[i*3];
int index1 = data->indices[i*3+1];
int index2 = data->indices[i*3+2];
btVector3 vertex0(data->vertices[index0*3], data->vertices[index0*3+1],data->vertices[index0*3+2]);
btVector3 vertex1(data->vertices[index1*3], data->vertices[index1*3+1],data->vertices[index1*3+2]);
btVector3 vertex2(data->vertices[index2*3], data->vertices[index2*3+1],data->vertices[index2*3+2]);
trimesh->addTriangle(vertex0,vertex1,vertex2);
}
m_collisionShape = new btBvhTriangleMeshShape(trimesh, true);
//--------------------------------------------------------------
btTransform trans;
trans.setIdentity();
trans.setOrigin(ConvertVector(position));
btVector3 inertia(0,0,0);
btDefaultMotionState* motionState = new btDefaultMotionState( trans );
btRigidBody::btRigidBodyConstructionInfo cInfo(mass,motionState,m_collisionShape,inertia);
m_rigidBody = new btRigidBody(cInfo);
return true;
}
So does this mean that the track mesh is faulty? Then again it worked with irrKit?!
I appreciate the help and any more ideas would be great.