mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 20:16:16 +02:00
split AvatarActionHold's finding of its location target into a new function
This commit is contained in:
parent
3b6b56f316
commit
ac635336b7
2 changed files with 30 additions and 23 deletions
|
@ -10,7 +10,6 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "QVariantGLM.h"
|
#include "QVariantGLM.h"
|
||||||
#include "avatar/MyAvatar.h"
|
|
||||||
#include "avatar/AvatarManager.h"
|
#include "avatar/AvatarManager.h"
|
||||||
|
|
||||||
#include "AvatarActionHold.h"
|
#include "AvatarActionHold.h"
|
||||||
|
@ -22,8 +21,7 @@ AvatarActionHold::AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntit
|
||||||
_relativePosition(glm::vec3(0.0f)),
|
_relativePosition(glm::vec3(0.0f)),
|
||||||
_relativeRotation(glm::quat()),
|
_relativeRotation(glm::quat()),
|
||||||
_hand("right"),
|
_hand("right"),
|
||||||
_holderID(QUuid())
|
_holderID(QUuid()) {
|
||||||
{
|
|
||||||
_type = ACTION_TYPE_HOLD;
|
_type = ACTION_TYPE_HOLD;
|
||||||
#if WANT_DEBUG
|
#if WANT_DEBUG
|
||||||
qDebug() << "AvatarActionHold::AvatarActionHold";
|
qDebug() << "AvatarActionHold::AvatarActionHold";
|
||||||
|
@ -36,13 +34,10 @@ AvatarActionHold::~AvatarActionHold() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
std::shared_ptr<Avatar> AvatarActionHold::getTarget(glm::quat& rotation, glm::vec3& position) {
|
||||||
bool gotLock = false;
|
|
||||||
glm::quat rotation;
|
|
||||||
glm::vec3 position;
|
|
||||||
std::shared_ptr<Avatar> holdingAvatar = nullptr;
|
std::shared_ptr<Avatar> holdingAvatar = nullptr;
|
||||||
|
|
||||||
gotLock = withTryReadLock([&]{
|
withTryReadLock([&]{
|
||||||
QSharedPointer<AvatarManager> avatarManager = DependencyManager::get<AvatarManager>();
|
QSharedPointer<AvatarManager> avatarManager = DependencyManager::get<AvatarManager>();
|
||||||
AvatarSharedPointer holdingAvatarData = avatarManager->getAvatarBySessionID(_holderID);
|
AvatarSharedPointer holdingAvatarData = avatarManager->getAvatarBySessionID(_holderID);
|
||||||
holdingAvatar = std::static_pointer_cast<Avatar>(holdingAvatarData);
|
holdingAvatar = std::static_pointer_cast<Avatar>(holdingAvatarData);
|
||||||
|
@ -65,22 +60,28 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return holdingAvatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
|
||||||
|
glm::quat rotation;
|
||||||
|
glm::vec3 position;
|
||||||
|
std::shared_ptr<Avatar> holdingAvatar = getTarget(rotation, position);
|
||||||
|
|
||||||
if (holdingAvatar) {
|
if (holdingAvatar) {
|
||||||
|
bool gotLock = withTryWriteLock([&]{
|
||||||
|
_positionalTarget = position;
|
||||||
|
_rotationalTarget = rotation;
|
||||||
|
_positionalTargetSet = true;
|
||||||
|
_rotationalTargetSet = true;
|
||||||
|
_active = true;
|
||||||
|
});
|
||||||
if (gotLock) {
|
if (gotLock) {
|
||||||
gotLock = withTryWriteLock([&]{
|
if (_kinematic) {
|
||||||
_positionalTarget = position;
|
doKinematicUpdate(deltaTimeStep);
|
||||||
_rotationalTarget = rotation;
|
} else {
|
||||||
_positionalTargetSet = true;
|
activateBody();
|
||||||
_rotationalTargetSet = true;
|
ObjectActionSpring::updateActionWorker(deltaTimeStep);
|
||||||
_active = true;
|
|
||||||
});
|
|
||||||
if (gotLock) {
|
|
||||||
if (_kinematic) {
|
|
||||||
doKinematicUpdate(deltaTimeStep);
|
|
||||||
} else {
|
|
||||||
activateBody();
|
|
||||||
ObjectActionSpring::updateActionWorker(deltaTimeStep);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +110,8 @@ void AvatarActionHold::doKinematicUpdate(float deltaTimeStep) {
|
||||||
if (_previousSet) {
|
if (_previousSet) {
|
||||||
// smooth velocity over 2 frames
|
// smooth velocity over 2 frames
|
||||||
glm::vec3 positionalDelta = _positionalTarget - _previousPositionalTarget;
|
glm::vec3 positionalDelta = _positionalTarget - _previousPositionalTarget;
|
||||||
glm::vec3 positionalVelocity = (positionalDelta + _previousPositionalDelta) / (deltaTimeStep + _previousDeltaTimeStep);
|
glm::vec3 positionalVelocity =
|
||||||
|
(positionalDelta + _previousPositionalDelta) / (deltaTimeStep + _previousDeltaTimeStep);
|
||||||
rigidBody->setLinearVelocity(glmToBullet(positionalVelocity));
|
rigidBody->setLinearVelocity(glmToBullet(positionalVelocity));
|
||||||
_previousPositionalDelta = positionalDelta;
|
_previousPositionalDelta = positionalDelta;
|
||||||
_previousDeltaTimeStep = deltaTimeStep;
|
_previousDeltaTimeStep = deltaTimeStep;
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
#include <EntityItem.h>
|
#include <EntityItem.h>
|
||||||
#include <ObjectActionSpring.h>
|
#include <ObjectActionSpring.h>
|
||||||
|
|
||||||
|
#include "avatar/MyAvatar.h"
|
||||||
|
|
||||||
|
|
||||||
class AvatarActionHold : public ObjectActionSpring {
|
class AvatarActionHold : public ObjectActionSpring {
|
||||||
public:
|
public:
|
||||||
AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntity);
|
AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntity);
|
||||||
|
@ -32,6 +35,8 @@ public:
|
||||||
|
|
||||||
virtual bool shouldSuppressLocationEdits() { return _active && !_ownerEntity.expired(); }
|
virtual bool shouldSuppressLocationEdits() { return _active && !_ownerEntity.expired(); }
|
||||||
|
|
||||||
|
std::shared_ptr<Avatar> getTarget(glm::quat& rotation, glm::vec3& position);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const uint16_t holdVersion;
|
static const uint16_t holdVersion;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue