void AddRadialForceToPxRigidDynamic(PxRigidDynamic& PRigidDynamic, const FVector& Origin, float Radius, float Strength, uint8 Falloff) { #if WITH_PHYSX if (!(PRigidDynamic.getRigidDynamicFlags() & PxRigidDynamicFlag::eKINEMATIC)) { float Mass = PRigidDynamic.getMass(); PxTransform PCOMTransform = PRigidDynamic.getGlobalPose().transform(PRigidDynamic.getCMassLocalPose()); PxVec3 PCOMPos = PCOMTransform.p; // center of mass in world space PxVec3 POrigin = U2PVector(Origin); // origin of radial impulse, in world space PxVec3 PDelta = PCOMPos - POrigin; // vector from float Mag = PDelta.magnitude(); // Distance from COM to origin, in Unreal scale : @todo: do we still need conversion scale? // If COM is outside radius, do nothing. if (Mag > Radius) { return; } PDelta.normalize(); // If using linear falloff, scale with distance. float ForceMag = Strength; if (Falloff == RIF_Linear) { ForceMag *= (1.0f - (Mag / Radius)); } // Apply force PxVec3 PImpulse = PDelta * ForceMag; PRigidDynamic.addForce(PImpulse, PxForceMode::eFORCE); } #endif // WITH_PHYSX }
void AddRadialImpulseToPxRigidDynamic(PxRigidDynamic& PRigidDynamic, const FVector& Origin, float Radius, float Strength, uint8 Falloff, bool bVelChange) { #if WITH_PHYSX if (!(PRigidDynamic.getRigidDynamicFlags() & PxRigidDynamicFlag::eKINEMATIC)) { float Mass = PRigidDynamic.getMass(); PxTransform PCOMTransform = PRigidDynamic.getGlobalPose().transform(PRigidDynamic.getCMassLocalPose()); PxVec3 PCOMPos = PCOMTransform.p; // center of mass in world space PxVec3 POrigin = U2PVector(Origin); // origin of radial impulse, in world space PxVec3 PDelta = PCOMPos - POrigin; // vector from origin to COM float Mag = PDelta.magnitude(); // Distance from COM to origin, in Unreal scale : @todo: do we still need conversion scale? // If COM is outside radius, do nothing. if (Mag > Radius) { return; } PDelta.normalize(); // Scale by U2PScale here, because units are velocity * mass. float ImpulseMag = Strength; if (Falloff == RIF_Linear) { ImpulseMag *= (1.0f - (Mag / Radius)); } PxVec3 PImpulse = PDelta * ImpulseMag; PxForceMode::Enum Mode = bVelChange ? PxForceMode::eVELOCITY_CHANGE : PxForceMode::eIMPULSE; PRigidDynamic.addForce(PImpulse, Mode); } #endif // WITH_PHYSX }
static PxRigidDynamic* canDoCCD(PxShape* shape) { PxActor& actor = shape->getActor(); PxRigidDynamic* dyna = actor.is<PxRigidDynamic>(); if(!dyna) return NULL; // PT: no need to do it for statics const PxU32 nbShapes = dyna->getNbShapes(); if(nbShapes!=1) return NULL; // PT: only works with simple actors for now if(dyna->getRigidDynamicFlags() & PxRigidDynamicFlag::eKINEMATIC) return NULL; // PT: no need to do it for kinematics return dyna; }
PxRigidDynamic* CloneDynamic(PxPhysics& physicsSDK, const PxTransform& transform, const PxRigidDynamic& from, NxMirrorScene::MirrorFilter &mirrorFilter) { PxRigidDynamic* to = physicsSDK.createRigidDynamic(transform); if(!to) return NULL; if ( !copyStaticProperties(*to, from, mirrorFilter) ) { to->release(); to = NULL; return NULL; } to->setRigidDynamicFlags(from.getRigidDynamicFlags()); to->setMass(from.getMass()); to->setMassSpaceInertiaTensor(from.getMassSpaceInertiaTensor()); to->setCMassLocalPose(from.getCMassLocalPose()); if ( !(to->getRigidDynamicFlags() & PxRigidDynamicFlag::eKINEMATIC) ) { to->setLinearVelocity(from.getLinearVelocity()); to->setAngularVelocity(from.getAngularVelocity()); } to->setLinearDamping(from.getAngularDamping()); to->setAngularDamping(from.getAngularDamping()); to->setMaxAngularVelocity(from.getMaxAngularVelocity()); PxU32 posIters, velIters; from.getSolverIterationCounts(posIters, velIters); to->setSolverIterationCounts(posIters, velIters); to->setSleepThreshold(from.getSleepThreshold()); to->setContactReportThreshold(from.getContactReportThreshold()); return to; }
void defaultCCTInteraction(const PxControllerShapeHit& hit) { PxRigidDynamic* actor = hit.shape->getActor().is<PxRigidDynamic>(); if(actor) { if(actor->getRigidDynamicFlags() & PxRigidDynamicFlag::eKINEMATIC) return; // We only allow horizontal pushes. Vertical pushes when we stand on dynamic objects creates // useless stress on the solver. It would be possible to enable/disable vertical pushes on // particular objects, if the gameplay requires it. const PxVec3 upVector = hit.controller->getUpDirection(); const PxF32 dp = hit.dir.dot(upVector); // printf("%f\n", fabsf(dp)); if(fabsf(dp)<1e-3f) // if(hit.dir.y==0.0f) { const PxTransform globalPose = actor->getGlobalPose(); const PxVec3 localPos = globalPose.transformInv(toVec3(hit.worldPos)); ::addForceAtLocalPos(*actor, hit.dir*hit.length*1000.0f, localPos, PxForceMode::eACCELERATION); } } }