mirror of
https://github.com/nillerusr/source-engine.git
synced 2024-12-22 14:16:50 +00:00
add creation of dynamic physics objects
This commit is contained in:
parent
58ff2f3a72
commit
5835b207c1
@ -127,9 +127,6 @@ InitReturnVal_t CPhysicsInterface::Init()
|
|||||||
|
|
||||||
MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f, false, false, false, false );
|
MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f, false, false, false, false );
|
||||||
|
|
||||||
PxTolerancesScale scale;
|
|
||||||
scale.length = g_PhysicsUnits.unitScaleMetersInv; // typical length of an object
|
|
||||||
|
|
||||||
gPxFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gPxAllocatorCallback, gPxErrorCallback);
|
gPxFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gPxAllocatorCallback, gPxErrorCallback);
|
||||||
|
|
||||||
if( !gPxFoundation )
|
if( !gPxFoundation )
|
||||||
@ -145,6 +142,11 @@ InitReturnVal_t CPhysicsInterface::Init()
|
|||||||
|
|
||||||
gPxPvd->connect(*transport,PxPvdInstrumentationFlag::eALL);
|
gPxPvd->connect(*transport,PxPvdInstrumentationFlag::eALL);
|
||||||
|
|
||||||
|
PxTolerancesScale scale;
|
||||||
|
|
||||||
|
scale.length = g_PhysicsUnits.unitScaleMetersInv;
|
||||||
|
scale.speed *= g_PhysicsUnits.unitScaleMetersInv;
|
||||||
|
|
||||||
gPxPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *gPxFoundation, scale, recordMemoryAllocations, gPxPvd);
|
gPxPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *gPxFoundation, scale, recordMemoryAllocations, gPxPvd);
|
||||||
|
|
||||||
if( !gPxPhysics )
|
if( !gPxPhysics )
|
||||||
@ -153,7 +155,7 @@ InitReturnVal_t CPhysicsInterface::Init()
|
|||||||
return INIT_FAILED;
|
return INIT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
gPxCooking = PxCreateCooking(PX_PHYSICS_VERSION, *gPxFoundation , PxCookingParams(scale));
|
gPxCooking = PxCreateCooking(PX_PHYSICS_VERSION, *gPxFoundation, PxCookingParams(scale));
|
||||||
return INIT_OK;
|
return INIT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1117,7 +1117,7 @@ CPhysicsEnvironment::CPhysicsEnvironment( void )
|
|||||||
// PHYSX_BEGIN
|
// PHYSX_BEGIN
|
||||||
|
|
||||||
PxSceneDesc sceneDesc(gPxPhysics->getTolerancesScale());
|
PxSceneDesc sceneDesc(gPxPhysics->getTolerancesScale());
|
||||||
sceneDesc.gravity = physx::PxVec3(0.0f, -9.81f, 0.0f);
|
sceneDesc.gravity = physx::PxVec3(0.0f, 0.0f, -50.f);
|
||||||
|
|
||||||
m_pPxDispatcher = PxDefaultCpuDispatcherCreate(2);
|
m_pPxDispatcher = PxDefaultCpuDispatcherCreate(2);
|
||||||
sceneDesc.cpuDispatcher = m_pPxDispatcher;
|
sceneDesc.cpuDispatcher = m_pPxDispatcher;
|
||||||
|
@ -1016,6 +1016,45 @@ static void InitObjectTemplate( IVP_Template_Real_Object &objectTemplate, int ma
|
|||||||
objectTemplate.auto_check_rot_inertia = pParams->rotInertiaLimit;
|
objectTemplate.auto_check_rot_inertia = pParams->rotInertiaLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PxRigidActor *CreatePxActor(PxTransform &transform, PxShape *shape, int materialIndex, objectparams_t *pParams, bool isStatic )
|
||||||
|
{
|
||||||
|
PxRigidActor *actor;
|
||||||
|
if( isStatic )
|
||||||
|
actor = gPxPhysics->createRigidStatic(transform);
|
||||||
|
else
|
||||||
|
actor = gPxPhysics->createRigidDynamic(transform);
|
||||||
|
|
||||||
|
while( shape )
|
||||||
|
{
|
||||||
|
actor->attachShape( *shape );
|
||||||
|
shape = (PxShape*)shape->userData;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !isStatic )
|
||||||
|
PxRigidBodyExt::setMassAndUpdateInertia( *(PxRigidDynamic*)actor, 0.05 );
|
||||||
|
|
||||||
|
return actor;
|
||||||
|
|
||||||
|
// objectTemplate.mass = clamp( pParams->mass, VPHYSICS_MIN_MASS, VPHYSICS_MAX_MASS );
|
||||||
|
// if ( materialIndex >= 0 )
|
||||||
|
// {
|
||||||
|
// objectTemplate.material = physprops->GetIVPMaterial( materialIndex );
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// materialIndex = physprops->GetSurfaceIndex( "default" );
|
||||||
|
// objectTemplate.material = physprops->GetIVPMaterial( materialIndex );
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// objectTemplate.rot_inertia.set(inertia, inertia, inertia);
|
||||||
|
// objectTemplate.rot_speed_damp_factor.set(pParams->rotdamping, pParams->rotdamping, pParams->rotdamping);
|
||||||
|
// objectTemplate.speed_damp_factor = pParams->damping;
|
||||||
|
// objectTemplate.auto_check_rot_inertia = pParams->rotInertiaLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
CPhysicsObject *CreatePhysicsObject( CPhysicsEnvironment *pEnvironment, const CPhysCollide *pCollisionModel, int materialIndex, const Vector &position, const QAngle& angles, objectparams_t *pParams, bool isStatic )
|
CPhysicsObject *CreatePhysicsObject( CPhysicsEnvironment *pEnvironment, const CPhysCollide *pCollisionModel, int materialIndex, const Vector &position, const QAngle& angles, objectparams_t *pParams, bool isStatic )
|
||||||
{
|
{
|
||||||
if ( materialIndex < 0 )
|
if ( materialIndex < 0 )
|
||||||
@ -1089,14 +1128,7 @@ CPhysicsObject *CreatePhysicsObject( CPhysicsEnvironment *pEnvironment, const CP
|
|||||||
PxQuat q( qw.x, qw.y, qw.z, qw.w );
|
PxQuat q( qw.x, qw.y, qw.z, qw.w );
|
||||||
|
|
||||||
PxTransform t(PxVec3(position.x, position.y, position.z), q);
|
PxTransform t(PxVec3(position.x, position.y, position.z), q);
|
||||||
PxRigidStatic* body = gPxPhysics->createRigidStatic(t);
|
PxRigidActor *body = CreatePxActor( t, shape, materialIndex, pParams, isStatic );
|
||||||
|
|
||||||
while( shape )
|
|
||||||
{
|
|
||||||
body->attachShape( *shape );
|
|
||||||
shape = (PxShape*)shape->userData;
|
|
||||||
}
|
|
||||||
|
|
||||||
scene->addActor(*body);
|
scene->addActor(*body);
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
|
Loading…
Reference in New Issue
Block a user