mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
change FrameCount to NumSubsteps for more accuracy
This commit is contained in:
parent
549e3fac5f
commit
0154c613d0
5 changed files with 24 additions and 16 deletions
|
@ -13,10 +13,10 @@
|
|||
#include "PhysicsEngine.h"
|
||||
|
||||
KinematicController::KinematicController() {
|
||||
_lastFrame = PhysicsEngine::getFrameCount();
|
||||
_lastSubstep = PhysicsEngine::getNumSubsteps();
|
||||
}
|
||||
|
||||
void KinematicController::start() {
|
||||
_enabled = true;
|
||||
_lastFrame = PhysicsEngine::getFrameCount();
|
||||
_lastSubstep = PhysicsEngine::getNumSubsteps();
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public:
|
|||
|
||||
protected:
|
||||
bool _enabled = false;
|
||||
uint32_t _lastFrame;
|
||||
uint32_t _lastSubstep;
|
||||
};
|
||||
|
||||
#endif // hifi_KinematicController_h
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
#include "ShapeInfoUtil.h"
|
||||
#include "ThreadSafeDynamicsWorld.h"
|
||||
|
||||
static uint32_t _frameCount;
|
||||
static uint32_t _numSubsteps;
|
||||
|
||||
// static
|
||||
uint32_t PhysicsEngine::getFrameCount() {
|
||||
return _frameCount;
|
||||
uint32_t PhysicsEngine::getNumSubsteps() {
|
||||
return _numSubsteps;
|
||||
}
|
||||
|
||||
PhysicsEngine::PhysicsEngine(const glm::vec3& offset)
|
||||
|
@ -47,8 +47,8 @@ void PhysicsEngine::updateEntitiesInternal(const quint64& now) {
|
|||
ObjectMotionState* state = *stateItr;
|
||||
if (state->doesNotNeedToSendUpdate()) {
|
||||
stateItr = _outgoingPackets.erase(stateItr);
|
||||
} else if (state->shouldSendUpdate(_frameCount)) {
|
||||
state->sendUpdate(_entityPacketSender, _frameCount);
|
||||
} else if (state->shouldSendUpdate(_numSubsteps)) {
|
||||
state->sendUpdate(_entityPacketSender, _numSubsteps);
|
||||
++stateItr;
|
||||
} else {
|
||||
++stateItr;
|
||||
|
@ -141,7 +141,7 @@ void PhysicsEngine::relayIncomingChangesToSimulation() {
|
|||
} else if (flags) {
|
||||
// an EASY update does NOT require that the body be pulled out of physics engine
|
||||
// hence the MotionState has all the knowledge and authority to perform the update.
|
||||
motionState->updateObjectEasy(flags, _frameCount);
|
||||
motionState->updateObjectEasy(flags, _numSubsteps);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,8 +216,8 @@ void PhysicsEngine::stepSimulation() {
|
|||
float timeStep = btMin(dt, MAX_TIMESTEP);
|
||||
|
||||
// This is step (2).
|
||||
int numSubSteps = _dynamicsWorld->stepSimulation(timeStep, MAX_NUM_SUBSTEPS, PHYSICS_ENGINE_FIXED_SUBSTEP);
|
||||
_frameCount += (uint32_t)numSubSteps;
|
||||
int numSubsteps = _dynamicsWorld->stepSimulation(timeStep, MAX_NUM_SUBSTEPS, PHYSICS_ENGINE_FIXED_SUBSTEP);
|
||||
_numSubsteps += (uint32_t)numSubsteps;
|
||||
unlock();
|
||||
|
||||
// This is step (3) which is done outside of stepSimulation() so we can lock _entityTree.
|
||||
|
@ -233,6 +233,12 @@ void PhysicsEngine::stepSimulation() {
|
|||
_dynamicsWorld->synchronizeMotionStates();
|
||||
unlock();
|
||||
_entityTree->unlock();
|
||||
|
||||
handleCollisionEvents();
|
||||
}
|
||||
|
||||
void PhysicsEngine::handleCollisionEvents() {
|
||||
|
||||
}
|
||||
|
||||
// Bullet collision flags are as follows:
|
||||
|
@ -352,7 +358,7 @@ void PhysicsEngine::updateObjectHard(btRigidBody* body, ObjectMotionState* motio
|
|||
}
|
||||
bool easyUpdate = flags & EASY_DIRTY_PHYSICS_FLAGS;
|
||||
if (easyUpdate) {
|
||||
motionState->updateObjectEasy(flags, _frameCount);
|
||||
motionState->updateObjectEasy(flags, _numSubsteps);
|
||||
}
|
||||
|
||||
// update the motion parameters
|
||||
|
|
|
@ -33,7 +33,7 @@ class ObjectMotionState;
|
|||
|
||||
class PhysicsEngine : public EntitySimulation {
|
||||
public:
|
||||
static uint32_t getFrameCount();
|
||||
static uint32_t getNumSubsteps();
|
||||
|
||||
PhysicsEngine(const glm::vec3& offset);
|
||||
|
||||
|
@ -51,6 +51,8 @@ public:
|
|||
|
||||
void stepSimulation();
|
||||
|
||||
void handleCollisionEvents();
|
||||
|
||||
/// \param offset position of simulation origin in domain-frame
|
||||
void setOriginOffset(const glm::vec3& offset) { _originOffset = offset; }
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
#include "SimpleEntityKinematicController.h"
|
||||
|
||||
void SimpleEntityKinematicController:: stepForward() {
|
||||
uint32_t frame = PhysicsEngine::getFrameCount();
|
||||
float dt = (frame - _lastFrame) * PHYSICS_ENGINE_FIXED_SUBSTEP;
|
||||
uint32_t substep = PhysicsEngine::getNumSubsteps();
|
||||
float dt = (substep - _lastSubstep) * PHYSICS_ENGINE_FIXED_SUBSTEP;
|
||||
_entity->simulateSimpleKinematicMotion(dt);
|
||||
_lastFrame = frame;
|
||||
_lastSubstep = substep;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue