Merge pull request #11282 from sethalves/fix-winking-dynamic-children-1

fix a bug that caused dynamic children to wink in and out and then vanish
This commit is contained in:
Andrew Meadows 2017-09-05 10:02:47 -07:00 committed by GitHub
commit 4b8840f307
4 changed files with 18 additions and 14 deletions

View file

@ -92,6 +92,7 @@ void EntityMotionState::updateServerPhysicsVariables() {
Transform localTransform; Transform localTransform;
_entity->getLocalTransformAndVelocities(localTransform, _serverVelocity, _serverAngularVelocity); _entity->getLocalTransformAndVelocities(localTransform, _serverVelocity, _serverAngularVelocity);
_serverVariablesSet = true;
_serverPosition = localTransform.getTranslation(); _serverPosition = localTransform.getTranslation();
_serverRotation = localTransform.getRotation(); _serverRotation = localTransform.getRotation();
_serverAcceleration = _entity->getAcceleration(); _serverAcceleration = _entity->getAcceleration();
@ -99,19 +100,20 @@ void EntityMotionState::updateServerPhysicsVariables() {
} }
void EntityMotionState::handleDeactivation() { void EntityMotionState::handleDeactivation() {
if (_serverVariablesSet) {
// copy _server data to entity // copy _server data to entity
bool success; Transform localTransform = _entity->getLocalTransform();
_entity->setPosition(_serverPosition, success, false); localTransform.setTranslation(_serverPosition);
_entity->setOrientation(_serverRotation, success, false); localTransform.setRotation(_serverRotation);
_entity->setVelocity(ENTITY_ITEM_ZERO_VEC3); _entity->setLocalTransformAndVelocities(localTransform, ENTITY_ITEM_ZERO_VEC3, ENTITY_ITEM_ZERO_VEC3);
_entity->setAngularVelocity(ENTITY_ITEM_ZERO_VEC3);
// and also to RigidBody // and also to RigidBody
btTransform worldTrans; btTransform worldTrans;
worldTrans.setOrigin(glmToBullet(_serverPosition)); worldTrans.setOrigin(glmToBullet(_entity->getPosition()));
worldTrans.setRotation(glmToBullet(_serverRotation)); worldTrans.setRotation(glmToBullet(_entity->getRotation()));
_body->setWorldTransform(worldTrans); _body->setWorldTransform(worldTrans);
// no need to update velocities... should already be zero // no need to update velocities... should already be zero
} }
}
// virtual // virtual
void EntityMotionState::handleEasyChanges(uint32_t& flags) { void EntityMotionState::handleEasyChanges(uint32_t& flags) {
@ -339,6 +341,7 @@ bool EntityMotionState::remoteSimulationOutOfSync(uint32_t simulationStep) {
// if we've never checked before, our _lastStep will be 0, and we need to initialize our state // if we've never checked before, our _lastStep will be 0, and we need to initialize our state
if (_lastStep == 0) { if (_lastStep == 0) {
btTransform xform = _body->getWorldTransform(); btTransform xform = _body->getWorldTransform();
_serverVariablesSet = true;
_serverPosition = worldToLocal.transform(bulletToGLM(xform.getOrigin())); _serverPosition = worldToLocal.transform(bulletToGLM(xform.getOrigin()));
_serverRotation = worldToLocal.getRotation() * bulletToGLM(xform.getRotation()); _serverRotation = worldToLocal.getRotation() * bulletToGLM(xform.getRotation());
_serverVelocity = worldVelocityToLocal.transform(getBodyLinearVelocityGTSigma()); _serverVelocity = worldVelocityToLocal.transform(getBodyLinearVelocityGTSigma());

View file

@ -107,6 +107,7 @@ protected:
// Meanwhile we also keep a raw EntityItem* for internal stuff where the pointer is guaranteed valid. // Meanwhile we also keep a raw EntityItem* for internal stuff where the pointer is guaranteed valid.
EntityItem* _entity; EntityItem* _entity;
bool _serverVariablesSet { false };
glm::vec3 _serverPosition; // in simulation-frame (not world-frame) glm::vec3 _serverPosition; // in simulation-frame (not world-frame)
glm::quat _serverRotation; glm::quat _serverRotation;
glm::vec3 _serverVelocity; glm::vec3 _serverVelocity;

View file

@ -731,7 +731,7 @@ void SpatiallyNestable::setScale(float value) {
} }
} }
const Transform SpatiallyNestable::getLocalTransform() const { Transform SpatiallyNestable::getLocalTransform() const {
Transform result; Transform result;
_transformLock.withReadLock([&] { _transformLock.withReadLock([&] {
result =_transform; result =_transform;

View file

@ -121,7 +121,7 @@ public:
virtual glm::vec3 getScale(int jointIndex) const; virtual glm::vec3 getScale(int jointIndex) const;
// object's parent's frame // object's parent's frame
virtual const Transform getLocalTransform() const; virtual Transform getLocalTransform() const;
virtual void setLocalTransform(const Transform& transform); virtual void setLocalTransform(const Transform& transform);
virtual glm::vec3 getLocalPosition() const; virtual glm::vec3 getLocalPosition() const;