fix mass setting

This commit is contained in:
nillerusr 2023-10-19 13:02:56 +03:00
parent 5835b207c1
commit ce44f36999
2 changed files with 15 additions and 32 deletions

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, 0.0f, -50.f); sceneDesc.gravity = physx::PxVec3(0.0f, 0.0f, -600.f);
m_pPxDispatcher = PxDefaultCpuDispatcherCreate(2); m_pPxDispatcher = PxDefaultCpuDispatcherCreate(2);
sceneDesc.cpuDispatcher = m_pPxDispatcher; sceneDesc.cpuDispatcher = m_pPxDispatcher;
@ -1525,9 +1525,10 @@ void CPhysicsEnvironment::Simulate( float deltaTime )
deltaTime = 0.1f; deltaTime = 0.1f;
} }
m_pPxScene->simulate(deltaTime); m_pPxScene->simulate( deltaTime /*1/60.f*/); // nillerusr: Stable simulation for testing in debug builds
m_pPxScene->fetchResults(true); m_pPxScene->fetchResults(true);
#if 0 #if 0
m_pCollisionSolver->EventPSI( this ); m_pCollisionSolver->EventPSI( this );
m_pCollisionListener->EventPSI( this ); m_pCollisionListener->EventPSI( this );

View File

@ -1030,12 +1030,14 @@ static PxRigidActor *CreatePxActor(PxTransform &transform, PxShape *shape, int m
shape = (PxShape*)shape->userData; shape = (PxShape*)shape->userData;
} }
if( !isStatic ) if( isStatic )
PxRigidBodyExt::setMassAndUpdateInertia( *(PxRigidDynamic*)actor, 0.05 ); return actor;
return actor; float mass = clamp( pParams->mass, VPHYSICS_MIN_MASS, VPHYSICS_MAX_MASS );
PxRigidDynamic *dynamic = (PxRigidDynamic*)actor;
PxRigidBodyExt::setMassAndUpdateInertia( *dynamic, mass );
// objectTemplate.mass = clamp( pParams->mass, VPHYSICS_MIN_MASS, VPHYSICS_MAX_MASS );
// if ( materialIndex >= 0 ) // if ( materialIndex >= 0 )
// { // {
// objectTemplate.material = physprops->GetIVPMaterial( materialIndex ); // objectTemplate.material = physprops->GetIVPMaterial( materialIndex );
@ -1046,12 +1048,14 @@ static PxRigidActor *CreatePxActor(PxTransform &transform, PxShape *shape, int m
// objectTemplate.material = physprops->GetIVPMaterial( materialIndex ); // objectTemplate.material = physprops->GetIVPMaterial( materialIndex );
// } // }
PxVec3 massInertia = dynamic->getMassSpaceInertiaTensor();
massInertia *= pParams->inertia;
dynamic->setMassSpaceInertiaTensor(massInertia);
dynamic->setAngularDamping( pParams->rotdamping );
dynamic->setLinearDamping( pParams->damping );
// objectTemplate.rot_inertia.set(inertia, inertia, inertia); return actor;
// 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;
} }
@ -1131,28 +1135,6 @@ CPhysicsObject *CreatePhysicsObject( CPhysicsEnvironment *pEnvironment, const CP
PxRigidActor *body = CreatePxActor( t, shape, materialIndex, pParams, isStatic ); PxRigidActor *body = CreatePxActor( t, shape, materialIndex, pParams, isStatic );
scene->addActor(*body); scene->addActor(*body);
} }
#if 0
if( pCollisionModel && mesh->getNbVertices() != 0 )
{
RadianEuler radian(angles);
Quaternion qw(radian);
PxQuat q( qw.x, qw.y, qw.z, qw.w );
PxTransform t(PxVec3(position.x, position.y, position.z), q);
PxMaterial *mat = gPxPhysics->createMaterial(0.5f, 0.5f, 0.6f);
PxRigidStatic* body = gPxPhysics->createRigidStatic(t);
if( body )
{
PxShape* aConvexShape = PxRigidActorExt::createExclusiveShape(*body,
PxConvexMeshGeometry(mesh), *mat);
scene->addActor(*body);
}
}
#endif
pObject->Init( pCollisionModel, NULL, materialIndex, pParams->volume, pParams->dragCoefficient, pParams->dragCoefficient ); pObject->Init( pCollisionModel, NULL, materialIndex, pParams->volume, pParams->dragCoefficient, pParams->dragCoefficient );
pObject->SetGameData( pParams->pGameData ); pObject->SetGameData( pParams->pGameData );