void createSceneLandscape() { PfxCreateLargeTriMeshParam param; param.verts = LargeMeshVtx; param.numVerts = LargeMeshVtxCount; param.vertexStrideBytes = sizeof(float)*6; param.triangles = LargeMeshIdx; param.numTriangles = LargeMeshIdxCount/3; param.triangleStrideBytes = sizeof(unsigned short)*3; if(gLargeMesh.m_numIslands > 0) { pfxReleaseLargeTriMesh(gLargeMesh); } PfxInt32 ret = pfxCreateLargeTriMesh(gLargeMesh,param); if(ret != SCE_PFX_OK) { SCE_PFX_PRINTF("Can't create large mesh.\n"); } int id = numRigidBodies++; PfxShape shape; shape.reset(); shape.setLargeTriMesh(&gLargeMesh); collidables[id].reset(); collidables[id].addShape(shape); collidables[id].finish(); bodies[id].reset(); states[id].reset(); states[id].setPosition(PfxVector3(0.0f,-5.0f,0.0f)); states[id].setOrientation(PfxQuat::rotationX(0.5f)*PfxQuat::rotationY(0.7f)); states[id].setMotionType(kPfxMotionTypeFixed); states[id].setRigidBodyId(id); }
static void convertShape(btCollisionShape* bulletShape, btAlignedObjectArray<sce::PhysicsEffects::PfxShape>& shapes) { switch (bulletShape->getShapeType()) { case BOX_SHAPE_PROXYTYPE: { btBoxShape* boxshape = (btBoxShape*)bulletShape; sce::PhysicsEffects::PfxBox box(boxshape->getHalfExtentsWithMargin().getX(),boxshape->getHalfExtentsWithMargin().getY(),boxshape->getHalfExtentsWithMargin().getZ()); sce::PhysicsEffects::PfxShape& shape = shapes.expand(); shape.reset(); shape.setBox(box); break; } case TRIANGLE_MESH_SHAPE_PROXYTYPE: { btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*) bulletShape; int numSubParts = trimesh->getMeshInterface()->getNumSubParts(); btAssert(numSubParts>0); for (int i=0;i<numSubParts;i++) { unsigned char* vertexBase=0; int numVerts = 0; PHY_ScalarType vertexType; int vertexStride=0; unsigned char* indexBase=0; int indexStride=0; int numFaces=0; PHY_ScalarType indexType; trimesh->getMeshInterface()->getLockedVertexIndexBase(&vertexBase,numVerts,vertexType,vertexStride,&indexBase,indexStride,numFaces,indexType,i); sce::PhysicsEffects::PfxCreateLargeTriMeshParam param; btAssert(param.flag&SCE_PFX_MESH_FLAG_16BIT_INDEX); unsigned short int* copyIndices = new unsigned short int[numFaces*3]; switch (indexType) { case PHY_UCHAR: { for (int p=0;p<numFaces;p++) { copyIndices[p*3]=indexBase[p*indexStride]; copyIndices[p*3+1]=indexBase[p*indexStride+1]; copyIndices[p*3+2]=indexBase[p*indexStride+2]; } break; } //PHY_INTEGER: //PHY_SHORT: default: { btAssert(0); } }; param.verts = (float*)vertexBase; param.numVerts = numVerts; param.vertexStrideBytes = vertexStride; param.triangles = copyIndices; param.numTriangles = numFaces; param.triangleStrideBytes = sizeof(unsigned short int)*3; sce::PhysicsEffects::PfxLargeTriMesh* largeMesh = new sce::PhysicsEffects::PfxLargeTriMesh(); sce::PhysicsEffects::PfxInt32 ret = pfxCreateLargeTriMesh(*largeMesh,param); if(ret != SCE_PFX_OK) { SCE_PFX_PRINTF("Can't create large mesh.\n"); } sce::PhysicsEffects::PfxShape& shape = shapes.expand(); shape.reset(); shape.setLargeTriMesh(largeMesh); } break; } case SPHERE_SHAPE_PROXYTYPE: { btSphereShape* sphereshape = (btSphereShape*)bulletShape; sce::PhysicsEffects::PfxSphere sphere(sphereshape->getRadius()); sce::PhysicsEffects::PfxShape& shape = shapes.expand(); shape.reset(); shape.setSphere(sphere); break; } case CAPSULE_SHAPE_PROXYTYPE: { btCapsuleShape* capsuleshape= (btCapsuleShape*)bulletShape;//assume btCapsuleShapeX for now sce::PhysicsEffects::PfxCapsule capsule(capsuleshape->getHalfHeight(),capsuleshape->getRadius()); sce::PhysicsEffects::PfxShape& shape = shapes.expand(); shape.reset(); shape.setCapsule(capsule); break; } case CYLINDER_SHAPE_PROXYTYPE: { btCylinderShape* cylindershape= (btCylinderShape*)bulletShape;//assume btCylinderShapeX for now sce::PhysicsEffects::PfxCylinder cylinder(cylindershape->getHalfExtentsWithMargin()[0],cylindershape->getRadius()); sce::PhysicsEffects::PfxShape& shape = shapes.expand(); shape.reset(); shape.setCylinder(cylinder); break; } case CONVEX_HULL_SHAPE_PROXYTYPE: { btConvexHullShape* convexHullShape = (btConvexHullShape*)bulletShape; sce::PhysicsEffects::PfxConvexMesh* convex = new sce::PhysicsEffects::PfxConvexMesh(); convex->m_numVerts = convexHullShape->getNumPoints(); convex->m_numIndices = 0;//todo for ray intersection test support for (int i=0;i<convex->m_numVerts;i++) { convex->m_verts[i].setX(convexHullShape->getPoints()[i].getX()); convex->m_verts[i].setY(convexHullShape->getPoints()[i].getY()); convex->m_verts[i].setZ(convexHullShape->getPoints()[i].getZ()); } convex->updateAABB(); sce::PhysicsEffects::PfxShape& shape = shapes.expand(); shape.reset(); shape.setConvexMesh(convex); break; } case COMPOUND_SHAPE_PROXYTYPE: { btCompoundShape* compound = (btCompoundShape*) bulletShape; for (int s=0;s<compound->getNumChildShapes();s++) { convertShape(compound->getChildShape(s),shapes); sce::PhysicsEffects::PfxMatrix3 rotMat = getVmMatrix3(compound->getChildTransform(s).getBasis()); sce::PhysicsEffects::PfxVector3 translate = getVmVector3(compound->getChildTransform(s).getOrigin()); sce::PhysicsEffects::PfxTransform3 childtransform(rotMat,translate); shapes[shapes.size()-1].setOffsetTransform(childtransform); } break; } default: { btAssert(0); } }; }