if measured acceleration is close to zero, send zero to entity server, else send gravity

This commit is contained in:
Seth Alves 2015-04-17 15:05:47 -07:00
parent 292ba20cf3
commit dac57c44da
6 changed files with 28 additions and 30 deletions

View file

@ -38,10 +38,10 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemI
//// XXX
auto nodeList = DependencyManager::get<NodeList>();
QUuid myNodeID = nodeList->getSessionUUID();
QString x = properties.getSimulatorID() == myNodeID ? "me" : properties.getSimulatorID().toString();
qDebug() << "sending update:" << properties.simulatorIDChanged() << x;
// auto nodeList = DependencyManager::get<NodeList>();
// QUuid myNodeID = nodeList->getSessionUUID();
// QString x = properties.getSimulatorID() == myNodeID ? "me" : properties.getSimulatorID().toString();
// qDebug() << "sending update:" << properties.simulatorIDChanged() << x;
//// XXX

View file

@ -699,6 +699,7 @@ void EntityItem::simulate(const quint64& now) {
qCDebug(entities) << " MOVING...=";
qCDebug(entities) << " hasVelocity=" << hasVelocity();
qCDebug(entities) << " hasGravity=" << hasGravity();
qCDebug(entities) << " hasAcceleration=" << hasAcceleration();
qCDebug(entities) << " hasAngularVelocity=" << hasAngularVelocity();
qCDebug(entities) << " getAngularVelocity=" << getAngularVelocity();
}
@ -788,13 +789,7 @@ void EntityItem::simulateKinematicMotion(float timeElapsed) {
position = newPosition;
// apply gravity
if (hasGravity()) {
// handle resting on surface case, this is definitely a bit of a hack, and it only works on the
// "ground" plane of the domain, but for now it's what we've got
velocity += getGravity() * timeElapsed;
}
// apply effective acceleration, which will be the same as gravity if the Entity isn't at rest.
if (hasAcceleration()) {
velocity += getAcceleration() * timeElapsed;
}
@ -1151,14 +1146,8 @@ void EntityItem::updateGravity(const glm::vec3& value) {
}
void EntityItem::updateAcceleration(const glm::vec3& value) {
if (glm::distance(_acceleration, value) > MIN_ACCELERATION_DELTA) {
if (glm::length(value) < MIN_ACCELERATION_DELTA) {
_acceleration = ENTITY_ITEM_ZERO_VEC3;
} else {
_acceleration = value;
}
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
}
_acceleration = value;
_dirtyFlags |= EntityItem::DIRTY_VELOCITY;
}
void EntityItem::updateAngularVelocity(const glm::vec3& value) {

View file

@ -195,8 +195,8 @@ public:
void setGravity(const glm::vec3& value) { _gravity = value; } /// gravity in meters
bool hasGravity() const { return _gravity != ENTITY_ITEM_ZERO_VEC3; }
const glm::vec3 getAcceleration() const { return _acceleration; } /// get acceleration in meters/second
void setAcceleration(const glm::vec3& value) { _acceleration = value; } /// acceleration in meters/second
const glm::vec3 getAcceleration() const { return _acceleration; } /// get acceleration in meters/second/second
void setAcceleration(const glm::vec3& value) { _acceleration = value; } /// acceleration in meters/second/second
bool hasAcceleration() const { return _acceleration != ENTITY_ITEM_ZERO_VEC3; }
float getDamping() const { return _damping; }

View file

@ -18,6 +18,7 @@
#include "PhysicsHelpers.h"
#include "PhysicsLogging.h"
static const float MEASURED_ACCELERATION_CLOSE_TO_ZERO = 0.05;
QSet<EntityItem*>* _outgoingEntityList;
@ -166,8 +167,8 @@ void EntityMotionState::updateObjectVelocities() {
_sentAngularVelocity = _entity->getAngularVelocity();
setAngularVelocity(_sentAngularVelocity);
_sentAcceleration = _entity->getGravity();
setGravity(_sentAcceleration);
_sentGravity = _entity->getGravity();
setGravity(_sentGravity);
_body->setActivationState(ACTIVE_TAG);
}
@ -191,8 +192,8 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationFrame) {
}
auto nodeList = DependencyManager::get<NodeList>();
QUuid myNodeID = nodeList->getSessionUUID();
QUuid simulatorID = _entity->getSimulatorID();
const QUuid& myNodeID = nodeList->getSessionUUID();
const QUuid& simulatorID = _entity->getSimulatorID();
if (!simulatorID.isNull() && simulatorID != myNodeID) {
// some other Node owns the simulating of this, so don't broadcast the results of local simulation.
@ -203,13 +204,18 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationFrame) {
}
void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_t step) {
if (!_entity->isKnownID()) {
return; // never update entities that are unknown
}
if (_outgoingPacketFlags) {
EntityItemProperties properties = _entity->getProperties();
if (glm::length(_measuredAcceleration) < MEASURED_ACCELERATION_CLOSE_TO_ZERO) {
_entity->setAcceleration(glm::vec3(0));
} else {
_entity->setAcceleration(_entity->getGravity());
}
if (_outgoingPacketFlags & EntityItem::DIRTY_POSITION) {
btTransform worldTrans = _body->getWorldTransform();
_sentPosition = bulletToGLM(worldTrans.getOrigin());
@ -245,12 +251,13 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
_sentMoving = false;
}
properties.setVelocity(_sentVelocity);
_sentAcceleration = bulletToGLM(_body->getGravity());
properties.setGravity(_sentAcceleration);
_sentGravity = _entity->getGravity();
properties.setGravity(_entity->getGravity());
_sentAcceleration = _entity->getAcceleration();
properties.setAcceleration(_sentAcceleration);
properties.setAngularVelocity(_sentAngularVelocity);
}
auto nodeList = DependencyManager::get<NodeList>();
QUuid myNodeID = nodeList->getSessionUUID();
QUuid simulatorID = _entity->getSimulatorID();

View file

@ -57,6 +57,7 @@ ObjectMotionState::ObjectMotionState() :
_sentRotation(),
_sentVelocity(0.0f),
_sentAngularVelocity(0.0f),
_sentGravity(0.0f),
_sentAcceleration(0.0f),
_lastSimulationStep(0),
_lastVelocity(0.0f),
@ -174,7 +175,7 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationStep) {
// Else we measure the error between current and extrapolated transform (according to expected behavior
// of remote EntitySimulation) and return true if the error is significant.
// NOTE: math in done the simulation-frame, which is NOT necessarily the same as the world-frame
// NOTE: math is done the simulation-frame, which is NOT necessarily the same as the world-frame
// due to _worldOffset.
// compute position error

View file

@ -138,6 +138,7 @@ protected:
glm::quat _sentRotation;;
glm::vec3 _sentVelocity;
glm::vec3 _sentAngularVelocity; // radians per second
glm::vec3 _sentGravity;
glm::vec3 _sentAcceleration;
uint32_t _lastSimulationStep;