mirror of
https://github.com/overte-org/overte.git
synced 2025-07-26 05:37:34 +02:00
attempt to allow position edits in releaseGrab entity-method
This commit is contained in:
parent
10bb637753
commit
0846eb8ec6
6 changed files with 68 additions and 17 deletions
|
@ -5300,6 +5300,16 @@ void MyAvatar::releaseGrab(const QUuid& grabID) {
|
||||||
bool tellHandler { false };
|
bool tellHandler { false };
|
||||||
|
|
||||||
_avatarGrabsLock.withWriteLock([&] {
|
_avatarGrabsLock.withWriteLock([&] {
|
||||||
|
|
||||||
|
std::map<QUuid, GrabPointer>::iterator itr;
|
||||||
|
itr = _avatarGrabs.find(grabID);
|
||||||
|
if (itr != _avatarGrabs.end()) {
|
||||||
|
GrabPointer grab = itr->second;
|
||||||
|
if (grab) {
|
||||||
|
grab->setDeleted(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (_avatarGrabData.remove(grabID)) {
|
if (_avatarGrabData.remove(grabID)) {
|
||||||
_grabsToDelete.push_back(grabID);
|
_grabsToDelete.push_back(grabID);
|
||||||
tellHandler = true;
|
tellHandler = true;
|
||||||
|
|
|
@ -412,6 +412,9 @@ void Avatar::accumulateGrabPositions(std::map<QUuid, GrabLocationAccumulator>& g
|
||||||
if (!grab || !grab->getActionID().isNull()) {
|
if (!grab || !grab->getActionID().isNull()) {
|
||||||
continue; // the accumulated value isn't used, in this case.
|
continue; // the accumulated value isn't used, in this case.
|
||||||
}
|
}
|
||||||
|
if (grab->getDeleted()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
glm::vec3 jointTranslation = getAbsoluteJointTranslationInObjectFrame(grab->getParentJointIndex());
|
glm::vec3 jointTranslation = getAbsoluteJointTranslationInObjectFrame(grab->getParentJointIndex());
|
||||||
glm::quat jointRotation = getAbsoluteJointRotationInObjectFrame(grab->getParentJointIndex());
|
glm::quat jointRotation = getAbsoluteJointRotationInObjectFrame(grab->getParentJointIndex());
|
||||||
|
|
|
@ -114,18 +114,45 @@ void EntityMotionState::updateServerPhysicsVariables() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void EntityMotionState::handleDeactivation() {
|
||||||
|
// // copy _server data to entity
|
||||||
|
// Transform localTransform = _entity->getLocalTransform();
|
||||||
|
// // localTransform.setTranslation(_serverPosition);
|
||||||
|
// // localTransform.setRotation(_serverRotation);
|
||||||
|
// _entity->setLocalTransformAndVelocities(localTransform, ENTITY_ITEM_ZERO_VEC3, ENTITY_ITEM_ZERO_VEC3);
|
||||||
|
// // and also to RigidBody
|
||||||
|
// btTransform worldTrans;
|
||||||
|
// worldTrans.setOrigin(glmToBullet(_entity->getWorldPosition()));
|
||||||
|
// worldTrans.setRotation(glmToBullet(_entity->getWorldOrientation()));
|
||||||
|
// _body->setWorldTransform(worldTrans);
|
||||||
|
// // no need to update velocities... should already be zero
|
||||||
|
// }
|
||||||
|
|
||||||
void EntityMotionState::handleDeactivation() {
|
void EntityMotionState::handleDeactivation() {
|
||||||
// copy _server data to entity
|
if (_entity->getDirtyFlags() & (Simulation::DIRTY_TRANSFORM | Simulation::DIRTY_VELOCITIES)) {
|
||||||
Transform localTransform = _entity->getLocalTransform();
|
// Some non-physical event (script-call or network-packet) has modified the entity's transform and/or velocities
|
||||||
localTransform.setTranslation(_serverPosition);
|
// at the last minute before deactivation --> the values stored in _server* and _body are stale.
|
||||||
localTransform.setRotation(_serverRotation);
|
// We assume the EntityMotionState is the last to know, so we copy from EntityItem and let things sort themselves out.
|
||||||
_entity->setLocalTransformAndVelocities(localTransform, ENTITY_ITEM_ZERO_VEC3, ENTITY_ITEM_ZERO_VEC3);
|
Transform localTransform;
|
||||||
// and also to RigidBody
|
_entity->getLocalTransformAndVelocities(localTransform, _serverVelocity, _serverAngularVelocity);
|
||||||
btTransform worldTrans;
|
_serverPosition = localTransform.getTranslation();
|
||||||
worldTrans.setOrigin(glmToBullet(_entity->getWorldPosition()));
|
_serverRotation = localTransform.getRotation();
|
||||||
worldTrans.setRotation(glmToBullet(_entity->getWorldOrientation()));
|
_serverAcceleration = _entity->getAcceleration();
|
||||||
_body->setWorldTransform(worldTrans);
|
_serverActionData = _entity->getDynamicData();
|
||||||
// no need to update velocities... should already be zero
|
_lastStep = ObjectMotionState::getWorldSimulationStep();
|
||||||
|
} else {
|
||||||
|
// copy _server data to entity
|
||||||
|
Transform localTransform = _entity->getLocalTransform();
|
||||||
|
localTransform.setTranslation(_serverPosition);
|
||||||
|
localTransform.setRotation(_serverRotation);
|
||||||
|
_entity->setLocalTransformAndVelocities(localTransform, ENTITY_ITEM_ZERO_VEC3, ENTITY_ITEM_ZERO_VEC3);
|
||||||
|
// and also to RigidBody
|
||||||
|
btTransform worldTrans;
|
||||||
|
worldTrans.setOrigin(glmToBullet(_entity->getWorldPosition()));
|
||||||
|
worldTrans.setRotation(glmToBullet(_entity->getWorldOrientation()));
|
||||||
|
_body->setWorldTransform(worldTrans);
|
||||||
|
// no need to update velocities... should already be zero
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// virtual
|
// virtual
|
||||||
|
|
|
@ -26,16 +26,16 @@ public:
|
||||||
void accumulate(glm::vec3 position, glm::quat orientation) {
|
void accumulate(glm::vec3 position, glm::quat orientation) {
|
||||||
_position += position;
|
_position += position;
|
||||||
_orientation = orientation; // XXX
|
_orientation = orientation; // XXX
|
||||||
count++;
|
_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 finalizePosition() { return count > 0 ? _position * (1.0f / count) : glm::vec3(0.0f); }
|
glm::vec3 finalizePosition() { return _count > 0 ? _position * (1.0f / _count) : glm::vec3(0.0f); }
|
||||||
glm::quat finalizeOrientation() { return _orientation; } // XXX
|
glm::quat finalizeOrientation() { return _orientation; } // XXX
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
glm::vec3 _position;
|
glm::vec3 _position;
|
||||||
glm::quat _orientation;
|
glm::quat _orientation;
|
||||||
int count { 0 };
|
int _count { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
class Grab {
|
class Grab {
|
||||||
|
@ -48,7 +48,8 @@ public:
|
||||||
_parentJointIndex(newParentJointIndex),
|
_parentJointIndex(newParentJointIndex),
|
||||||
_hand(newHand),
|
_hand(newHand),
|
||||||
_positionalOffset(newPositionalOffset),
|
_positionalOffset(newPositionalOffset),
|
||||||
_rotationalOffset(newRotationalOffset) {}
|
_rotationalOffset(newRotationalOffset),
|
||||||
|
_deleted(false) {}
|
||||||
|
|
||||||
QByteArray toByteArray();
|
QByteArray toByteArray();
|
||||||
bool fromByteArray(const QByteArray& grabData);
|
bool fromByteArray(const QByteArray& grabData);
|
||||||
|
@ -61,6 +62,7 @@ public:
|
||||||
_positionalOffset = other->_positionalOffset;
|
_positionalOffset = other->_positionalOffset;
|
||||||
_rotationalOffset = other->_rotationalOffset;
|
_rotationalOffset = other->_rotationalOffset;
|
||||||
_actionID = other->_actionID;
|
_actionID = other->_actionID;
|
||||||
|
_deleted = other->_deleted;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +87,9 @@ public:
|
||||||
glm::quat getRotationalOffset() const { return _rotationalOffset; }
|
glm::quat getRotationalOffset() const { return _rotationalOffset; }
|
||||||
void setRotationalOffset(glm::quat rotationalOffset) { _rotationalOffset = rotationalOffset; }
|
void setRotationalOffset(glm::quat rotationalOffset) { _rotationalOffset = rotationalOffset; }
|
||||||
|
|
||||||
|
bool getDeleted() const { return _deleted; }
|
||||||
|
void setDeleted(bool value) { _deleted = value; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QUuid _actionID; // if an action is created in bullet for this grab, this is the ID
|
QUuid _actionID; // if an action is created in bullet for this grab, this is the ID
|
||||||
QUuid _ownerID; // avatar ID of grabber
|
QUuid _ownerID; // avatar ID of grabber
|
||||||
|
@ -93,6 +98,7 @@ protected:
|
||||||
QString _hand; // "left" or "right"
|
QString _hand; // "left" or "right"
|
||||||
glm::vec3 _positionalOffset; // relative to joint
|
glm::vec3 _positionalOffset; // relative to joint
|
||||||
glm::quat _rotationalOffset; // relative to joint
|
glm::quat _rotationalOffset; // relative to joint
|
||||||
|
bool _deleted { false }; // scheduled for deletion
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1390,7 +1390,12 @@ void SpatiallyNestable::removeGrab(GrabPointer grab) {
|
||||||
bool SpatiallyNestable::hasGrabs() {
|
bool SpatiallyNestable::hasGrabs() {
|
||||||
bool result { false };
|
bool result { false };
|
||||||
_grabsLock.withReadLock([&] {
|
_grabsLock.withReadLock([&] {
|
||||||
result = !_grabs.isEmpty();
|
foreach (const GrabPointer &grab, _grabs) {
|
||||||
|
if (grab && !grab->getDeleted()) {
|
||||||
|
result = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -241,7 +241,7 @@ protected:
|
||||||
quint64 _rotationChanged { 0 };
|
quint64 _rotationChanged { 0 };
|
||||||
|
|
||||||
mutable ReadWriteLockable _grabsLock;
|
mutable ReadWriteLockable _grabsLock;
|
||||||
QSet<GrabPointer> _grabs;
|
QSet<GrabPointer> _grabs; // upon this thing
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SpatiallyNestable() = delete;
|
SpatiallyNestable() = delete;
|
||||||
|
|
Loading…
Reference in a new issue