diff --git a/interface/src/octree/OctreePacketProcessor.cpp b/interface/src/octree/OctreePacketProcessor.cpp index f87e978b66..92eb7f7f31 100644 --- a/interface/src/octree/OctreePacketProcessor.cpp +++ b/interface/src/octree/OctreePacketProcessor.cpp @@ -61,7 +61,7 @@ void OctreePacketProcessor::processPacket(const SharedNodePointer& sendingNode, // check version of piggyback packet against expected version if (packetVersion != expectedVersion // TODO: remove the temporary exception below when everyone is using meters instead of DomainUnits - && !(PacketTypeEntityData == voxelPacketType && packetVersion < VERSION_ENTITIES_USE_METERS)) { + && !(PacketTypeEntityData == voxelPacketType && packetVersion < VERSION_ENTITIES_USE_METERS_AND_RADIANS)) { static QMultiMap versionDebugSuppressMap; QUuid senderUUID = uuidFromPacketHeader(packet); diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 5a1712a1f6..093f8cf84c 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -501,7 +501,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef EntityPropertyFlags propertyFlags = encodedPropertyFlags; dataAt += propertyFlags.getEncodedLength(); bytesRead += propertyFlags.getEncodedLength(); - bool useMeters = (args.bitstreamVersion == VERSION_ENTITIES_USE_METERS); + bool useMeters = (args.bitstreamVersion == VERSION_ENTITIES_USE_METERS_AND_RADIANS); if (useMeters) { READ_ENTITY_PROPERTY_SETTER(PROP_POSITION, glm::vec3, updatePosition); } else { @@ -540,7 +540,11 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef READ_ENTITY_PROPERTY_SETTER(PROP_LIFETIME, float, updateLifetime); READ_ENTITY_PROPERTY_STRING(PROP_SCRIPT, setScript); READ_ENTITY_PROPERTY(PROP_REGISTRATION_POINT, glm::vec3, _registrationPoint); - READ_ENTITY_PROPERTY_SETTER(PROP_ANGULAR_VELOCITY, glm::vec3, updateAngularVelocity); + if (useMeters) { + READ_ENTITY_PROPERTY_SETTER(PROP_ANGULAR_VELOCITY, glm::vec3, updateAngularVelocity); + } else { + READ_ENTITY_PROPERTY_SETTER(PROP_ANGULAR_VELOCITY, glm::vec3, updateAngularVelocityInDegrees); + } READ_ENTITY_PROPERTY(PROP_ANGULAR_DAMPING, float, _angularDamping); READ_ENTITY_PROPERTY(PROP_VISIBLE, bool, _visible); READ_ENTITY_PROPERTY_SETTER(PROP_IGNORE_FOR_COLLISIONS, bool, updateIgnoreForCollisions); @@ -683,41 +687,36 @@ void EntityItem::simulate(const quint64& now) { void EntityItem::simulateKinematicMotion(float timeElapsed) { if (hasAngularVelocity()) { // angular damping - glm::vec3 angularVelocity = getAngularVelocity(); if (_angularDamping > 0.0f) { - angularVelocity *= powf(1.0f - _angularDamping, timeElapsed); + _angularVelocity *= powf(1.0f - _angularDamping, timeElapsed); #ifdef WANT_DEBUG qDebug() << " angularDamping :" << _angularDamping; - qDebug() << " newAngularVelocity:" << angularVelocity; + qDebug() << " newAngularVelocity:" << _angularVelocity; #endif - setAngularVelocity(angularVelocity); } float angularSpeed = glm::length(_angularVelocity); - const float EPSILON_ANGULAR_VELOCITY_LENGTH = 0.1f; // + const float EPSILON_ANGULAR_VELOCITY_LENGTH = 0.0017453f; // 0.0017453 rad/sec = 0.1f degrees/sec if (angularSpeed < EPSILON_ANGULAR_VELOCITY_LENGTH) { if (angularSpeed > 0.0f) { _dirtyFlags |= EntityItem::DIRTY_MOTION_TYPE; } - setAngularVelocity(ENTITY_ITEM_ZERO_VEC3); + _angularVelocity = ENTITY_ITEM_ZERO_VEC3; } else { - // NOTE: angularSpeed is currently in degrees/sec!!! - // TODO: Andrew to convert to radians/sec - glm::vec3 angularVelocity = glm::radians(_angularVelocity); // for improved agreement with the way Bullet integrates rotations we use an approximation // and break the integration into bullet-sized substeps glm::quat rotation = getRotation(); float dt = timeElapsed; while (dt > PHYSICS_ENGINE_FIXED_SUBSTEP) { - glm::quat dQ = computeBulletRotationStep(angularVelocity, PHYSICS_ENGINE_FIXED_SUBSTEP); + glm::quat dQ = computeBulletRotationStep(_angularVelocity, PHYSICS_ENGINE_FIXED_SUBSTEP); rotation = glm::normalize(dQ * rotation); dt -= PHYSICS_ENGINE_FIXED_SUBSTEP; } // NOTE: this final partial substep can drift away from a real Bullet simulation however // it only becomes significant for rapidly rotating objects // (e.g. around PI/4 radians per substep, or 7.5 rotations/sec at 60 substeps/sec). - glm::quat dQ = computeBulletRotationStep(angularVelocity, dt); + glm::quat dQ = computeBulletRotationStep(_angularVelocity, dt); rotation = glm::normalize(dQ * rotation); setRotation(rotation); diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 0f8139eea5..5193aa4490 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -275,6 +275,7 @@ public: void updateGravityInDomainUnits(const glm::vec3& value); void updateGravity(const glm::vec3& value); void updateAngularVelocity(const glm::vec3& value); + void updateAngularVelocityInDegrees(const glm::vec3& value) { updateAngularVelocity(glm::radians(value)); } void updateAngularDamping(float value); void updateIgnoreForCollisions(bool value); void updateCollisionsWillMove(bool value); diff --git a/libraries/networking/src/PacketHeaders.cpp b/libraries/networking/src/PacketHeaders.cpp index 6150ba5a9e..c7f1f4ec88 100644 --- a/libraries/networking/src/PacketHeaders.cpp +++ b/libraries/networking/src/PacketHeaders.cpp @@ -74,7 +74,7 @@ PacketVersion versionForPacketType(PacketType type) { return 1; case PacketTypeEntityAddOrEdit: case PacketTypeEntityData: - return VERSION_ENTITIES_USE_METERS; + return VERSION_ENTITIES_USE_METERS_AND_RADIANS; case PacketTypeEntityErase: return 2; case PacketTypeAudioStreamStats: diff --git a/libraries/networking/src/PacketHeaders.h b/libraries/networking/src/PacketHeaders.h index dd0e166ea8..731be118af 100644 --- a/libraries/networking/src/PacketHeaders.h +++ b/libraries/networking/src/PacketHeaders.h @@ -129,7 +129,7 @@ const PacketVersion VERSION_ENTITIES_HAVE_USER_DATA = 6; const PacketVersion VERSION_ENTITIES_HAS_LAST_SIMULATED_TIME = 7; const PacketVersion VERSION_MODEL_ENTITIES_SUPPORT_SHAPE_TYPE = 8; const PacketVersion VERSION_ENTITIES_LIGHT_HAS_INTENSITY_AND_COLOR_PROPERTIES = 9; -const PacketVersion VERSION_ENTITIES_USE_METERS = 10; +const PacketVersion VERSION_ENTITIES_USE_METERS_AND_RADIANS = 10; const PacketVersion VERSION_OCTREE_HAS_FILE_BREAKS = 1; #endif // hifi_PacketHeaders_h diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index c35ace6b11..cd0769255b 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -99,8 +99,7 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) { _entity->setVelocity(v); getAngularVelocity(v); - // DANGER! EntityItem stores angularVelocity in degrees/sec!!! - _entity->setAngularVelocity(glm::degrees(v)); + _entity->setAngularVelocity(v); _entity->setLastSimulated(usecTimestampNow()); @@ -159,8 +158,7 @@ void EntityMotionState::updateObjectVelocities() { _sentVelocity = _entity->getVelocity(); setVelocity(_sentVelocity); - // DANGER! EntityItem stores angularVelocity in degrees/sec!!! - _sentAngularVelocity = glm::radians(_entity->getAngularVelocity()); + _sentAngularVelocity = _entity->getAngularVelocity(); setAngularVelocity(_sentAngularVelocity); _sentAcceleration = _entity->getGravity(); @@ -219,8 +217,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_ properties.setVelocity(_sentVelocity); _sentAcceleration = bulletToGLM(_body->getGravity()); properties.setGravity(_sentAcceleration); - // DANGER! EntityItem stores angularVelocity in degrees/sec!!! - properties.setAngularVelocity(glm::degrees(_sentAngularVelocity)); + properties.setAngularVelocity(_sentAngularVelocity); } // RELIABLE_SEND_HACK: count number of updates for entities at rest so we can stop sending them after some limit.