mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-09 01:22:21 +02:00
avoid loop where bullet moves an entity and then an entity tells bullet that it has moved.
This commit is contained in:
parent
b87e8220c4
commit
43f735dd21
10 changed files with 31 additions and 21 deletions
|
@ -92,7 +92,7 @@ private:
|
|||
public: \
|
||||
virtual bool addToScene(EntityItemPointer self, std::shared_ptr<render::Scene> scene, render::PendingChanges& pendingChanges) override { return _renderHelper.addToScene(self, scene, pendingChanges); } \
|
||||
virtual void removeFromScene(EntityItemPointer self, std::shared_ptr<render::Scene> scene, render::PendingChanges& pendingChanges) override { _renderHelper.removeFromScene(self, scene, pendingChanges); } \
|
||||
virtual void locationChanged() override { EntityItem::locationChanged(); _renderHelper.notifyChanged(); } \
|
||||
virtual void locationChanged(bool tellPhysics = true) override { EntityItem::locationChanged(tellPhysics); _renderHelper.notifyChanged(); } \
|
||||
virtual void dimensionsChanged() override { EntityItem::dimensionsChanged(); _renderHelper.notifyChanged(); } \
|
||||
private: \
|
||||
SimpleRenderableEntityItem _renderHelper;
|
||||
|
|
|
@ -798,8 +798,8 @@ void RenderableModelEntityItem::setJointTranslationsSet(const QVector<bool>& tra
|
|||
}
|
||||
|
||||
|
||||
void RenderableModelEntityItem::locationChanged() {
|
||||
EntityItem::locationChanged();
|
||||
void RenderableModelEntityItem::locationChanged(bool tellPhysics) {
|
||||
EntityItem::locationChanged(tellPhysics);
|
||||
if (_model && _model->isActive()) {
|
||||
_model->setRotation(getRotation());
|
||||
_model->setTranslation(getPosition());
|
||||
|
|
|
@ -75,7 +75,7 @@ public:
|
|||
virtual void setJointTranslationsSet(const QVector<bool>& translationsSet) override;
|
||||
|
||||
virtual void loader() override;
|
||||
virtual void locationChanged() override;
|
||||
virtual void locationChanged(bool tellPhysics = true) override;
|
||||
|
||||
virtual void resizeJointArrays(int newSize = -1) override;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
virtual void removeFromScene(EntityItemPointer self, render::ScenePointer scene, render::PendingChanges& pendingChanges) override;
|
||||
|
||||
protected:
|
||||
virtual void locationChanged() override { EntityItem::locationChanged(); notifyBoundChanged(); }
|
||||
virtual void locationChanged(bool tellPhysics = true) override { EntityItem::locationChanged(tellPhysics); notifyBoundChanged(); }
|
||||
virtual void dimensionsChanged() override { EntityItem::dimensionsChanged(); notifyBoundChanged(); }
|
||||
|
||||
void notifyBoundChanged();
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
virtual void removeFromScene(EntityItemPointer self, std::shared_ptr<render::Scene> scene, render::PendingChanges& pendingChanges);
|
||||
|
||||
private:
|
||||
virtual void locationChanged() override { EntityItem::locationChanged(); notifyBoundChanged(); }
|
||||
virtual void locationChanged(bool tellPhysics = true) override { EntityItem::locationChanged(tellPhysics); notifyBoundChanged(); }
|
||||
virtual void dimensionsChanged() override { EntityItem::dimensionsChanged(); notifyBoundChanged(); }
|
||||
void notifyBoundChanged();
|
||||
|
||||
|
|
|
@ -1976,14 +1976,16 @@ QList<EntityActionPointer> EntityItem::getActionsOfType(EntityActionType typeToG
|
|||
return result;
|
||||
}
|
||||
|
||||
void EntityItem::locationChanged() {
|
||||
void EntityItem::locationChanged(bool tellPhysics) {
|
||||
requiresRecalcBoxes();
|
||||
_dirtyFlags |= Simulation::DIRTY_TRANSFORM;
|
||||
if (tellPhysics) {
|
||||
_dirtyFlags |= Simulation::DIRTY_TRANSFORM;
|
||||
}
|
||||
EntityTreePointer tree = getTree();
|
||||
if (tree) {
|
||||
tree->entityChanged(getThisPointer());
|
||||
}
|
||||
SpatiallyNestable::locationChanged(); // tell all the children, also
|
||||
SpatiallyNestable::locationChanged(tellPhysics); // tell all the children, also
|
||||
}
|
||||
|
||||
void EntityItem::dimensionsChanged() {
|
||||
|
|
|
@ -432,7 +432,7 @@ protected:
|
|||
const QByteArray getActionDataInternal() const;
|
||||
void setActionDataInternal(QByteArray actionData);
|
||||
|
||||
virtual void locationChanged() override;
|
||||
virtual void locationChanged(bool tellPhysics = true) override;
|
||||
virtual void dimensionsChanged() override;
|
||||
|
||||
EntityTypes::EntityType _type;
|
||||
|
|
|
@ -207,8 +207,16 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) {
|
|||
|
||||
assert(entityTreeIsLocked());
|
||||
measureBodyAcceleration();
|
||||
_entity->setPosition(bulletToGLM(worldTrans.getOrigin()) + ObjectMotionState::getWorldOffset());
|
||||
_entity->setRotation(bulletToGLM(worldTrans.getRotation()));
|
||||
bool positionSuccess;
|
||||
_entity->setPosition(bulletToGLM(worldTrans.getOrigin()) + ObjectMotionState::getWorldOffset(), positionSuccess, false);
|
||||
if (!positionSuccess) {
|
||||
qDebug() << "EntityMotionState::setWorldTransform setPosition failed" << _entity->getID();
|
||||
}
|
||||
bool orientationSuccess;
|
||||
_entity->setOrientation(bulletToGLM(worldTrans.getRotation()), orientationSuccess, false);
|
||||
if (!orientationSuccess) {
|
||||
qDebug() << "EntityMotionState::setWorldTransform setOrientation failed" << _entity->getID();
|
||||
}
|
||||
_entity->setVelocity(getBodyLinearVelocity());
|
||||
_entity->setAngularVelocity(getBodyAngularVelocity());
|
||||
_entity->setLastSimulated(usecTimestampNow());
|
||||
|
|
|
@ -314,7 +314,7 @@ glm::vec3 SpatiallyNestable::getPosition(int jointIndex, bool& success) const {
|
|||
return getTransform(jointIndex, success).getTranslation();
|
||||
}
|
||||
|
||||
void SpatiallyNestable::setPosition(const glm::vec3& position, bool& success) {
|
||||
void SpatiallyNestable::setPosition(const glm::vec3& position, bool& success, bool tellPhysics) {
|
||||
// guard against introducing NaN into the transform
|
||||
if (isNaN(position)) {
|
||||
success = false;
|
||||
|
@ -328,7 +328,7 @@ void SpatiallyNestable::setPosition(const glm::vec3& position, bool& success) {
|
|||
Transform::inverseMult(_transform, parentTransform, myWorldTransform);
|
||||
});
|
||||
if (success) {
|
||||
locationChanged();
|
||||
locationChanged(tellPhysics);
|
||||
} else {
|
||||
qDebug() << "setPosition failed for" << getID();
|
||||
}
|
||||
|
@ -363,7 +363,7 @@ glm::quat SpatiallyNestable::getOrientation(int jointIndex, bool& success) const
|
|||
return getTransform(jointIndex, success).getRotation();
|
||||
}
|
||||
|
||||
void SpatiallyNestable::setOrientation(const glm::quat& orientation, bool& success) {
|
||||
void SpatiallyNestable::setOrientation(const glm::quat& orientation, bool& success, bool tellPhysics) {
|
||||
// guard against introducing NaN into the transform
|
||||
if (isNaN(orientation)) {
|
||||
success = false;
|
||||
|
@ -378,7 +378,7 @@ void SpatiallyNestable::setOrientation(const glm::quat& orientation, bool& succe
|
|||
Transform::inverseMult(_transform, parentTransform, myWorldTransform);
|
||||
});
|
||||
if (success) {
|
||||
locationChanged();
|
||||
locationChanged(tellPhysics);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -751,9 +751,9 @@ void SpatiallyNestable::forEachDescendant(std::function<void(SpatiallyNestablePo
|
|||
}
|
||||
}
|
||||
|
||||
void SpatiallyNestable::locationChanged() {
|
||||
void SpatiallyNestable::locationChanged(bool tellPhysics) {
|
||||
forEachChild([&](SpatiallyNestablePointer object) {
|
||||
object->locationChanged();
|
||||
object->locationChanged(tellPhysics);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -59,13 +59,13 @@ public:
|
|||
|
||||
virtual glm::vec3 getPosition(bool& success) const;
|
||||
virtual glm::vec3 getPosition() const;
|
||||
virtual void setPosition(const glm::vec3& position, bool& success);
|
||||
virtual void setPosition(const glm::vec3& position, bool& success, bool tellPhysics = true);
|
||||
virtual void setPosition(const glm::vec3& position);
|
||||
|
||||
virtual glm::quat getOrientation(bool& success) const;
|
||||
virtual glm::quat getOrientation() const;
|
||||
virtual glm::quat getOrientation(int jointIndex, bool& success) const;
|
||||
virtual void setOrientation(const glm::quat& orientation, bool& success);
|
||||
virtual void setOrientation(const glm::quat& orientation, bool& success, bool tellPhysics = true);
|
||||
virtual void setOrientation(const glm::quat& orientation);
|
||||
|
||||
virtual glm::vec3 getVelocity(bool& success) const;
|
||||
|
@ -159,7 +159,7 @@ protected:
|
|||
mutable ReadWriteLockable _childrenLock;
|
||||
mutable QHash<QUuid, SpatiallyNestableWeakPointer> _children;
|
||||
|
||||
virtual void locationChanged(); // called when a this object's location has changed
|
||||
virtual void locationChanged(bool tellPhysics = true); // called when a this object's location has changed
|
||||
virtual void dimensionsChanged() { } // called when a this object's dimensions have changed
|
||||
|
||||
// _queryAACube is used to decide where something lives in the octree
|
||||
|
|
Loading…
Reference in a new issue