add creation of dynamic physics objects

This commit is contained in:
nillerusr 2023-10-18 22:38:42 +03:00
parent 58ff2f3a72
commit 5835b207c1
3 changed files with 47 additions and 13 deletions

View File

@ -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;
} }

View File

@ -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;

View File

@ -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