mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-13 06:18:43 +02:00
Merge branch 'physics-substep-fix' into baseball
This commit is contained in:
commit
b75ad7f254
4 changed files with 14 additions and 6 deletions
|
@ -774,7 +774,7 @@ void EntityTreeRenderer::entityCollisionWithEntity(const EntityItemID& idA, cons
|
|||
}
|
||||
// Don't respond to small continuous contacts.
|
||||
const float COLLISION_MINUMUM_PENETRATION = 0.002f;
|
||||
if ((collision.type != CONTACT_EVENT_TYPE_START) && (glm::length(collision.penetration) < COLLISION_MINUMUM_PENETRATION)) {
|
||||
if ((collision.type == CONTACT_EVENT_TYPE_CONTINUE) && (glm::length(collision.penetration) < COLLISION_MINUMUM_PENETRATION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -251,7 +251,12 @@ void PhysicsEngine::stepSimulation() {
|
|||
_characterController->preSimulation(timeStep);
|
||||
}
|
||||
|
||||
int numSubsteps = _dynamicsWorld->stepSimulation(timeStep, PHYSICS_ENGINE_MAX_NUM_SUBSTEPS, PHYSICS_ENGINE_FIXED_SUBSTEP);
|
||||
auto onSubStep = [this]() {
|
||||
updateContactMap();
|
||||
_hasOutgoingChanges = true;
|
||||
};
|
||||
|
||||
int numSubsteps = _dynamicsWorld->stepSimulation(timeStep, PHYSICS_ENGINE_MAX_NUM_SUBSTEPS, PHYSICS_ENGINE_FIXED_SUBSTEP, onSubStep);
|
||||
if (numSubsteps > 0) {
|
||||
BT_PROFILE("postSimulation");
|
||||
_numSubsteps += (uint32_t)numSubsteps;
|
||||
|
@ -260,8 +265,6 @@ void PhysicsEngine::stepSimulation() {
|
|||
if (_characterController) {
|
||||
_characterController->postSimulation();
|
||||
}
|
||||
updateContactMap();
|
||||
_hasOutgoingChanges = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ ThreadSafeDynamicsWorld::ThreadSafeDynamicsWorld(
|
|||
: btDiscreteDynamicsWorld(dispatcher, pairCache, constraintSolver, collisionConfiguration) {
|
||||
}
|
||||
|
||||
int ThreadSafeDynamicsWorld::stepSimulation( btScalar timeStep, int maxSubSteps, btScalar fixedTimeStep) {
|
||||
int ThreadSafeDynamicsWorld::stepSimulation( btScalar timeStep, int maxSubSteps, btScalar fixedTimeStep, SubStepCallback onSubStep) {
|
||||
BT_PROFILE("stepSimulation");
|
||||
int subSteps = 0;
|
||||
if (maxSubSteps) {
|
||||
|
@ -70,6 +70,7 @@ int ThreadSafeDynamicsWorld::stepSimulation( btScalar timeStep, int maxSubSteps,
|
|||
|
||||
for (int i=0;i<clampedSimulationSteps;i++) {
|
||||
internalSingleStepSimulation(fixedTimeStep);
|
||||
onSubStep();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
|
||||
#include "ObjectMotionState.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
using SubStepCallback = std::function<void()>;
|
||||
|
||||
ATTRIBUTE_ALIGNED16(class) ThreadSafeDynamicsWorld : public btDiscreteDynamicsWorld {
|
||||
public:
|
||||
BT_DECLARE_ALIGNED_ALLOCATOR();
|
||||
|
@ -34,7 +38,7 @@ public:
|
|||
btCollisionConfiguration* collisionConfiguration);
|
||||
|
||||
// virtual overrides from btDiscreteDynamicsWorld
|
||||
int stepSimulation( btScalar timeStep, int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.));
|
||||
int stepSimulation( btScalar timeStep, int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.), SubStepCallback onSubStep = []() { });
|
||||
void synchronizeMotionStates();
|
||||
|
||||
// btDiscreteDynamicsWorld::m_localTime is the portion of real-time that has not yet been simulated
|
||||
|
|
Loading…
Reference in a new issue