Makes vehicles work with the physics plugins.

Makes vehicles create a basic physics body when using one of the physics plugins so that they can collide with other physics-enabled objects.

Based on @rextimmy 's work.
This commit is contained in:
Areloch 2016-06-04 16:47:03 -05:00
parent 5122360552
commit 37e030f8f4
9 changed files with 161 additions and 2 deletions

View file

@ -378,3 +378,25 @@ void BtBody::setSimulationEnabled( bool enabled )
mIsEnabled = enabled;
}
void BtBody::moveKinematicTo(const MatrixF &transform)
{
AssertFatal(mActor, "BtBody::moveKinematicTo - The actor is null!");
U32 bodyflags = mActor->getCollisionFlags();
const bool isKinematic = bodyflags & BF_KINEMATIC;
if (!isKinematic)
{
Con::errorf("BtBody::moveKinematicTo is only for kinematic bodies.");
return;
}
if (mCenterOfMass)
{
MatrixF xfm;
xfm.mul(transform, *mCenterOfMass);
mActor->setCenterOfMassTransform(btCast<btTransform>(xfm));
}
else
mActor->setCenterOfMassTransform(btCast<btTransform>(transform));
}

View file

@ -111,6 +111,8 @@ public:
F32 staticFriction );
virtual void applyCorrection( const MatrixF &xfm );
virtual void applyImpulse( const Point3F &origin, const Point3F &force );
virtual void moveKinematicTo(const MatrixF &xfm);
};
#endif // _T3D_PHYSICS_BTBODY_H_

View file

@ -113,6 +113,10 @@ public:
///
virtual void applyImpulse( const Point3F &origin, const Point3F &force ) = 0;
///
virtual void moveKinematicTo(const MatrixF &xfm) = 0;
};

View file

@ -417,3 +417,22 @@ void Px3Body::applyImpulse( const Point3F &origin, const Point3F &force )
}
void Px3Body::moveKinematicTo(const MatrixF &transform)
{
AssertFatal(mActor, "Px3Body::moveKinematicTo - The actor is null!");
const bool isKinematic = mBodyFlags & BF_KINEMATIC;
if (!isKinematic)
{
Con::errorf("Px3Body::moveKinematicTo is only for kinematic bodies.");
return;
}
mWorld->lockScene();
physx::PxRigidDynamic *actor = mActor->is<physx::PxRigidDynamic>();
actor->setKinematicTarget(px3Cast<physx::PxTransform>(transform));
mWorld->unlockScene();
}

View file

@ -117,6 +117,8 @@ public:
F32 staticFriction );
virtual void applyCorrection( const MatrixF &xfm );
virtual void applyImpulse( const Point3F &origin, const Point3F &force );
virtual void moveKinematicTo(const MatrixF &xfm);
};
#endif // _PX3BODY_H_

View file

@ -62,7 +62,8 @@ Px3World::Px3World(): mScene( NULL ),
mIsEnabled( false ),
mEditorTimeScale( 1.0f ),
mAccumulator( 0 ),
mControllerManager( NULL )
mControllerManager(NULL),
mIsSceneLocked(false)
{
}
@ -335,6 +336,62 @@ void Px3World::releaseWriteLock()
//AssertFatal( mScene->isWritable(), "PhysX3World::releaseWriteLock() - We should have been writable now!" );
}
void Px3World::lockScenes()
{
Px3World *world = dynamic_cast<Px3World*>(PHYSICSMGR->getWorld("server"));
if (world)
world->lockScene();
world = dynamic_cast<Px3World*>(PHYSICSMGR->getWorld("client"));
if (world)
world->lockScene();
}
void Px3World::unlockScenes()
{
Px3World *world = dynamic_cast<Px3World*>(PHYSICSMGR->getWorld("server"));
if (world)
world->unlockScene();
world = dynamic_cast<Px3World*>(PHYSICSMGR->getWorld("client"));
if (world)
world->unlockScene();
}
void Px3World::lockScene()
{
if (!mScene)
return;
if (mIsSceneLocked)
{
Con::printf("Px3World: Attempting to lock a scene that is already locked.");
return;
}
mScene->lockWrite();
mIsSceneLocked = true;
}
void Px3World::unlockScene()
{
if (!mScene)
return;
if (!mIsSceneLocked)
{
Con::printf("Px3World: Attempting to unlock a scene that is not locked.");
return;
}
mScene->unlockWrite();
mIsSceneLocked = false;
}
bool Px3World::castRay( const Point3F &startPnt, const Point3F &endPnt, RayInfo *ri, const Point3F &impulse )
{

View file

@ -56,6 +56,7 @@ protected:
bool mIsEnabled;
bool mIsSimulating;
bool mIsServer;
bool mIsSceneLocked;
U32 mTickCount;
ProcessList *mProcessList;
F32 mEditorTimeScale;
@ -96,11 +97,15 @@ public:
void releaseWriteLock();
bool isServer(){return mIsServer;}
physx::PxController* createController( physx::PxControllerDesc &desc );
void lockScene();
void unlockScene();
//static
static bool restartSDK( bool destroyOnly = false, Px3World *clientWorld = NULL, Px3World *serverWorld = NULL );
static void releaseWriteLocks();
static physx::PxCooking *getCooking();
static void setTiming(F32 stepTime,U32 maxIterations);
static void lockScenes();
static void unlockScenes();
};
#endif // _PX3WORLD_H_