mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 12:09:45 +02:00
new method -- ObjectMotionState::getBodyLinearVelocityGTSigma
This commit is contained in:
parent
113321184d
commit
6f30a3c178
3 changed files with 17 additions and 19 deletions
|
@ -32,11 +32,6 @@ static const quint8 STEPS_TO_DECIDE_BALLISTIC = 4;
|
||||||
const uint32_t LOOPS_FOR_SIMULATION_ORPHAN = 50;
|
const uint32_t LOOPS_FOR_SIMULATION_ORPHAN = 50;
|
||||||
const quint64 USECS_BETWEEN_OWNERSHIP_BIDS = USECS_PER_SECOND / 5;
|
const quint64 USECS_BETWEEN_OWNERSHIP_BIDS = USECS_PER_SECOND / 5;
|
||||||
|
|
||||||
// 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
|
|
||||||
|
|
||||||
#ifdef WANT_DEBUG_ENTITY_TREE_LOCKS
|
#ifdef WANT_DEBUG_ENTITY_TREE_LOCKS
|
||||||
bool EntityMotionState::entityTreeIsLocked() const {
|
bool EntityMotionState::entityTreeIsLocked() const {
|
||||||
EntityTreeElementPointer element = _entity ? _entity->getElement() : nullptr;
|
EntityTreeElementPointer element = _entity ? _entity->getElement() : nullptr;
|
||||||
|
@ -253,11 +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 = getBodyLinearVelocity();
|
_serverVelocity = getBodyLinearVelocityGTSigma();
|
||||||
if (glm::length2(_serverVelocity) < MIN_LINEAR_SPEED_SQUARED) {
|
|
||||||
_serverVelocity *= 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
_serverAngularVelocity = bulletToGLM(_body->getAngularVelocity());
|
_serverAngularVelocity = bulletToGLM(_body->getAngularVelocity());
|
||||||
_lastStep = simulationStep;
|
_lastStep = simulationStep;
|
||||||
_serverActionData = _entity->getActionData();
|
_serverActionData = _entity->getActionData();
|
||||||
|
@ -556,11 +547,7 @@ void EntityMotionState::bump(quint8 priority) {
|
||||||
void EntityMotionState::resetMeasuredBodyAcceleration() {
|
void EntityMotionState::resetMeasuredBodyAcceleration() {
|
||||||
_lastMeasureStep = ObjectMotionState::getWorldSimulationStep();
|
_lastMeasureStep = ObjectMotionState::getWorldSimulationStep();
|
||||||
if (_body) {
|
if (_body) {
|
||||||
_lastVelocity = getBodyLinearVelocity();
|
_lastVelocity = getBodyLinearVelocityGTSigma();
|
||||||
// if _lastVelocity is too slow, set it to zero
|
|
||||||
if (glm::length2(_lastVelocity) < MIN_LINEAR_SPEED_SQUARED) {
|
|
||||||
_lastVelocity *= 0.0f;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
_lastVelocity = glm::vec3(0.0f);
|
_lastVelocity = glm::vec3(0.0f);
|
||||||
}
|
}
|
||||||
|
@ -579,10 +566,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 = getBodyLinearVelocity();
|
glm::vec3 velocity = getBodyLinearVelocityGTSigma();
|
||||||
if (glm::length2(velocity) < MIN_LINEAR_SPEED_SQUARED) {
|
|
||||||
velocity *= 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
_measuredAcceleration = (velocity / powf(1.0f - _body->getLinearDamping(), dt) - _lastVelocity) * invDt;
|
_measuredAcceleration = (velocity / powf(1.0f - _body->getLinearDamping(), dt) - _lastVelocity) * invDt;
|
||||||
_lastVelocity = velocity;
|
_lastVelocity = velocity;
|
||||||
|
|
|
@ -83,6 +83,19 @@ glm::vec3 ObjectMotionState::getBodyLinearVelocity() const {
|
||||||
return bulletToGLM(_body->getLinearVelocity());
|
return bulletToGLM(_body->getLinearVelocity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::vec3 ObjectMotionState::getBodyLinearVelocityGTSigma() const {
|
||||||
|
// 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
|
||||||
|
|
||||||
|
glm::vec3 velocity = bulletToGLM(_body->getLinearVelocity());
|
||||||
|
if (glm::length2(velocity) < MIN_LINEAR_SPEED_SQUARED) {
|
||||||
|
velocity *= 0.0f;
|
||||||
|
}
|
||||||
|
return 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.
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,7 @@ public:
|
||||||
void setBodyGravity(const glm::vec3& gravity) const;
|
void setBodyGravity(const glm::vec3& gravity) const;
|
||||||
|
|
||||||
glm::vec3 getBodyLinearVelocity() const;
|
glm::vec3 getBodyLinearVelocity() const;
|
||||||
|
glm::vec3 getBodyLinearVelocityGTSigma() const;
|
||||||
glm::vec3 getBodyAngularVelocity() const;
|
glm::vec3 getBodyAngularVelocity() const;
|
||||||
virtual glm::vec3 getObjectLinearVelocityChange() const;
|
virtual glm::vec3 getObjectLinearVelocityChange() const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue