void SetupAttachmentScene() { sprintf(gTitleString, "Attachment Demo"); // Create objects in scene groundPlane = CreateGroundPlane(); NxActor* box1 = CreateBox(NxVec3(-7,12.25,0), NxVec3(2.5,1,1), 0); NxActor* box2 = CreateBox(NxVec3(0,12.25,0), NxVec3(2.5,1,1), 0); NxActor* box3 = CreateBox(NxVec3(7,12.25,0), NxVec3(2.5,1,1), 0); NxActor* attachedBox = CreateBox(NxVec3(-7.2,4.5,1.6), NxVec3(1.25,1,1), 1); NxActor* attachedSphere = CreateSphere(NxVec3(-0.25,4.0,2.0), 1.3, 1); NxActor* attachedCapsule = CreateCapsule(NxVec3(9.0,5.5,2.0),2.0, 1, 1); NxReal damping = 0.3; attachedBox->setAngularDamping(damping); attachedBox->setLinearDamping(damping); attachedSphere->setAngularDamping(damping); attachedSphere->setLinearDamping(damping); attachedCapsule->setAngularDamping(damping); attachedCapsule->setLinearDamping(damping); NxQuat q; q.fromAngleAxis(90,NxVec3(0,0,1)); attachedCapsule->setGlobalOrientationQuat(q); // Cloth NxClothDesc clothDesc; clothDesc.globalPose.M.rotX(1.3); clothDesc.thickness = 0.3; clothDesc.attachmentResponseCoefficient = 1; clothDesc.flags |= NX_CLF_BENDING; clothDesc.flags |= NX_CLF_BENDING_ORTHO; clothDesc.flags |= NX_CLF_DAMPING | NX_CLF_VISUALIZATION; if (gHardwareCloth) clothDesc.flags |= NX_CLF_HARDWARE; // Cloth attaching to sphere clothDesc.globalPose.t = NxVec3(0.75,5,2); MyCloth* regularCloth1 = new MyCloth(gScene, clothDesc, 2, 8, 0.4); regularCloth1->getNxCloth()->attachToCollidingShapes(NX_CLOTH_ATTACHMENT_TWOWAY); gCloths.push_back(regularCloth1); // Cloth attaching to box clothDesc.globalPose.t = NxVec3(-6.2,5,2); MyCloth* regularCloth2 = new MyCloth(gScene, clothDesc, 2, 8, 0.4); regularCloth2->getNxCloth()->attachToCollidingShapes(NX_CLOTH_ATTACHMENT_TWOWAY); gCloths.push_back(regularCloth2); // Cloth attaching to capsule clothDesc.globalPose.t = NxVec3(8.0,5,2); clothDesc.attachmentTearFactor = 2.0; MyCloth* regularCloth3 = new MyCloth(gScene, clothDesc, 2, 8, 0.4); regularCloth3->getNxCloth()->attachToShape(box3->getShapes()[0], NX_CLOTH_ATTACHMENT_TEARABLE); regularCloth3->getNxCloth()->attachToShape(attachedCapsule->getShapes()[0], NX_CLOTH_ATTACHMENT_TWOWAY); gCloths.push_back(regularCloth3); }
//----------------------------------------------------------------------- PhysicsActor* PhysXActorExtern::createPhysicsActor(PhysicsActorDesc* physicsActorDesc, PhysicsShapeDesc* physicsShapeDesc) { if (!PhysXBridge::getSingletonPtr()->getScene() || !physicsActorDesc || !physicsShapeDesc) return 0; NxBodyDesc bodyDesc; bodyDesc.setToDefault(); NxReal angularDamping = bodyDesc.angularDamping; NxVec3 angularVelocity = bodyDesc.angularVelocity; NxVec3 linearVelocity = bodyDesc.linearVelocity; bodyDesc.angularDamping = physicsShapeDesc->mAngularDamping; bodyDesc.angularVelocity = PhysXMath::convert(physicsShapeDesc->mAngularVelocity); bodyDesc.linearVelocity = PhysXMath::convert(physicsActorDesc->direction); NxActorDesc actorDesc; NxActorDesc defaultActorDesc; actorDesc.setToDefault(); defaultActorDesc.setToDefault(); switch (physicsShapeDesc->mPhysicsShapeType) { case ST_BOX: { PhysicsBoxDesc* physicsBoxDesc = static_cast<PhysicsBoxDesc*>(physicsShapeDesc); NxBoxShapeDesc boxDesc; boxDesc.setToDefault(); boxDesc.dimensions = PhysXMath::convert(physicsBoxDesc->mDimensions); boxDesc.group = physicsBoxDesc->mCollisionGroup; boxDesc.groupsMask = PhysXMath::convert(physicsBoxDesc->mGroupMask); boxDesc.materialIndex = physicsBoxDesc->mMaterialIndex; actorDesc.density = NxComputeBoxDensity(2 * boxDesc.dimensions, physicsActorDesc->mass); actorDesc.shapes.pushBack(&boxDesc); } break; case ST_SPHERE: { PhysicsSphereDesc* physicsSphereDesc = static_cast<PhysicsSphereDesc*>(physicsShapeDesc); NxSphereShapeDesc sphereDec; sphereDec.setToDefault(); sphereDec.radius = physicsSphereDesc->mRadius; sphereDec.group = physicsSphereDesc->mCollisionGroup; sphereDec.groupsMask = PhysXMath::convert(physicsSphereDesc->mGroupMask); sphereDec.materialIndex = physicsSphereDesc->mMaterialIndex; actorDesc.density = NxComputeSphereDensity(sphereDec.radius, physicsActorDesc->mass); actorDesc.shapes.pushBack(&sphereDec); } break; case ST_CAPSULE: { PhysicsCapsuleDesc* physicsCapsuleDesc = static_cast<PhysicsCapsuleDesc*>(physicsShapeDesc); NxCapsuleShapeDesc capsuleDec; capsuleDec.setToDefault(); capsuleDec.radius = physicsCapsuleDesc->mRadius; capsuleDec.height = physicsCapsuleDesc->mHeight; capsuleDec.group = physicsCapsuleDesc->mCollisionGroup; capsuleDec.groupsMask = PhysXMath::convert(physicsCapsuleDesc->mGroupMask); capsuleDec.materialIndex = physicsCapsuleDesc->mMaterialIndex; actorDesc.density = NxComputeCylinderDensity(capsuleDec.radius, capsuleDec.height, physicsActorDesc->mass); actorDesc.shapes.pushBack(&capsuleDec); } break; } actorDesc.globalPose.t = PhysXMath::convert(physicsActorDesc->position); actorDesc.body = &bodyDesc; actorDesc.group = physicsActorDesc->collisionGroup; PhysXActor* physXActor = 0; if (!actorDesc.isValid()) { actorDesc = defaultActorDesc; Ogre::LogManager::getSingleton().logMessage("ParticleUniverse PhysXActor: Cannot create actor; use default attributes."); } NxActor* nxActor = PhysXBridge::getSingletonPtr()->getScene()->createActor(actorDesc); if (nxActor) { physXActor = OGRE_NEW_T(PhysXActor, Ogre::MEMCATEGORY_SCENE_OBJECTS)(); physXActor->position = PhysXMath::convert(nxActor->getGlobalPosition()); physXActor->direction = PhysXMath::convert(nxActor->getLinearVelocity()); nxActor->setGlobalOrientationQuat(PhysXMath::convert(physicsActorDesc->orientation)); physXActor->orientation = physicsActorDesc->orientation; physXActor->mass = nxActor->getMass(); physXActor->collisionGroup = nxActor->getGroup(); physXActor->nxActor = nxActor; } return physXActor; }