void World::SetupAnimalScene() { // Create the objects in the scene NxSoftBodyDesc softBodyDesc; softBodyDesc.globalPose.t = NxVec3(0.0f, 3.0f, 0.0f); softBodyDesc.particleRadius = 0.2f; softBodyDesc.volumeStiffness = 0.5f; softBodyDesc.stretchingStiffness= 1.0f; softBodyDesc.friction = 1.0f; softBodyDesc.attachmentResponseCoefficient = 0.1f; softBodyDesc.solverIterations = 5; char *fileName = "froggyNormalized"; char tetFileName[256], objFileName[256], s[256]; sprintf(tetFileName, "%s.tet", fileName); sprintf(objFileName, "%s.obj", fileName); ObjMesh *objMesh = new ObjMesh(); objMesh->loadFromObjFile(FindMediaFile(objFileName, s)); gObjMeshes.pushBack(objMesh); if(objMesh == NULL) { printf("objMesh %s\n"); } NxMat33 rot; rot.rotX(NxHalfPiF32); for (int i = 0; i < 5; i++) { softBodyDesc.globalPose.t = NxVec3(0, 3+i*3, 0); MySoftBody *softBody = new MySoftBody(gScene, softBodyDesc, FindMediaFile(tetFileName, s), objMesh); assert(softBody); if (!softBody->getNxSoftBody()) { printf("Error: unable to create the softbody for the current scene.\n"); delete softBody; } else { gSoftBodies.pushBack(softBody); NxActor *caps = MyCreateCapsule(NxVec3(0.0f, 3.0f + i*3.0f, -0.3f), 1.0f, 0.73f, 1.0f); caps->userData = (void*)&gInvisible; caps->setGlobalOrientation(rot); softBody->getNxSoftBody()->attachToShape(caps->getShapes()[0], NX_SOFTBODY_ATTACHMENT_TWOWAY); } } }
NxActor* CreateCar(const NxVec3& pos) { // Create body NxBodyDesc bodyDesc; NxBoxShapeDesc boxDesc; NxCapsuleShapeDesc capsuleDesc[4]; NxActorDesc actorDesc; bodyDesc.mass = carMass; const NxReal height = 0.3; const NxReal width = 2; const NxReal length = 4; //boxDesc.dimensions.set(length*0.65, height*0.85, width*0.65); //actorDesc.shapes.pushBack(&boxDesc); { sObject* pObject = dbGetObject ( 5 ); float fXPos = pObject->position.vecPosition.x; float fYPos = pObject->position.vecPosition.y; float fZPos = pObject->position.vecPosition.z; float fXSize = ( pObject->collision.vecMax.x - pObject->collision.vecMin.x ) * pObject->position.vecScale.x; float fYSize = ( pObject->collision.vecMax.y - pObject->collision.vecMin.y ) * pObject->position.vecScale.y; float fZSize = ( pObject->collision.vecMax.z - pObject->collision.vecMin.z ) * pObject->position.vecScale.z; boxDesc.dimensions.set ( fXSize / 2, fYSize / 2, fZSize / 2 ); boxDesc.localPose.t = NxVec3 ( pObject->collision.vecCentre.x, pObject->collision.vecCentre.y, pObject->collision.vecCentre.z ); //boxDesc.localPose. actorDesc.shapes.pushBack ( &boxDesc ); } capsuleDesc[0].radius = 0.1; capsuleDesc[0].height = 1; capsuleDesc[0].flags = NX_SWEPT_SHAPE; capsuleDesc[0].localPose.M.setColumn(1, NxVec3(0,-1, 0)); capsuleDesc[0].localPose.M.setColumn(2, NxVec3(0, 0,-1)); //rotate 180 degrees around x axis to cast downward! capsuleDesc[0].localPose.t.set(length*0.5, -height, width*0.5); capsuleDesc[0].materialIndex = raycastWheelMaterialIndex; capsuleDesc[0].userData = &(wheelUserDatas[0]); actorDesc.shapes.pushBack(&capsuleDesc[0]); wheelUserDatas[0].frontWheel = true; capsuleDesc[1].radius = capsuleDesc[0].radius; capsuleDesc[1].height = capsuleDesc[0].height; capsuleDesc[1].flags = capsuleDesc[0].flags; capsuleDesc[1].localPose.M = capsuleDesc[0].localPose.M; capsuleDesc[1].localPose.t.set(length*0.5, -height, -width*0.5); capsuleDesc[1].materialIndex = raycastWheelMaterialIndex; capsuleDesc[1].userData = &(wheelUserDatas[1]); actorDesc.shapes.pushBack(&capsuleDesc[1]); wheelUserDatas[1].frontWheel = true; capsuleDesc[2].radius = capsuleDesc[0].radius; capsuleDesc[2].height = capsuleDesc[0].height; capsuleDesc[2].flags = capsuleDesc[0].flags; capsuleDesc[2].localPose.M = capsuleDesc[0].localPose.M; capsuleDesc[2].localPose.t.set(-length*0.5, -height, -width*0.5); capsuleDesc[2].materialIndex = raycastWheelMaterialIndex; capsuleDesc[2].userData = &(wheelUserDatas[2]); actorDesc.shapes.pushBack(&capsuleDesc[2]); wheelUserDatas[2].frontWheel = false; capsuleDesc[3].radius = capsuleDesc[0].radius; capsuleDesc[3].height = capsuleDesc[0].height; capsuleDesc[3].flags = capsuleDesc[0].flags; capsuleDesc[3].localPose.M = capsuleDesc[0].localPose.M; capsuleDesc[3].localPose.t.set(-length*0.5, -height, width*0.5); capsuleDesc[3].materialIndex = raycastWheelMaterialIndex; capsuleDesc[3].userData = &(wheelUserDatas[3]); actorDesc.shapes.pushBack(&capsuleDesc[3]); wheelUserDatas[3].frontWheel = false; actorDesc.body = &bodyDesc; actorDesc.globalPose.t = pos; NxActor* a = gScene->createActor(actorDesc); //a->userData = &carData; //so we can recoginze it in the contact stream sPhysObject* pPhys = new sPhysObject; pPhys->iID = 5; a->userData = (void*)pPhys; //actorDesc.globalPose.t = NxVec3 ( fXPos, fYPos, fZPos ); NxMat33 mat; mat.rotY ( D3DXToRadian ( 90 ) ); a->setGlobalOrientation ( mat ); a->wakeUp(1e10); //don't go to sleep. return a; }