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); }
void createSceneBoxGround() { int id = numRigidBodies++; PfxBox box(150.0f,2.5f,150.0f); PfxShape shape; shape.reset(); shape.setBox(box); collidables[id].reset(); collidables[id].addShape(shape); collidables[id].finish(); bodies[id].reset(); states[id].reset(); states[id].setPosition(PfxVector3(0.0f,-2.5f,0.0f)); states[id].setMotionType(kPfxMotionTypeFixed); states[id].setRigidBodyId(id); }
void createBrick(int id,const PfxVector3 &pos,const PfxQuat &rot,const PfxVector3 &boxSize,PfxFloat mass) { PfxBox box(boxSize); PfxShape shape; shape.reset(); shape.setBox(box); collidables[id].reset(); collidables[id].addShape(shape); collidables[id].finish(); bodies[id].reset(); bodies[id].setRestitution(0.0f); bodies[id].setMass(mass); bodies[id].setInertia(pfxCalcInertiaBox(boxSize,mass)); states[id].reset(); states[id].setPosition(pos); states[id].setOrientation(rot); states[id].setMotionType(kPfxMotionTypeActive); states[id].setRigidBodyId(id); }
void createScenePrimitives() { // sphere { int id = numRigidBodies++; PfxSphere sphere(1.0f); PfxShape shape; shape.reset(); shape.setSphere(sphere); collidables[id].reset(); collidables[id].addShape(shape); collidables[id].finish(); bodies[id].reset(); bodies[id].setMass(1.0f); bodies[id].setInertia(pfxCalcInertiaSphere(1.0f,1.0f)); states[id].reset(); states[id].setPosition(PfxVector3(-5.0f,5.0f,0.0f)); states[id].setMotionType(kPfxMotionTypeActive); states[id].setRigidBodyId(id); } // box { int id = numRigidBodies++; PfxBox box(1.0f,1.0f,1.0f); PfxShape shape; shape.reset(); shape.setBox(box); collidables[id].reset(); collidables[id].addShape(shape); collidables[id].finish(); bodies[id].reset(); bodies[id].setMass(1.0f); bodies[id].setInertia(pfxCalcInertiaBox(PfxVector3(1.0f),1.0f)); states[id].reset(); states[id].setPosition(PfxVector3(0.0f,5.0f,5.0f)); states[id].setMotionType(kPfxMotionTypeActive); states[id].setRigidBodyId(id); } // capsule { int id = numRigidBodies++; PfxCapsule capsule(1.5f,0.5f); PfxShape shape; shape.reset(); shape.setCapsule(capsule); collidables[id].reset(); collidables[id].addShape(shape); collidables[id].finish(); bodies[id].reset(); bodies[id].setMass(2.0f); bodies[id].setInertia(pfxCalcInertiaCylinderX(2.0f,0.5f,2.0f)); states[id].reset(); states[id].setPosition(PfxVector3(5.0f,5.0f,0.0f)); states[id].setMotionType(kPfxMotionTypeActive); states[id].setRigidBodyId(id); } // cylinder { int id = numRigidBodies++; PfxCylinder cylinder(0.5f,1.5f); PfxShape shape; shape.reset(); shape.setCylinder(cylinder); collidables[id].reset(); collidables[id].addShape(shape); collidables[id].finish(); bodies[id].reset(); bodies[id].setMass(3.0f); bodies[id].setInertia(pfxCalcInertiaCylinderX(0.5f,1.5f,3.0f)); states[id].reset(); states[id].setPosition(PfxVector3(0.0f,10.0f,0.0f)); states[id].setMotionType(kPfxMotionTypeActive); states[id].setRigidBodyId(id); } // convex mesh { PfxCreateConvexMeshParam param; param.verts = BarrelVtx; param.numVerts = BarrelVtxCount; param.vertexStrideBytes = sizeof(float)*6; param.triangles = BarrelIdx; param.numTriangles = BarrelIdxCount/3; param.triangleStrideBytes = sizeof(unsigned short)*3; PfxInt32 ret = pfxCreateConvexMesh(gConvex,param); if(ret != SCE_PFX_OK) { SCE_PFX_PRINTF("Can't create gConvex mesh.\n"); } int id = numRigidBodies++; PfxShape shape; shape.reset(); shape.setConvexMesh(&gConvex); collidables[id].reset(); collidables[id].addShape(shape); collidables[id].finish(); bodies[id].reset(); bodies[id].setMass(3.0f); bodies[id].setInertia(pfxCalcInertiaSphere(1.0f,1.0f)); states[id].reset(); states[id].setPosition(PfxVector3(0.0f,15.0f,0.0f)); states[id].setMotionType(kPfxMotionTypeActive); states[id].setRigidBodyId(id); } // combined primitives { int id = numRigidBodies++; //E Both shapes and incides buffer have to be kept when creating a combined shape. static PfxShape shapes[3]; PfxUInt16 shapeIds[3]={0,1,2}; collidables[id].reset(shapes,shapeIds,3); { PfxBox box(0.5f,0.5f,1.5f); PfxShape shape; shape.reset(); shape.setBox(box); shape.setOffsetPosition(PfxVector3(-2.0f,0.0f,0.0f)); collidables[id].addShape(shape); } { PfxBox box(0.5f,1.5f,0.5f); PfxShape shape; shape.reset(); shape.setBox(box); shape.setOffsetPosition(PfxVector3(2.0f,0.0f,0.0f)); collidables[id].addShape(shape); } { PfxCapsule cap(1.5f,0.5f); PfxShape shape; shape.reset(); shape.setCapsule(cap); collidables[id].addShape(shape); } collidables[id].finish(); bodies[id].reset(); bodies[id].setMass(3.0f); bodies[id].setInertia(pfxCalcInertiaBox(PfxVector3(2.5f,1.0f,1.0f),3.0f)); states[id].reset(); states[id].setPosition(PfxVector3(0.0f,5.0f,0.0f)); states[id].setMotionType(kPfxMotionTypeActive); states[id].setRigidBodyId(id); } }