try another way of fixing held object snagging at slow velocity

This commit is contained in:
Seth Alves 2015-10-19 09:48:34 -07:00
parent 1f3b92577d
commit 742e48b0c8
3 changed files with 20 additions and 12 deletions

View file

@ -299,9 +299,10 @@ void RenderableModelEntityItem::render(RenderArgs* args) {
bool movingOrAnimating = isMoving() || isAnimatingSomething();
if ((movingOrAnimating ||
_needsInitialSimulation ||
_model->getTranslation() != getPosition() ||
_model->getRotation() != getRotation())
_needsInitialSimulation // ||
// _model->getTranslation() != getPosition() ||
// _model->getRotation() != getRotation()
)
&& _model->isActive() && _dimensionsInitialized) {
_model->setScaleToFit(true, getDimensions());
_model->setSnapModelToRegistrationPoint(true, getRegistrationPoint());

View file

@ -9,6 +9,8 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <glm/gtx/norm.hpp>
#include <EntityItem.h>
#include <EntityItemProperties.h>
#include <EntityEditPacketSender.h>
@ -30,6 +32,11 @@ static const quint8 STEPS_TO_DECIDE_BALLISTIC = 4;
const uint32_t LOOPS_FOR_SIMULATION_ORPHAN = 50;
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
bool EntityMotionState::entityTreeIsLocked() const {
EntityTreeElementPointer element = _entity ? _entity->getElement() : nullptr;
@ -548,6 +555,10 @@ void EntityMotionState::resetMeasuredBodyAcceleration() {
_lastMeasureStep = ObjectMotionState::getWorldSimulationStep();
if (_body) {
_lastVelocity = getBodyLinearVelocity();
// if _lastVelocity is too slow, set it to zero
if (glm::length2(_lastVelocity) < MIN_LINEAR_SPEED_SQUARED) {
_lastVelocity *= 0.0f;
}
} else {
_lastVelocity = glm::vec3(0.0f);
}
@ -567,6 +578,10 @@ void EntityMotionState::measureBodyAcceleration() {
// 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
glm::vec3 velocity = getBodyLinearVelocity();
if (glm::length2(velocity) < MIN_LINEAR_SPEED_SQUARED) {
velocity *= 0.0f;
}
_measuredAcceleration = (velocity / powf(1.0f - _body->getLinearDamping(), dt) - _lastVelocity) * invDt;
_lastVelocity = velocity;
if (numSubsteps > PHYSICS_ENGINE_MAX_NUM_SUBSTEPS) {

View file

@ -80,16 +80,8 @@ void ObjectMotionState::setBodyGravity(const glm::vec3& gravity) const {
}
glm::vec3 ObjectMotionState::getBodyLinearVelocity() const {
// returns the body's velocity unless it is moving too slow in which case returns zero
// returns the body's velocity
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);
}