I'm currently trying to get my head round Bullet and implement it using cocos3d on IOS.
So far I have the basics up and running, but I am trying to use btConvexHullShape, as I believe it would
be quite suitable to use for a floor.
I have managed to build one by coping the vertexes of one of my meshes, but, it seems to be two, big?
It's quite hard to tell if it has been constructed correctly but as I can find any in-depth information on it I believe my understanding of how it may work is correct. That you feed all the vertexes in that it creates a height map based on them. Is this correct or does the order in which you enter the vertexes matter?
I noted that in the ConvexDecompositionDemo it states that there may be an issue with the collision margin, so I have tried to take this into account.
At current my mix and match objective c / c++ code takes the following form...
Code: Select all
CC3PODMesh* va=(CC3PODMesh *)groundNode.mesh;
btAlignedObjectArray<btVector3> vertices;
for(GLsizei i=0; i<va.vertexCount; i++)
{
CC3Vector pos1 = (CC3Vector)([va vertexLocationAt:i]);
btVector3 vertex(pos1.x,pos1.y,pos1.z);
vertices.push_back(vertex);
//colShapeTemp->addPoint(btVector3(pos1.x, pos1.y, pos1.z));
}
btAlignedObjectArray<btVector3> planeEquations;
btGeometryUtil::getPlaneEquationsFromVertices(vertices,planeEquations);
float collisionMargin = 0.1f;
btAlignedObjectArray<btVector3> shiftedPlaneEquations;
for (int p=0;p<planeEquations.size();p++)
{
btVector3 plane = planeEquations[p];
plane[3] += collisionMargin;
shiftedPlaneEquations.push_back(plane);
}
btAlignedObjectArray<btVector3> shiftedVertices;
btGeometryUtil::getVerticesFromPlaneEquations(shiftedPlaneEquations,shiftedVertices);
btConvexHullShape* convexShape = new btConvexHullShape(&(shiftedVertices[0].getX()),shiftedVertices.size());
btCollisionShape* boxShape = convexShape;
convexShape->setMargin(0.01f);
Thanks in advance.
Duncan.