Want Bullet physics collision complex shapes samples.

Post Reply
srkrambo
Posts: 1
Joined: Mon Aug 13, 2012 8:06 am

Want Bullet physics collision complex shapes samples.

Post by srkrambo »

I would like to use complex physics shape in bullet physics integrated to Cocos 3d -(iphone objective C).
I was not able to find enough samples. Actually I want to bring a complex shape such torus 3d model.

I was able to bring a simple cube with the following code

Code: Select all

[self addContentFromPODResourceFile: @"shapeCube.pod"]; // cocos 3d way of importing 3d file
  CC3MeshNode* triMeshNode1 = (CC3MeshNode*)[self getNodeNamed:@"BigCube"];
    float* vertexData1 = (float*)((CC3VertexArrayMeshModel*)triMeshNode1.mesh).vertexLocations.elements;
    int vertexCount1 = ((CC3VertexArrayMeshModel*)triMeshNode1.mesh).vertexLocations.elementCount;   
    btTriangleMesh* triMesh1 = new btTriangleMesh();    
    int offset = 0;
    for (int i = 0; i < (vertexCount1 / 3); i++)
	{
        unsigned int index1 = offset;
		unsigned int index2 = offset+6;
		unsigned int index3 = offset+12;
		triMesh1->addTriangle(btVector3(vertexData1[index1], vertexData1[index1+1], vertexData1[index1+2] ),
                              btVector3(vertexData1[index2], vertexData1[index2+1], vertexData1[index2+2] ),
                              btVector3(vertexData1[index3], vertexData1[index3+1], vertexData1[index3+2] ));
        offset += 18;      
	}
    triMeshNode1.location = cc3v(-2, 2, 0);    
    btBvhTriangleMeshShape* triMeshShape1 = new btBvhTriangleMeshShape(triMesh1,true); 
    CC3PhysicsObject3D *torusobject1 = [_physicsWorld createPhysicsObject:triMeshNode1 shape:triMeshShape1 mass:0 restitution:1.0 position:triMeshNode1.location];
When I import a simple cube it works good but fails for other shapes, Even when I scale the cube model,I'm not able get the correct physics shape. So please tell about whether how to scale a physics object also. If any one have used complex shape please help by posting a sample code.
Post Reply