mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 12:37:51 +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"
|
#include "PhysicsEngine.h"
|
||||||
|
|
||||||
KinematicController::KinematicController() {
|
KinematicController::KinematicController() {
|
||||||
_lastFrame = PhysicsEngine::getFrameCount();
|
_lastSubstep = PhysicsEngine::getNumSubsteps();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KinematicController::start() {
|
void KinematicController::start() {
|
||||||
_enabled = true;
|
_enabled = true;
|
||||||
_lastFrame = PhysicsEngine::getFrameCount();
|
_lastSubstep = PhysicsEngine::getNumSubsteps();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool _enabled = false;
|
bool _enabled = false;
|
||||||
uint32_t _lastFrame;
|
uint32_t _lastSubstep;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_KinematicController_h
|
#endif // hifi_KinematicController_h
|
||||||
|
|
|
@ -13,11 +13,11 @@
|
||||||
#include "ShapeInfoUtil.h"
|
#include "ShapeInfoUtil.h"
|
||||||
#include "ThreadSafeDynamicsWorld.h"
|
#include "ThreadSafeDynamicsWorld.h"
|
||||||
|
|
||||||
static uint32_t _frameCount;
|
static uint32_t _numSubsteps;
|
||||||
|
|
||||||
// static
|
// static
|
||||||
uint32_t PhysicsEngine::getFrameCount() {
|
uint32_t PhysicsEngine::getNumSubsteps() {
|
||||||
return _frameCount;
|
return _numSubsteps;
|
||||||
}
|
}
|
||||||
|
|
||||||
PhysicsEngine::PhysicsEngine(const glm::vec3& offset)
|
PhysicsEngine::PhysicsEngine(const glm::vec3& offset)
|
||||||
|
@ -47,8 +47,8 @@ void PhysicsEngine::updateEntitiesInternal(const quint64& now) {
|
||||||
ObjectMotionState* state = *stateItr;
|
ObjectMotionState* state = *stateItr;
|
||||||
if (state->doesNotNeedToSendUpdate()) {
|
if (state->doesNotNeedToSendUpdate()) {
|
||||||
stateItr = _outgoingPackets.erase(stateItr);
|
stateItr = _outgoingPackets.erase(stateItr);
|
||||||
} else if (state->shouldSendUpdate(_frameCount)) {
|
} else if (state->shouldSendUpdate(_numSubsteps)) {
|
||||||
state->sendUpdate(_entityPacketSender, _frameCount);
|
state->sendUpdate(_entityPacketSender, _numSubsteps);
|
||||||
++stateItr;
|
++stateItr;
|
||||||
} else {
|
} else {
|
||||||
++stateItr;
|
++stateItr;
|
||||||
|
@ -141,7 +141,7 @@ void PhysicsEngine::relayIncomingChangesToSimulation() {
|
||||||
} else if (flags) {
|
} else if (flags) {
|
||||||
// an EASY update does NOT require that the body be pulled out of physics engine
|
// 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.
|
// 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);
|
float timeStep = btMin(dt, MAX_TIMESTEP);
|
||||||
|
|
||||||
// This is step (2).
|
// This is step (2).
|
||||||
int numSubSteps = _dynamicsWorld->stepSimulation(timeStep, MAX_NUM_SUBSTEPS, PHYSICS_ENGINE_FIXED_SUBSTEP);
|
int numSubsteps = _dynamicsWorld->stepSimulation(timeStep, MAX_NUM_SUBSTEPS, PHYSICS_ENGINE_FIXED_SUBSTEP);
|
||||||
_frameCount += (uint32_t)numSubSteps;
|
_numSubsteps += (uint32_t)numSubsteps;
|
||||||
unlock();
|
unlock();
|
||||||
|
|
||||||
// This is step (3) which is done outside of stepSimulation() so we can lock _entityTree.
|
// This is step (3) which is done outside of stepSimulation() so we can lock _entityTree.
|
||||||
|
@ -233,6 +233,12 @@ void PhysicsEngine::stepSimulation() {
|
||||||
_dynamicsWorld->synchronizeMotionStates();
|
_dynamicsWorld->synchronizeMotionStates();
|
||||||
unlock();
|
unlock();
|
||||||
_entityTree->unlock();
|
_entityTree->unlock();
|
||||||
|
|
||||||
|
handleCollisionEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicsEngine::handleCollisionEvents() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bullet collision flags are as follows:
|
// Bullet collision flags are as follows:
|
||||||
|
@ -352,7 +358,7 @@ void PhysicsEngine::updateObjectHard(btRigidBody* body, ObjectMotionState* motio
|
||||||
}
|
}
|
||||||
bool easyUpdate = flags & EASY_DIRTY_PHYSICS_FLAGS;
|
bool easyUpdate = flags & EASY_DIRTY_PHYSICS_FLAGS;
|
||||||
if (easyUpdate) {
|
if (easyUpdate) {
|
||||||
motionState->updateObjectEasy(flags, _frameCount);
|
motionState->updateObjectEasy(flags, _numSubsteps);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the motion parameters
|
// update the motion parameters
|
||||||
|
|
|
@ -33,7 +33,7 @@ class ObjectMotionState;
|
||||||
|
|
||||||
class PhysicsEngine : public EntitySimulation {
|
class PhysicsEngine : public EntitySimulation {
|
||||||
public:
|
public:
|
||||||
static uint32_t getFrameCount();
|
static uint32_t getNumSubsteps();
|
||||||
|
|
||||||
PhysicsEngine(const glm::vec3& offset);
|
PhysicsEngine(const glm::vec3& offset);
|
||||||
|
|
||||||
|
@ -51,6 +51,8 @@ public:
|
||||||
|
|
||||||
void stepSimulation();
|
void stepSimulation();
|
||||||
|
|
||||||
|
void handleCollisionEvents();
|
||||||
|
|
||||||
/// \param offset position of simulation origin in domain-frame
|
/// \param offset position of simulation origin in domain-frame
|
||||||
void setOriginOffset(const glm::vec3& offset) { _originOffset = offset; }
|
void setOriginOffset(const glm::vec3& offset) { _originOffset = offset; }
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,9 @@
|
||||||
#include "SimpleEntityKinematicController.h"
|
#include "SimpleEntityKinematicController.h"
|
||||||
|
|
||||||
void SimpleEntityKinematicController:: stepForward() {
|
void SimpleEntityKinematicController:: stepForward() {
|
||||||
uint32_t frame = PhysicsEngine::getFrameCount();
|
uint32_t substep = PhysicsEngine::getNumSubsteps();
|
||||||
float dt = (frame - _lastFrame) * PHYSICS_ENGINE_FIXED_SUBSTEP;
|
float dt = (substep - _lastSubstep) * PHYSICS_ENGINE_FIXED_SUBSTEP;
|
||||||
_entity->simulateSimpleKinematicMotion(dt);
|
_entity->simulateSimpleKinematicMotion(dt);
|
||||||
_lastFrame = frame;
|
_lastSubstep = substep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue