mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 04:03:35 +02:00
Merge pull request #7181 from sethalves/fix-grab-action
fix avatarActionHold
This commit is contained in:
commit
cfdaf643a1
2 changed files with 30 additions and 9 deletions
|
@ -93,7 +93,7 @@ void AvatarActionHold::prepareForPhysicsSimulation() {
|
||||||
activateBody(true);
|
activateBody(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Avatar> AvatarActionHold::getTarget(glm::quat& rotation, glm::vec3& position,
|
std::shared_ptr<Avatar> AvatarActionHold::getTarget(float deltaTimeStep, glm::quat& rotation, glm::vec3& position,
|
||||||
glm::vec3& linearVelocity, glm::vec3& angularVelocity) {
|
glm::vec3& linearVelocity, glm::vec3& angularVelocity) {
|
||||||
auto avatarManager = DependencyManager::get<AvatarManager>();
|
auto avatarManager = DependencyManager::get<AvatarManager>();
|
||||||
auto holdingAvatar = std::static_pointer_cast<Avatar>(avatarManager->getAvatarBySessionID(_holderID));
|
auto holdingAvatar = std::static_pointer_cast<Avatar>(avatarManager->getAvatarBySessionID(_holderID));
|
||||||
|
@ -106,16 +106,16 @@ std::shared_ptr<Avatar> AvatarActionHold::getTarget(glm::quat& rotation, glm::ve
|
||||||
bool isRightHand = (_hand == "right");
|
bool isRightHand = (_hand == "right");
|
||||||
glm::vec3 palmPosition;
|
glm::vec3 palmPosition;
|
||||||
glm::quat palmRotation;
|
glm::quat palmRotation;
|
||||||
glm::vec3 palmLinearVelocity;
|
|
||||||
glm::vec3 palmAngularVelocity;
|
|
||||||
|
|
||||||
PalmData palmData = holdingAvatar->getHand()->getCopyOfPalmData(isRightHand ? HandData::RightHand : HandData::LeftHand);
|
PalmData palmData = holdingAvatar->getHand()->getCopyOfPalmData(isRightHand ? HandData::RightHand : HandData::LeftHand);
|
||||||
|
|
||||||
// TODO: adjust according to _relativePosition and _relativeRotation?
|
if (palmData.isValid()) {
|
||||||
linearVelocity = palmData.getVelocity();
|
// TODO: adjust according to _relativePosition and _relativeRotation?
|
||||||
angularVelocity = palmData.getAngularVelocity();
|
linearVelocity = palmData.getVelocity();
|
||||||
|
angularVelocity = palmData.getAngularVelocity();
|
||||||
|
}
|
||||||
|
|
||||||
if (_ignoreIK && holdingAvatar->isMyAvatar()) {
|
if (_ignoreIK && holdingAvatar->isMyAvatar() && palmData.isValid()) {
|
||||||
// We cannot ignore other avatars IK and this is not the point of this option
|
// We cannot ignore other avatars IK and this is not the point of this option
|
||||||
// This is meant to make the grabbing behavior more reactive.
|
// This is meant to make the grabbing behavior more reactive.
|
||||||
palmPosition = palmData.getPosition();
|
palmPosition = palmData.getPosition();
|
||||||
|
@ -153,6 +153,25 @@ std::shared_ptr<Avatar> AvatarActionHold::getTarget(glm::quat& rotation, glm::ve
|
||||||
palmPosition = holdingAvatar->getLeftPalmPosition();
|
palmPosition = holdingAvatar->getLeftPalmPosition();
|
||||||
palmRotation = holdingAvatar->getLeftPalmRotation();
|
palmRotation = holdingAvatar->getLeftPalmRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In this case we are simulating the grab of another avatar.
|
||||||
|
// Because the hand controller velocity for their palms is not transmitted over the
|
||||||
|
// network, we have to synthesize our own.
|
||||||
|
|
||||||
|
if (_previousSet) {
|
||||||
|
// smooth linear velocity over two frames
|
||||||
|
glm::vec3 positionalDelta = palmPosition - _previousPositionalTarget;
|
||||||
|
linearVelocity = (positionalDelta + _previousPositionalDelta) / (deltaTimeStep + _previousDeltaTimeStep);
|
||||||
|
glm::quat deltaRotation = palmRotation * glm::inverse(_previousRotationalTarget);
|
||||||
|
float rotationAngle = glm::angle(deltaRotation);
|
||||||
|
if (rotationAngle > EPSILON) {
|
||||||
|
angularVelocity = glm::normalize(glm::axis(deltaRotation));
|
||||||
|
angularVelocity *= (rotationAngle / deltaTimeStep);
|
||||||
|
}
|
||||||
|
|
||||||
|
_previousPositionalDelta = positionalDelta;
|
||||||
|
_previousDeltaTimeStep = deltaTimeStep;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rotation = palmRotation * _relativeRotation;
|
rotation = palmRotation * _relativeRotation;
|
||||||
|
@ -183,7 +202,7 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
||||||
glm::quat rotationForAction;
|
glm::quat rotationForAction;
|
||||||
glm::vec3 positionForAction;
|
glm::vec3 positionForAction;
|
||||||
glm::vec3 linearVelocityForAction, angularVelocityForAction;
|
glm::vec3 linearVelocityForAction, angularVelocityForAction;
|
||||||
std::shared_ptr<Avatar> holdingAvatar = holdAction->getTarget(rotationForAction, positionForAction, linearVelocityForAction, angularVelocityForAction);
|
std::shared_ptr<Avatar> holdingAvatar = holdAction->getTarget(deltaTimeStep, rotationForAction, positionForAction, linearVelocityForAction, angularVelocityForAction);
|
||||||
if (holdingAvatar) {
|
if (holdingAvatar) {
|
||||||
holdCount ++;
|
holdCount ++;
|
||||||
if (holdAction.get() == this) {
|
if (holdAction.get() == this) {
|
||||||
|
@ -254,6 +273,7 @@ void AvatarActionHold::doKinematicUpdate(float deltaTimeStep) {
|
||||||
|
|
||||||
_previousPositionalTarget = _positionalTarget;
|
_previousPositionalTarget = _positionalTarget;
|
||||||
_previousRotationalTarget = _rotationalTarget;
|
_previousRotationalTarget = _rotationalTarget;
|
||||||
|
_previousDeltaTimeStep = deltaTimeStep;
|
||||||
_previousSet = true;
|
_previousSet = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
virtual bool shouldSuppressLocationEdits() override { return _active && !_ownerEntity.expired(); }
|
virtual bool shouldSuppressLocationEdits() override { return _active && !_ownerEntity.expired(); }
|
||||||
|
|
||||||
bool getAvatarRigidBodyLocation(glm::vec3& avatarRigidBodyPosition, glm::quat& avatarRigidBodyRotation);
|
bool getAvatarRigidBodyLocation(glm::vec3& avatarRigidBodyPosition, glm::quat& avatarRigidBodyRotation);
|
||||||
std::shared_ptr<Avatar> getTarget(glm::quat& rotation, glm::vec3& position,
|
std::shared_ptr<Avatar> getTarget(float deltaTimeStep, glm::quat& rotation, glm::vec3& position,
|
||||||
glm::vec3& linearVelocity, glm::vec3& angularVelocity);
|
glm::vec3& linearVelocity, glm::vec3& angularVelocity);
|
||||||
|
|
||||||
virtual void prepareForPhysicsSimulation() override;
|
virtual void prepareForPhysicsSimulation() override;
|
||||||
|
@ -61,6 +61,7 @@ private:
|
||||||
glm::vec3 _previousPositionalTarget;
|
glm::vec3 _previousPositionalTarget;
|
||||||
glm::quat _previousRotationalTarget;
|
glm::quat _previousRotationalTarget;
|
||||||
|
|
||||||
|
float _previousDeltaTimeStep { 0.0f };
|
||||||
glm::vec3 _previousPositionalDelta;
|
glm::vec3 _previousPositionalDelta;
|
||||||
|
|
||||||
glm::vec3 _palmOffsetFromRigidBody;
|
glm::vec3 _palmOffsetFromRigidBody;
|
||||||
|
|
Loading…
Reference in a new issue