I’m engaged on my first 3D sport, for iphone, and I’m utilizing Blender to create fashions, Cocos3D sport engine and Bullet for physics simulation. I’m making an attempt to study using physics engine.
What I’ve executed
I’ve created a small mannequin in blender which accommodates a Dice (default blender dice) on the origin and a Uvsphere hovering precisely on high of this dice (with out touching the dice)
I saved the file to get MyModel.mix. Then I used
File -> Export -> PVRGeoPOD (.pod/.h/.cpp)
in Blender to export the mannequin to .pod format to make use of together with Cocos3D.
Within the coding facet, I added crucial bullet recordsdata to my Cocos3D template challenge in XCode.
I’m additionally utilizing a bullet goal C wrapper.
-(void) initializeScene {
_physicsWorld = ((CC3PhysicsWorld alloc) init);
(_physicsWorld setGravity:0 y:-9.8 z:0);
/*Setup digicam, lamp and many others.*/
..........
...........
/*Add fashions created in blender to scene*/
(self addContentFromPODFile: @"MyModel.pod");
/*Create OpenGL ES buffers*/
(self createGLBuffers);
/*get fashions*/
CC3MeshNode* cubeNode = (CC3MeshNode*)(self getNodeNamed:@"Dice");
CC3MeshNode* sphereNode = (CC3MeshNode*)(self getNodeNamed:@"Sphere");
/*These boring gray colours..*/
(cubeNode setColor:ccc3(255, 255, 0));
(sphereNode setColor:ccc3(255, 0, 0));
float *cVertexData = (float*)((CC3VertexArrayMesh*)cubeNode.mesh).vertexLocations.vertices;
int cVertexCount = (CC3VertexArrayMesh*)cubeNode.mesh).vertexLocations.vertexCount;
btTriangleMesh* cTriangleMesh = new btTriangleMesh();
// for (int i = 0; i < cVertexCount * 3; i+=3) {
// printf("npercentf", cVertexData(i));
// printf("npercentf", cVertexData(i+1));
// printf("npercentf", cVertexData(i+2));
// }
/*Making an attempt to create a triangle mesh that curresponds the dice in 3D area.*/
int offset = 0;
for (int i = 0; i < (cVertexCount / 3); i++){
unsigned int index1 = offset;
unsigned int index2 = offset+6;
unsigned int index3 = offset+12;
cTriangleMesh->addTriangle(
btVector3(cVertexData(index1), cVertexData(index1+1), cVertexData(index1+2) ),
btVector3(cVertexData(index2), cVertexData(index2+1), cVertexData(index2+2) ),
btVector3(cVertexData(index3), cVertexData(index3+1), cVertexData(index3+2)
));
offset += 18;
}
(self releaseRedundantData);
/*Create a collision form from triangle mesh*/
btBvhTriangleMeshShape* cTriMeshShape = new btBvhTriangleMeshShape(cTriangleMesh,true);
btCollisionShape *sphereShape = new btSphereShape(1);
/*Create physics objects*/
gTriMeshObject = (_physicsWorld createPhysicsObjectTrimesh:cubeNode form:cTriMeshShape mass:0 restitution:1.0 place:cubeNode.location);
sphereObject = (_physicsWorld createPhysicsObject:sphereNode form:sphereShape mass:1 restitution:0.1 place:sphereNode.location);
sphereObject.rigidBody->setDamping(0.1,0.8);
}
After I run the sphere and dice exhibits up superb. I anticipate the sphere object to fall instantly on high of the dice, since I’ve given it a mass of 1 and the physics world gravity is given as -9.8 in y course. However What is occurring the spere rotates round dice three or instances after which simply jumps out of the scene. Then I do know I’ve some fundamental misunderstanding about the entire course of.
So my query is, how can I create a physics collision form which corresponds to the form of a selected mesh mannequin. I might have advanced shapes than dice and sphere, however earlier than going into them I wish to perceive the ideas.