本文整理汇总了C++中PxRigidDynamic::addForce方法的典型用法代码示例。如果您正苦于以下问题:C++ PxRigidDynamic::addForce方法的具体用法?C++ PxRigidDynamic::addForce怎么用?C++ PxRigidDynamic::addForce使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PxRigidDynamic
的用法示例。
在下文中一共展示了PxRigidDynamic::addForce方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddRadialForceToPxRigidDynamic
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
}
示例2: pickup
/**
@brief
@date 2013-12-03
*/
void CEvc::pickup()
{
PxU32 width;
PxU32 height;
mApplication.getPlatform()->getWindowSize(width, height);
mPicking->moveCursor(width/2,height/2);
mPicking->lazyPick();
PxActor *actor = mPicking->letGo();
//PxRigidDynamic *rigidActor = static_cast<PxRigidDynamic*>(actor->is<PxRigidDynamic>());
PxRigidDynamic *rigidActor = (PxRigidDynamic*)actor;
if (rigidActor)
{
const PxVec3 pos = getCamera().getPos() + (getCamera().getViewDir()*10.f);
const PxVec3 vel = getCamera().getViewDir() * 20.f;
rigidActor->addForce( getCamera().getViewDir()*g_pDbgConfig->force );
PxU32 nbShapes = rigidActor->getNbShapes();
if(!nbShapes)
return;
PxShape** shapes = (PxShape**)SAMPLE_ALLOC(sizeof(PxShape*)*nbShapes);
PxU32 nb = rigidActor->getShapes(shapes, nbShapes);
PX_ASSERT(nb==nbShapes);
for(PxU32 i=0;i<nbShapes;i++)
{
RenderBaseActor *renderActor = getRenderActor(rigidActor, shapes[i]);
if (renderActor)
{
renderActor->setRenderMaterial(mManagedMaterials[ 1]);
}
}
SAMPLE_FREE(shapes);
}
}
示例3: mat
void
PhysXRigidManager::update(const physx::PxActiveTransform * activeTransforms, physx::PxU32 nbActiveTransforms, float timeStep, physx::PxVec3 gravity) {
for (PxU32 i = 0; i < nbActiveTransforms; ++i) {
if (activeTransforms[i].userData != NULL) {
std::string *n = static_cast<std::string*>(activeTransforms[i].userData);
if (rigidBodies.find(*n) != rigidBodies.end()) {
PxRigidDynamic * actor = rigidBodies[*n].info.actor->is<PxRigidDynamic>();
if (rigidBodies[*n].rollingFriction >= 0.0f) {
float mass = actor->getMass();
float force = mass * gravity.magnitude() * rigidBodies[*n].rollingFriction;
float actorMotion = (mass * actor->getLinearVelocity().magnitude()) / ((float)rigidBodies[*n].rollingFrictionTimeStamp * timeStep);
if (force <= actorMotion) {
rigidBodies[*n].rollingFrictionTimeStamp++;
PxVec3 forceVec = -(actor->getLinearVelocity().getNormalized() * force);
actor->addForce(forceVec);
}
else {
rigidBodies[*n].rollingFrictionTimeStamp = 1;
//actor->setLinearVelocity(actor->getLinearVelocity() / 1.5f);
//actor->setAngularVelocity(actor->getAngularVelocity() / 1.5f);
//actor->setLinearVelocity(PxVec3(0.0f));
//actor->setAngularVelocity(PxVec3(0.0f));
}
}
PxMat44 mat(activeTransforms[i].actor2World);
mat.scale(PxVec4(PxVec3(rigidBodies[*n].scalingFactor), 1.0f));
//getMatFromPhysXTransform(activeTransforms[i].actor2World, rigidBodies[*n].extInfo.transform);
getMatFromPhysXTransform(mat, rigidBodies[*n].info.extInfo.transform);
}
}
}
}
示例4: AddRadialImpulseToPxRigidDynamic
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
}
示例5: setImpulse
void PhysXRigidManager::setImpulse(std::string scene, float * impulse) {
if (rigidBodies.find(scene) != rigidBodies.end()) {
PxRigidDynamic * actor = rigidBodies[scene].info.actor->is<PxRigidDynamic>();
if (actor) {
actor->addForce(PxVec3(impulse[0], impulse[1], impulse[2]), PxForceMode::eIMPULSE);
}
}
}
示例6:
void
PhysXRigidManager::setForce(std::string scene, float * force) {
if (rigidBodies.find(scene) != rigidBodies.end()) {
PxRigidDynamic * actor = rigidBodies[scene].info.actor->is<PxRigidDynamic>();
if (actor) {
actor->addForce(PxVec3(force[0], force[1], force[2]));
}
}
}
示例7: applyNitroBoost
void Vehicle::applyNitroBoost()
{
PxRigidDynamic* vehBody = vehDrive4W->getRigidDynamicActor();
vec3 forceVec = lastState->getPlayer(vehicleNum)->getForward();
forceVec = 39050.f * forceVec * vec3(1, 0, 1);
vehBody->addForce(getPxVec3(forceVec));
}
示例8: Shoot
void Physics::Shoot()
{
float densityS = 100;
PxSphereGeometry sphere(1);
PxTransform transformS(PxVec3(m_camera.world[3].x, m_camera.world[3].y, m_camera.world[3].z));
PxRigidDynamic* dynamicActorS = PxCreateDynamic(*g_Physics, transformS, sphere, *g_PhysicsMaterial, densityS);
//add it to the physx scene
g_PhysicsScene->addActor(*dynamicActorS);
dynamicActorS->addForce(PxVec3(-m_camera.world[2].x, -m_camera.world[2].y, -m_camera.world[2].z)*muzzleSpeed, PxForceMode::eIMPULSE, true);
}
示例9: AddForce
void UDestructibleComponent::AddForce( FVector Force, FName BoneName /*= NAME_None*/, bool bAccelChange /* = false */ )
{
#if WITH_APEX
int32 ChunkIdx = NxModuleDestructibleConst::INVALID_CHUNK_INDEX;
if (BoneName != NAME_None)
{
ChunkIdx = BoneIdxToChunkIdx(GetBoneIndex(BoneName));
}
PxRigidDynamic* Actor = ApexDestructibleActor->getChunkPhysXActor(ChunkIdx);
Actor->addForce(U2PVector(Force), bAccelChange ? PxForceMode::eACCELERATION : PxForceMode::eFORCE);
#endif
}
示例10: AddImpulse
void UDestructibleComponent::AddImpulse( FVector Impulse, FName BoneName /*= NAME_None*/, bool bVelChange /*= false*/ )
{
#if WITH_APEX
int32 ChunkIdx = BoneIdxToChunkIdx(GetBoneIndex(BoneName));
PxRigidDynamic* PActor = ApexDestructibleActor->getChunkPhysXActor(ChunkIdx);
if (PActor != NULL)
{
SCOPED_SCENE_WRITE_LOCK(PActor->getScene());
PActor->addForce(U2PVector(Impulse), bVelChange ? PxForceMode::eVELOCITY_CHANGE : PxForceMode::eIMPULSE);
}
#endif
}
示例11: AddForceAtLocation
void UDestructibleComponent::AddForceAtLocation( FVector Force, FVector Location, FName BoneName /*= NAME_None*/ )
{
#if WITH_APEX
if (ApexDestructibleActor)
{
int32 ChunkIdx = NxModuleDestructibleConst::INVALID_CHUNK_INDEX;
if (BoneName != NAME_None)
{
ChunkIdx = BoneIdxToChunkIdx(GetBoneIndex(BoneName));
}
PxRigidDynamic* Actor = ApexDestructibleActor->getChunkPhysXActor(ChunkIdx);
Actor->addForce(U2PVector(Force), PxForceMode::eFORCE);
}
#endif
}
示例12: ApplyForces
/** Applies forces - Assumes caller has obtained writer lock */
void FPhysSubstepTask::ApplyForces(const FPhysTarget & PhysTarget, FBodyInstance * BodyInstance)
{
#if WITH_PHYSX
/** Apply Forces */
PxRigidDynamic * PRigidDynamic = BodyInstance->GetPxRigidDynamic();
for (int32 i = 0; i < PhysTarget.Forces.Num(); ++i)
{
const FForceTarget & ForceTarget = PhysTarget.Forces[i];
if (ForceTarget.bPosition)
{
PxRigidBodyExt::addForceAtPos(*PRigidDynamic, U2PVector(ForceTarget.Force), U2PVector(ForceTarget.Position), PxForceMode::eFORCE, true);
}
else
{
PRigidDynamic->addForce(U2PVector(ForceTarget.Force), PxForceMode::eFORCE, true);
}
}
#endif
}
示例13: actorAddForce
void actorAddForce( PxActor* actor, PxVec3* force, PxForceMode::Enum mode, bool autowake )
{
PxRigidDynamic* rigid = (PxRigidDynamic*)actor;
rigid->addForce( *force, mode, autowake );
}