split AvatarActionHold's finding of its location target into a new function

This commit is contained in:
Seth Alves 2015-11-13 14:58:17 -08:00
parent 3b6b56f316
commit ac635336b7
2 changed files with 30 additions and 23 deletions

View file

@ -10,7 +10,6 @@
//
#include "QVariantGLM.h"
#include "avatar/MyAvatar.h"
#include "avatar/AvatarManager.h"
#include "AvatarActionHold.h"
@ -22,8 +21,7 @@ AvatarActionHold::AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntit
_relativePosition(glm::vec3(0.0f)),
_relativeRotation(glm::quat()),
_hand("right"),
_holderID(QUuid())
{
_holderID(QUuid()) {
_type = ACTION_TYPE_HOLD;
#if WANT_DEBUG
qDebug() << "AvatarActionHold::AvatarActionHold";
@ -36,13 +34,10 @@ AvatarActionHold::~AvatarActionHold() {
#endif
}
void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
bool gotLock = false;
glm::quat rotation;
glm::vec3 position;
std::shared_ptr<Avatar> AvatarActionHold::getTarget(glm::quat& rotation, glm::vec3& position) {
std::shared_ptr<Avatar> holdingAvatar = nullptr;
gotLock = withTryReadLock([&]{
withTryReadLock([&]{
QSharedPointer<AvatarManager> avatarManager = DependencyManager::get<AvatarManager>();
AvatarSharedPointer holdingAvatarData = avatarManager->getAvatarBySessionID(_holderID);
holdingAvatar = std::static_pointer_cast<Avatar>(holdingAvatarData);
@ -65,9 +60,16 @@ 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 (gotLock) {
gotLock = withTryWriteLock([&]{
bool gotLock = withTryWriteLock([&]{
_positionalTarget = position;
_rotationalTarget = rotation;
_positionalTargetSet = true;
@ -84,7 +86,6 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
}
}
}
}
void AvatarActionHold::doKinematicUpdate(float deltaTimeStep) {
auto ownerEntity = _ownerEntity.lock();
@ -109,7 +110,8 @@ void AvatarActionHold::doKinematicUpdate(float deltaTimeStep) {
if (_previousSet) {
// smooth velocity over 2 frames
glm::vec3 positionalDelta = _positionalTarget - _previousPositionalTarget;
glm::vec3 positionalVelocity = (positionalDelta + _previousPositionalDelta) / (deltaTimeStep + _previousDeltaTimeStep);
glm::vec3 positionalVelocity =
(positionalDelta + _previousPositionalDelta) / (deltaTimeStep + _previousDeltaTimeStep);
rigidBody->setLinearVelocity(glmToBullet(positionalVelocity));
_previousPositionalDelta = positionalDelta;
_previousDeltaTimeStep = deltaTimeStep;

View file

@ -17,6 +17,9 @@
#include <EntityItem.h>
#include <ObjectActionSpring.h>
#include "avatar/MyAvatar.h"
class AvatarActionHold : public ObjectActionSpring {
public:
AvatarActionHold(const QUuid& id, EntityItemPointer ownerEntity);
@ -32,6 +35,8 @@ public:
virtual bool shouldSuppressLocationEdits() { return _active && !_ownerEntity.expired(); }
std::shared_ptr<Avatar> getTarget(glm::quat& rotation, glm::vec3& position);
private:
static const uint16_t holdVersion;