mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 20:17:01 +02:00
MotionState reports zero velocity for slow objects
This reduces the number of updates for an Entity that is effectively at rest due to a balance between some spring action and gravity, but nevertheless has a slight non-zero velocity at the end of each simulation step.
This commit is contained in:
parent
542a5f100a
commit
46bca30698
2 changed files with 14 additions and 4 deletions
|
@ -248,7 +248,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) {
|
||||||
btTransform xform = _body->getWorldTransform();
|
btTransform xform = _body->getWorldTransform();
|
||||||
_serverPosition = bulletToGLM(xform.getOrigin());
|
_serverPosition = bulletToGLM(xform.getOrigin());
|
||||||
_serverRotation = bulletToGLM(xform.getRotation());
|
_serverRotation = bulletToGLM(xform.getRotation());
|
||||||
_serverVelocity = bulletToGLM(_body->getLinearVelocity());
|
_serverVelocity = getBodyLinearVelocity();
|
||||||
_serverAngularVelocity = bulletToGLM(_body->getAngularVelocity());
|
_serverAngularVelocity = bulletToGLM(_body->getAngularVelocity());
|
||||||
_lastStep = simulationStep;
|
_lastStep = simulationStep;
|
||||||
_serverActionData = _entity->getActionData();
|
_serverActionData = _entity->getActionData();
|
||||||
|
@ -536,7 +536,7 @@ void EntityMotionState::bump(quint8 priority) {
|
||||||
void EntityMotionState::resetMeasuredBodyAcceleration() {
|
void EntityMotionState::resetMeasuredBodyAcceleration() {
|
||||||
_lastMeasureStep = ObjectMotionState::getWorldSimulationStep();
|
_lastMeasureStep = ObjectMotionState::getWorldSimulationStep();
|
||||||
if (_body) {
|
if (_body) {
|
||||||
_lastVelocity = bulletToGLM(_body->getLinearVelocity());
|
_lastVelocity = getBodyLinearVelocity();
|
||||||
} else {
|
} else {
|
||||||
_lastVelocity = glm::vec3(0.0f);
|
_lastVelocity = glm::vec3(0.0f);
|
||||||
}
|
}
|
||||||
|
@ -555,7 +555,7 @@ void EntityMotionState::measureBodyAcceleration() {
|
||||||
|
|
||||||
// Note: the integration equation for velocity uses damping: v1 = (v0 + a * dt) * (1 - D)^dt
|
// Note: the integration equation for velocity uses damping: v1 = (v0 + a * dt) * (1 - D)^dt
|
||||||
// hence the equation for acceleration is: a = (v1 / (1 - D)^dt - v0) / dt
|
// hence the equation for acceleration is: a = (v1 / (1 - D)^dt - v0) / dt
|
||||||
glm::vec3 velocity = bulletToGLM(_body->getLinearVelocity());
|
glm::vec3 velocity = getBodyLinearVelocity();
|
||||||
_measuredAcceleration = (velocity / powf(1.0f - _body->getLinearDamping(), dt) - _lastVelocity) * invDt;
|
_measuredAcceleration = (velocity / powf(1.0f - _body->getLinearDamping(), dt) - _lastVelocity) * invDt;
|
||||||
_lastVelocity = velocity;
|
_lastVelocity = velocity;
|
||||||
if (numSubsteps > PHYSICS_ENGINE_MAX_NUM_SUBSTEPS) {
|
if (numSubsteps > PHYSICS_ENGINE_MAX_NUM_SUBSTEPS) {
|
||||||
|
|
|
@ -80,7 +80,17 @@ void ObjectMotionState::setBodyGravity(const glm::vec3& gravity) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 ObjectMotionState::getBodyLinearVelocity() const {
|
glm::vec3 ObjectMotionState::getBodyLinearVelocity() const {
|
||||||
return bulletToGLM(_body->getLinearVelocity());
|
// returns the body's velocity unless it is moving too slow in which case returns zero
|
||||||
|
btVector3 velocity = _body->getLinearVelocity();
|
||||||
|
|
||||||
|
// NOTE: the threshold to use here relates to the linear displacement threshold (dX) for sending updates
|
||||||
|
// to objects that are tracked server-side (e.g. entities which use dX = 2mm). Hence an object moving
|
||||||
|
// just under this velocity threshold would trigger an update about V/dX times per second.
|
||||||
|
const float MIN_LINEAR_SPEED_SQUARED = 0.0036f; // 6 mm/sec
|
||||||
|
if (velocity.length2() < MIN_LINEAR_SPEED_SQUARED) {
|
||||||
|
velocity *= 0.0f;
|
||||||
|
}
|
||||||
|
return bulletToGLM(velocity);
|
||||||
}
|
}
|
||||||
glm::vec3 ObjectMotionState::getObjectLinearVelocityChange() const {
|
glm::vec3 ObjectMotionState::getObjectLinearVelocityChange() const {
|
||||||
return glm::vec3(0.0f); // Subclasses override where meaningful.
|
return glm::vec3(0.0f); // Subclasses override where meaningful.
|
||||||
|
|
Loading…
Reference in a new issue