From 0d514ad6450f46da10d3d2a1b68becfc07f2fb12 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Thu, 22 Oct 2015 13:02:08 -0700 Subject: [PATCH 01/16] Thread-safe avatar list access --- interface/src/avatar/AvatarManager.cpp | 8 +++++++- libraries/avatars/src/AvatarHashMap.cpp | 3 +++ libraries/avatars/src/AvatarHashMap.h | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index 5f0ac435e0..20fdfdb1e9 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -77,7 +77,10 @@ AvatarManager::AvatarManager(QObject* parent) : void AvatarManager::init() { _myAvatar->init(); - _avatarHash.insert(MY_AVATAR_KEY, _myAvatar); + { + QWriteLocker locker(&_hashLock); + _avatarHash.insert(MY_AVATAR_KEY, _myAvatar); + } connect(DependencyManager::get().data(), &SceneScriptingInterface::shouldRenderAvatarsChanged, this, &AvatarManager::updateAvatarRenderStatus, Qt::QueuedConnection); @@ -127,6 +130,7 @@ void AvatarManager::updateOtherAvatars(float deltaTime) { } else if (avatar->shouldDie()) { removeAvatarMotionState(avatar); _avatarFades.push_back(avatarIterator.value()); + QWriteLocker locker(&_hashLock); avatarIterator = _avatarHash.erase(avatarIterator); } else { avatar->startUpdate(); @@ -202,6 +206,7 @@ void AvatarManager::removeAvatar(const QUuid& sessionUUID) { if (avatar != _myAvatar && avatar->isInitialized()) { removeAvatarMotionState(avatar); _avatarFades.push_back(avatarIterator.value()); + QWriteLocker locker(&_hashLock); _avatarHash.erase(avatarIterator); } } @@ -218,6 +223,7 @@ void AvatarManager::clearOtherAvatars() { } else { removeAvatarMotionState(avatar); _avatarFades.push_back(avatarIterator.value()); + QWriteLocker locker(&_hashLock); avatarIterator = _avatarHash.erase(avatarIterator); } } diff --git a/libraries/avatars/src/AvatarHashMap.cpp b/libraries/avatars/src/AvatarHashMap.cpp index 520bb34887..4256e2650e 100644 --- a/libraries/avatars/src/AvatarHashMap.cpp +++ b/libraries/avatars/src/AvatarHashMap.cpp @@ -23,6 +23,7 @@ AvatarHashMap::AvatarHashMap() { } bool AvatarHashMap::isAvatarInRange(const glm::vec3& position, const float range) { + QReadLocker locker(&_hashLock); foreach(const AvatarSharedPointer& sharedAvatar, _avatarHash) { glm::vec3 avatarPosition = sharedAvatar->getPosition(); float distance = glm::distance(avatarPosition, position); @@ -43,6 +44,7 @@ AvatarSharedPointer AvatarHashMap::addAvatar(const QUuid& sessionUUID, const QWe AvatarSharedPointer avatar = newSharedAvatar(); avatar->setSessionUUID(sessionUUID); avatar->setOwningAvatarMixer(mixerWeakPointer); + QWriteLocker locker(&_hashLock); _avatarHash.insert(sessionUUID, avatar); return avatar; @@ -134,6 +136,7 @@ void AvatarHashMap::processKillAvatar(QSharedPointer packet, SharedNod } void AvatarHashMap::removeAvatar(const QUuid& sessionUUID) { + QWriteLocker locker(&_hashLock); _avatarHash.remove(sessionUUID); } diff --git a/libraries/avatars/src/AvatarHashMap.h b/libraries/avatars/src/AvatarHashMap.h index 804233b76a..142fb1cab5 100644 --- a/libraries/avatars/src/AvatarHashMap.h +++ b/libraries/avatars/src/AvatarHashMap.h @@ -52,6 +52,9 @@ protected: virtual void removeAvatar(const QUuid& sessionUUID); AvatarHash _avatarHash; + // "Case-based safety": Most access to the _avatarHash is on the same thread. Write access is protected by a write lock. + // If you access from a different thread, it is your responsibility to write- or read-lock the _hashLock. + QReadWriteLock _hashLock; private: QUuid _lastOwnerSessionUUID; From 624ed7c71128cd413f577ca26963c648f7eb9fd8 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Thu, 22 Oct 2015 13:14:38 -0700 Subject: [PATCH 02/16] fix comment --- libraries/avatars/src/AvatarHashMap.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/avatars/src/AvatarHashMap.h b/libraries/avatars/src/AvatarHashMap.h index 142fb1cab5..4af741c8cc 100644 --- a/libraries/avatars/src/AvatarHashMap.h +++ b/libraries/avatars/src/AvatarHashMap.h @@ -52,8 +52,8 @@ protected: virtual void removeAvatar(const QUuid& sessionUUID); AvatarHash _avatarHash; - // "Case-based safety": Most access to the _avatarHash is on the same thread. Write access is protected by a write lock. - // If you access from a different thread, it is your responsibility to write- or read-lock the _hashLock. + // "Case-based safety": Most access to the _avatarHash is on the same thread. Write access is protected by a write-lock. + // If you read from a different thread, you must read-lock the _hashLock. (Scripted write access is not supported). QReadWriteLock _hashLock; private: From 7b0b77f4d11eb8b7f40631b111d0dafabfc56b68 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Fri, 23 Oct 2015 16:57:27 -0700 Subject: [PATCH 03/16] getAvatarHash => withAvatarHash --- interface/src/avatar/AvatarManager.cpp | 6 +- interface/src/avatar/MyAvatar.cpp | 107 ++++++++++++------------ libraries/avatars/src/AvatarHashMap.cpp | 4 + libraries/avatars/src/AvatarHashMap.h | 3 +- 4 files changed, 65 insertions(+), 55 deletions(-) diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index 20fdfdb1e9..4352934315 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -355,5 +355,9 @@ AvatarSharedPointer AvatarManager::getAvatarBySessionID(const QUuid& sessionID) if (sessionID == _myAvatar->getSessionUUID()) { return std::static_pointer_cast(_myAvatar); } - return getAvatarHash()[sessionID]; + AvatarSharedPointer avatar; + withAvatarHash([&avatar, &sessionID] (const AvatarHash& hash) { + avatar = hash[sessionID]; + }); + return avatar; } diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 5920543dca..c6711c3324 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1018,71 +1018,72 @@ void MyAvatar::updateLookAtTargetAvatar() { const float KEEP_LOOKING_AT_CURRENT_ANGLE_FACTOR = 1.3f; const float GREATEST_LOOKING_AT_DISTANCE = 10.0f; - foreach (const AvatarSharedPointer& avatarPointer, DependencyManager::get()->getAvatarHash()) { - auto avatar = static_pointer_cast(avatarPointer); - bool isCurrentTarget = avatar->getIsLookAtTarget(); - float distanceTo = glm::length(avatar->getHead()->getEyePosition() - cameraPosition); - avatar->setIsLookAtTarget(false); - if (!avatar->isMyAvatar() && avatar->isInitialized() && (distanceTo < GREATEST_LOOKING_AT_DISTANCE * getScale())) { - float angleTo = glm::angle(lookForward, glm::normalize(avatar->getHead()->getEyePosition() - cameraPosition)); - if (angleTo < (smallestAngleTo * (isCurrentTarget ? KEEP_LOOKING_AT_CURRENT_ANGLE_FACTOR : 1.0f))) { - _lookAtTargetAvatar = avatarPointer; - _targetAvatarPosition = avatarPointer->getPosition(); - smallestAngleTo = angleTo; - } - if (isLookingAtMe(avatar)) { + DependencyManager::get()->withAvatarHash([&] (const AvatarHash& hash) { + foreach (const AvatarSharedPointer& avatarPointer, hash) { + auto avatar = static_pointer_cast(avatarPointer); + bool isCurrentTarget = avatar->getIsLookAtTarget(); + float distanceTo = glm::length(avatar->getHead()->getEyePosition() - cameraPosition); + avatar->setIsLookAtTarget(false); + if (!avatar->isMyAvatar() && avatar->isInitialized() && (distanceTo < GREATEST_LOOKING_AT_DISTANCE * getScale())) { + float angleTo = glm::angle(lookForward, glm::normalize(avatar->getHead()->getEyePosition() - cameraPosition)); + if (angleTo < (smallestAngleTo * (isCurrentTarget ? KEEP_LOOKING_AT_CURRENT_ANGLE_FACTOR : 1.0f))) { + _lookAtTargetAvatar = avatarPointer; + _targetAvatarPosition = avatarPointer->getPosition(); + smallestAngleTo = angleTo; + } + if (isLookingAtMe(avatar)) { - // Alter their gaze to look directly at my camera; this looks more natural than looking at my avatar's face. - glm::vec3 lookAtPosition = avatar->getHead()->getLookAtPosition(); // A position, in world space, on my avatar. + // Alter their gaze to look directly at my camera; this looks more natural than looking at my avatar's face. + glm::vec3 lookAtPosition = avatar->getHead()->getLookAtPosition(); // A position, in world space, on my avatar. - // The camera isn't at the point midway between the avatar eyes. (Even without an HMD, the head can be offset a bit.) - // Let's get everything to world space: - glm::vec3 avatarLeftEye = getHead()->getLeftEyePosition(); - glm::vec3 avatarRightEye = getHead()->getRightEyePosition(); - // When not in HMD, these might both answer identity (i.e., the bridge of the nose). That's ok. - // By my inpsection of the code and live testing, getEyeOffset and getEyePose are the same. (Application hands identity as offset matrix.) - // This might be more work than needed for any given use, but as we explore different formulations, we go mad if we don't work in world space. - glm::mat4 leftEye = qApp->getEyeOffset(Eye::Left); - glm::mat4 rightEye = qApp->getEyeOffset(Eye::Right); - glm::vec3 leftEyeHeadLocal = glm::vec3(leftEye[3]); - glm::vec3 rightEyeHeadLocal = glm::vec3(rightEye[3]); - auto humanSystem = qApp->getViewFrustum(); - glm::vec3 humanLeftEye = humanSystem->getPosition() + (humanSystem->getOrientation() * leftEyeHeadLocal); - glm::vec3 humanRightEye = humanSystem->getPosition() + (humanSystem->getOrientation() * rightEyeHeadLocal); + // The camera isn't at the point midway between the avatar eyes. (Even without an HMD, the head can be offset a bit.) + // Let's get everything to world space: + glm::vec3 avatarLeftEye = getHead()->getLeftEyePosition(); + glm::vec3 avatarRightEye = getHead()->getRightEyePosition(); + // When not in HMD, these might both answer identity (i.e., the bridge of the nose). That's ok. + // By my inpsection of the code and live testing, getEyeOffset and getEyePose are the same. (Application hands identity as offset matrix.) + // This might be more work than needed for any given use, but as we explore different formulations, we go mad if we don't work in world space. + glm::mat4 leftEye = qApp->getEyeOffset(Eye::Left); + glm::mat4 rightEye = qApp->getEyeOffset(Eye::Right); + glm::vec3 leftEyeHeadLocal = glm::vec3(leftEye[3]); + glm::vec3 rightEyeHeadLocal = glm::vec3(rightEye[3]); + auto humanSystem = qApp->getViewFrustum(); + glm::vec3 humanLeftEye = humanSystem->getPosition() + (humanSystem->getOrientation() * leftEyeHeadLocal); + glm::vec3 humanRightEye = humanSystem->getPosition() + (humanSystem->getOrientation() * rightEyeHeadLocal); + // First find out where (in world space) the person is looking relative to that bridge-of-the-avatar point. + // (We will be adding that offset to the camera position, after making some other adjustments.) + glm::vec3 gazeOffset = lookAtPosition - getHead()->getEyePosition(); - // First find out where (in world space) the person is looking relative to that bridge-of-the-avatar point. - // (We will be adding that offset to the camera position, after making some other adjustments.) - glm::vec3 gazeOffset = lookAtPosition - getHead()->getEyePosition(); + // Scale by proportional differences between avatar and human. + float humanEyeSeparationInModelSpace = glm::length(humanLeftEye - humanRightEye); + float avatarEyeSeparation = glm::length(avatarLeftEye - avatarRightEye); + gazeOffset = gazeOffset * humanEyeSeparationInModelSpace / avatarEyeSeparation; - // Scale by proportional differences between avatar and human. - float humanEyeSeparationInModelSpace = glm::length(humanLeftEye - humanRightEye); - float avatarEyeSeparation = glm::length(avatarLeftEye - avatarRightEye); - gazeOffset = gazeOffset * humanEyeSeparationInModelSpace / avatarEyeSeparation; + // If the camera is also not oriented with the head, adjust by getting the offset in head-space... + /* Not needed (i.e., code is a no-op), but I'm leaving the example code here in case something like this is needed someday. + glm::quat avatarHeadOrientation = getHead()->getOrientation(); + glm::vec3 gazeOffsetLocalToHead = glm::inverse(avatarHeadOrientation) * gazeOffset; + // ... and treat that as though it were in camera space, bringing it back to world space. + // But camera is fudged to make the picture feel like the avatar's orientation. + glm::quat humanOrientation = humanSystem->getOrientation(); // or just avatar getOrienation() ? + gazeOffset = humanOrientation * gazeOffsetLocalToHead; + glm::vec3 corrected = humanSystem->getPosition() + gazeOffset; + */ - // If the camera is also not oriented with the head, adjust by getting the offset in head-space... - /* Not needed (i.e., code is a no-op), but I'm leaving the example code here in case something like this is needed someday. - glm::quat avatarHeadOrientation = getHead()->getOrientation(); - glm::vec3 gazeOffsetLocalToHead = glm::inverse(avatarHeadOrientation) * gazeOffset; - // ... and treat that as though it were in camera space, bringing it back to world space. - // But camera is fudged to make the picture feel like the avatar's orientation. - glm::quat humanOrientation = humanSystem->getOrientation(); // or just avatar getOrienation() ? - gazeOffset = humanOrientation * gazeOffsetLocalToHead; - glm::vec3 corrected = humanSystem->getPosition() + gazeOffset; - */ + // And now we can finally add that offset to the camera. + glm::vec3 corrected = qApp->getViewFrustum()->getPosition() + gazeOffset; - // And now we can finally add that offset to the camera. - glm::vec3 corrected = qApp->getViewFrustum()->getPosition() + gazeOffset; - - avatar->getHead()->setCorrectedLookAtPosition(corrected); + avatar->getHead()->setCorrectedLookAtPosition(corrected); + } else { + avatar->getHead()->clearCorrectedLookAtPosition(); + } } else { avatar->getHead()->clearCorrectedLookAtPosition(); } - } else { - avatar->getHead()->clearCorrectedLookAtPosition(); } - } + }); auto avatarPointer = _lookAtTargetAvatar.lock(); if (avatarPointer) { static_pointer_cast(avatarPointer)->setIsLookAtTarget(true); diff --git a/libraries/avatars/src/AvatarHashMap.cpp b/libraries/avatars/src/AvatarHashMap.cpp index 4256e2650e..3f1e668cd0 100644 --- a/libraries/avatars/src/AvatarHashMap.cpp +++ b/libraries/avatars/src/AvatarHashMap.cpp @@ -22,6 +22,10 @@ AvatarHashMap::AvatarHashMap() { connect(DependencyManager::get().data(), &NodeList::uuidChanged, this, &AvatarHashMap::sessionUUIDChanged); } +void AvatarHashMap::withAvatarHash(std::function callback) { + QReadLocker locker(&_hashLock); + callback(_avatarHash); +} bool AvatarHashMap::isAvatarInRange(const glm::vec3& position, const float range) { QReadLocker locker(&_hashLock); foreach(const AvatarSharedPointer& sharedAvatar, _avatarHash) { diff --git a/libraries/avatars/src/AvatarHashMap.h b/libraries/avatars/src/AvatarHashMap.h index 4af741c8cc..93364eb1ef 100644 --- a/libraries/avatars/src/AvatarHashMap.h +++ b/libraries/avatars/src/AvatarHashMap.h @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -30,7 +31,7 @@ class AvatarHashMap : public QObject, public Dependency { SINGLETON_DEPENDENCY public: - const AvatarHash& getAvatarHash() { return _avatarHash; } + void withAvatarHash(std::function); int size() { return _avatarHash.size(); } public slots: From fc8184ffedb3286d102fce49b1370e70e838f3ad Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 26 Oct 2015 12:25:51 -0700 Subject: [PATCH 04/16] add arcade sound --- examples/toybox/AC_scripts/toybox_sounds.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/examples/toybox/AC_scripts/toybox_sounds.js b/examples/toybox/AC_scripts/toybox_sounds.js index 67985a5938..10c7135196 100644 --- a/examples/toybox/AC_scripts/toybox_sounds.js +++ b/examples/toybox/AC_scripts/toybox_sounds.js @@ -65,7 +65,7 @@ var soundMap = [{ y: 495.60, z: 502.08 }, - volume: 0.25, + volume: 0.05, loop: true } }, { @@ -73,14 +73,27 @@ var soundMap = [{ url: "http://hifi-public.s3.amazonaws.com/ryan/dogs_barking_1.L.wav", audioOptions: { position: { - x: 551.61, + x: 523, y: 494.88, - z: 502.00 + z: 469 }, - volume: 0.15, + volume: 0.05, loop: false }, playAtInterval: 60 * 1000 +}, { + name: 'arcade game', + url: "http://hifi-public.s3.amazonaws.com/ryan/ARCADE_GAMES_VID.L.L.wav", + audioOptions: { + position: { + x: 543.77, + y: 495.07, + z: 502.25 + }, + volume: 0.01, + loop: false, + }, + playAtInterval: 90 * 1000 }]; function loadSounds() { From 8d0aaed41ae09f2ef47e0390b3f4e254303dcf3c Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 26 Oct 2015 13:50:21 -0700 Subject: [PATCH 05/16] fix bug that was deleting actions with 0 ttl. in js interface, action parameter 'lifetime' is now called 'ttl' --- examples/controllers/handControllerGrab.js | 24 ++++++++--------- examples/grab.js | 8 +++--- interface/src/InterfaceActionFactory.cpp | 3 ++- interface/src/avatar/AvatarActionHold.cpp | 8 +++--- .../entities/src/EntityActionInterface.h | 1 + libraries/physics/src/ObjectAction.cpp | 26 ++++++++++++++----- libraries/physics/src/ObjectAction.h | 9 +++++-- libraries/physics/src/ObjectActionOffset.cpp | 9 ++++--- libraries/physics/src/ObjectActionSpring.cpp | 8 +++--- 9 files changed, 62 insertions(+), 34 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 80fb4c8e40..cb445a0960 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -74,8 +74,8 @@ var MSEC_PER_SEC = 1000.0; // these control how long an abandoned pointer line will hang around var LIFETIME = 10; -var ACTION_LIFETIME = 15; // seconds -var ACTION_LIFETIME_REFRESH = 5; +var ACTION_TTL = 15; // seconds +var ACTION_TTL_REFRESH = 5; var PICKS_PER_SECOND_PER_HAND = 5; var MSECS_PER_SEC = 1000.0; @@ -422,12 +422,12 @@ function MyController(hand, triggerAction) { targetRotation: this.currentObjectRotation, angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, tag: getTag(), - lifetime: ACTION_LIFETIME + ttl: ACTION_TTL }); if (this.actionID === NULL_ACTION_ID) { this.actionID = null; } - this.actionTimeout = now + (ACTION_LIFETIME * MSEC_PER_SEC); + this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); if (this.actionID !== null) { this.setState(STATE_CONTINUE_DISTANCE_HOLDING); @@ -524,9 +524,9 @@ function MyController(hand, triggerAction) { linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, targetRotation: this.currentObjectRotation, angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, - lifetime: ACTION_LIFETIME + ttl: ACTION_TTL }); - this.actionTimeout = now + (ACTION_LIFETIME * MSEC_PER_SEC); + this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); }; this.nearGrabbing = function() { @@ -579,12 +579,12 @@ function MyController(hand, triggerAction) { timeScale: NEAR_GRABBING_ACTION_TIMEFRAME, relativePosition: this.offsetPosition, relativeRotation: this.offsetRotation, - lifetime: ACTION_LIFETIME + ttl: ACTION_TTL }); if (this.actionID === NULL_ACTION_ID) { this.actionID = null; } else { - this.actionTimeout = now + (ACTION_LIFETIME * MSEC_PER_SEC); + this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); this.setState(STATE_CONTINUE_NEAR_GRABBING); if (this.hand === RIGHT_HAND) { Entities.callEntityMethod(this.grabbedEntity, "setRightHand"); @@ -624,16 +624,16 @@ function MyController(hand, triggerAction) { this.currentObjectTime = now; Entities.callEntityMethod(this.grabbedEntity, "continueNearGrab"); - if (this.actionTimeout - now < ACTION_LIFETIME_REFRESH * MSEC_PER_SEC) { - // if less than a 5 seconds left, refresh the actions lifetime + if (this.actionTimeout - now < ACTION_TTL_REFRESH * MSEC_PER_SEC) { + // if less than a 5 seconds left, refresh the actions ttl Entities.updateAction(this.grabbedEntity, this.actionID, { hand: this.hand === RIGHT_HAND ? "right" : "left", timeScale: NEAR_GRABBING_ACTION_TIMEFRAME, relativePosition: this.offsetPosition, relativeRotation: this.offsetRotation, - lifetime: ACTION_LIFETIME + ttl: ACTION_TTL }); - this.actionTimeout = now + (ACTION_LIFETIME * MSEC_PER_SEC); + this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); } }; diff --git a/examples/grab.js b/examples/grab.js index 1a02911db9..ee6c3c4de5 100644 --- a/examples/grab.js +++ b/examples/grab.js @@ -47,7 +47,7 @@ var IDENTITY_QUAT = { z: 0, w: 0 }; -var ACTION_LIFETIME = 10; // seconds +var ACTION_TTL = 10; // seconds function getTag() { return "grab-" + MyAvatar.sessionUUID; @@ -403,7 +403,7 @@ Grabber.prototype.moveEvent = function(event) { var actionArgs = { tag: getTag(), - lifetime: ACTION_LIFETIME + ttl: ACTION_TTL }; if (this.mode === "rotate") { @@ -424,7 +424,7 @@ Grabber.prototype.moveEvent = function(event) { targetRotation: this.lastRotation, angularTimeScale: 0.1, tag: getTag(), - lifetime: ACTION_LIFETIME + ttl: ACTION_TTL }; } else { @@ -459,7 +459,7 @@ Grabber.prototype.moveEvent = function(event) { targetPosition: this.targetPosition, linearTimeScale: 0.1, tag: getTag(), - lifetime: ACTION_LIFETIME + ttl: ACTION_TTL }; diff --git a/interface/src/InterfaceActionFactory.cpp b/interface/src/InterfaceActionFactory.cpp index f814df9a99..67b3b4a649 100644 --- a/interface/src/InterfaceActionFactory.cpp +++ b/interface/src/InterfaceActionFactory.cpp @@ -66,7 +66,8 @@ EntityActionPointer InterfaceActionFactory::factoryBA(EntityItemPointer ownerEnt if (action) { action->deserialize(data); if (action->lifetimeIsOver()) { - qDebug() << "InterfaceActionFactory::factoryBA lifetimeIsOver during action creation"; + qDebug() << "InterfaceActionFactory::factoryBA lifetimeIsOver during action creation --" + << action->getExpires() << "<" << usecTimestampNow(); return nullptr; } } diff --git a/interface/src/avatar/AvatarActionHold.cpp b/interface/src/avatar/AvatarActionHold.cpp index d2f5514e10..238e48d2fd 100644 --- a/interface/src/avatar/AvatarActionHold.cpp +++ b/interface/src/avatar/AvatarActionHold.cpp @@ -243,7 +243,7 @@ QByteArray AvatarActionHold::serialize() const { dataStream << _linearTimeScale; dataStream << _hand; - dataStream << _expires + getEntityServerClockSkew(); + dataStream << localTimeToServerTime(_expires); dataStream << _tag; dataStream << _kinematic; dataStream << _kinematicSetVelocity; @@ -277,8 +277,10 @@ void AvatarActionHold::deserialize(QByteArray serializedArguments) { _angularTimeScale = _linearTimeScale; dataStream >> _hand; - dataStream >> _expires; - _expires -= getEntityServerClockSkew(); + quint64 serverExpires; + dataStream >> serverExpires; + _expires = serverTimeToLocalTime(serverExpires); + dataStream >> _tag; dataStream >> _kinematic; dataStream >> _kinematicSetVelocity; diff --git a/libraries/entities/src/EntityActionInterface.h b/libraries/entities/src/EntityActionInterface.h index d97b5e8106..b257df3325 100644 --- a/libraries/entities/src/EntityActionInterface.h +++ b/libraries/entities/src/EntityActionInterface.h @@ -47,6 +47,7 @@ public: static QString actionTypeToString(EntityActionType actionType); virtual bool lifetimeIsOver() { return false; } + virtual quint64 getExpires() { return 0; } bool locallyAddedButNotYetReceived = false; diff --git a/libraries/physics/src/ObjectAction.cpp b/libraries/physics/src/ObjectAction.cpp index ce4ebfd22f..b58e37e495 100644 --- a/libraries/physics/src/ObjectAction.cpp +++ b/libraries/physics/src/ObjectAction.cpp @@ -85,11 +85,11 @@ bool ObjectAction::updateArguments(QVariantMap arguments) { quint64 previousExpires = _expires; QString previousTag = _tag; - bool lifetimeSet = true; - float lifetime = EntityActionInterface::extractFloatArgument("action", arguments, "lifetime", lifetimeSet, false); - if (lifetimeSet) { + bool ttlSet = true; + float ttl = EntityActionInterface::extractFloatArgument("action", arguments, "ttl", ttlSet, false); + if (ttlSet) { quint64 now = usecTimestampNow(); - _expires = now + (quint64)(lifetime * USECS_PER_SECOND); + _expires = now + (quint64)(ttl * USECS_PER_SECOND); } else { _expires = 0; } @@ -114,10 +114,10 @@ QVariantMap ObjectAction::getArguments() { QVariantMap arguments; withReadLock([&]{ if (_expires == 0) { - arguments["lifetime"] = 0.0f; + arguments["ttl"] = 0.0f; } else { quint64 now = usecTimestampNow(); - arguments["lifetime"] = (float)(_expires - now) / (float)USECS_PER_SECOND; + arguments["ttl"] = (float)(_expires - now) / (float)USECS_PER_SECOND; } arguments["tag"] = _tag; }); @@ -245,3 +245,17 @@ bool ObjectAction::lifetimeIsOver() { } return false; } + +quint64 ObjectAction::localTimeToServerTime(quint64 timeValue) { + if (timeValue == 0) { + return 0; + } + return timeValue + getEntityServerClockSkew(); +} + +quint64 ObjectAction::serverTimeToLocalTime(quint64 timeValue) { + if (timeValue == 0) { + return 0; + } + return timeValue - getEntityServerClockSkew(); +} diff --git a/libraries/physics/src/ObjectAction.h b/libraries/physics/src/ObjectAction.h index 98e58475c6..3c8574f6ff 100644 --- a/libraries/physics/src/ObjectAction.h +++ b/libraries/physics/src/ObjectAction.h @@ -47,11 +47,10 @@ public: virtual void deserialize(QByteArray serializedArguments) = 0; virtual bool lifetimeIsOver(); + virtual quint64 getExpires() { return _expires; } protected: - int getEntityServerClockSkew() const; - virtual btRigidBody* getRigidBody(); virtual glm::vec3 getPosition(); virtual void setPosition(glm::vec3 position); @@ -68,6 +67,12 @@ protected: quint64 _expires; // in seconds since epoch QString _tag; + + quint64 localTimeToServerTime(quint64 timeValue); + quint64 serverTimeToLocalTime(quint64 timeValue); + +private: + int getEntityServerClockSkew() const; }; #endif // hifi_ObjectAction_h diff --git a/libraries/physics/src/ObjectActionOffset.cpp b/libraries/physics/src/ObjectActionOffset.cpp index b6edf22ffc..2cfd98497b 100644 --- a/libraries/physics/src/ObjectActionOffset.cpp +++ b/libraries/physics/src/ObjectActionOffset.cpp @@ -160,7 +160,7 @@ QByteArray ObjectActionOffset::serialize() const { dataStream << _linearDistance; dataStream << _linearTimeScale; dataStream << _positionalTargetSet; - dataStream << _expires + getEntityServerClockSkew(); + dataStream << localTimeToServerTime(_expires); dataStream << _tag; }); @@ -189,8 +189,11 @@ void ObjectActionOffset::deserialize(QByteArray serializedArguments) { dataStream >> _linearDistance; dataStream >> _linearTimeScale; dataStream >> _positionalTargetSet; - dataStream >> _expires; - _expires -= getEntityServerClockSkew(); + + quint64 serverExpires; + dataStream >> serverExpires; + _expires = serverTimeToLocalTime(serverExpires); + dataStream >> _tag; _active = true; }); diff --git a/libraries/physics/src/ObjectActionSpring.cpp b/libraries/physics/src/ObjectActionSpring.cpp index a74756eb53..c1cd2db5ca 100644 --- a/libraries/physics/src/ObjectActionSpring.cpp +++ b/libraries/physics/src/ObjectActionSpring.cpp @@ -198,7 +198,7 @@ QByteArray ObjectActionSpring::serialize() const { dataStream << _rotationalTarget; dataStream << _angularTimeScale; dataStream << _rotationalTargetSet; - dataStream << _expires + getEntityServerClockSkew(); + dataStream << localTimeToServerTime(_expires); dataStream << _tag; }); @@ -232,8 +232,10 @@ void ObjectActionSpring::deserialize(QByteArray serializedArguments) { dataStream >> _angularTimeScale; dataStream >> _rotationalTargetSet; - dataStream >> _expires; - _expires -= getEntityServerClockSkew(); + quint64 serverExpires; + dataStream >> serverExpires; + _expires = serverTimeToLocalTime(serverExpires); + dataStream >> _tag; _active = true; From 0dff037f5601b011c992a0565f0d3c49291b61e4 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 26 Oct 2015 13:55:07 -0700 Subject: [PATCH 06/16] fuck you, const! --- libraries/physics/src/ObjectAction.cpp | 4 ++-- libraries/physics/src/ObjectAction.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/physics/src/ObjectAction.cpp b/libraries/physics/src/ObjectAction.cpp index b58e37e495..8ed06aea5d 100644 --- a/libraries/physics/src/ObjectAction.cpp +++ b/libraries/physics/src/ObjectAction.cpp @@ -246,14 +246,14 @@ bool ObjectAction::lifetimeIsOver() { return false; } -quint64 ObjectAction::localTimeToServerTime(quint64 timeValue) { +quint64 ObjectAction::localTimeToServerTime(quint64 timeValue) const { if (timeValue == 0) { return 0; } return timeValue + getEntityServerClockSkew(); } -quint64 ObjectAction::serverTimeToLocalTime(quint64 timeValue) { +quint64 ObjectAction::serverTimeToLocalTime(quint64 timeValue) const { if (timeValue == 0) { return 0; } diff --git a/libraries/physics/src/ObjectAction.h b/libraries/physics/src/ObjectAction.h index 3c8574f6ff..fca446aec4 100644 --- a/libraries/physics/src/ObjectAction.h +++ b/libraries/physics/src/ObjectAction.h @@ -68,8 +68,8 @@ protected: quint64 _expires; // in seconds since epoch QString _tag; - quint64 localTimeToServerTime(quint64 timeValue); - quint64 serverTimeToLocalTime(quint64 timeValue); + quint64 localTimeToServerTime(quint64 timeValue) const; + quint64 serverTimeToLocalTime(quint64 timeValue) const; private: int getEntityServerClockSkew() const; From f436857a6241e2f4874fa615efe310aa8508f291 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 26 Oct 2015 15:28:35 -0700 Subject: [PATCH 07/16] add reset buttons for basketballs and targets --- unpublishedScripts/basketballsResetter.js | 111 ++++++++++++++++++ unpublishedScripts/hiddenEntityReset.js | 109 +++++++++++++++++- unpublishedScripts/immediateClientReset.js | 7 +- unpublishedScripts/masterReset.js | 128 +++++++++++++++++++-- unpublishedScripts/targetsResetter.js | 128 +++++++++++++++++++++ 5 files changed, 461 insertions(+), 22 deletions(-) create mode 100644 unpublishedScripts/basketballsResetter.js create mode 100644 unpublishedScripts/targetsResetter.js diff --git a/unpublishedScripts/basketballsResetter.js b/unpublishedScripts/basketballsResetter.js new file mode 100644 index 0000000000..8574bc6e92 --- /dev/null +++ b/unpublishedScripts/basketballsResetter.js @@ -0,0 +1,111 @@ +// +// +// Created by James B. Pollack @imgntn on 10/26/2015 +// Copyright 2015 High Fidelity, Inc. +// +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +var HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; + +(function() { + + var _this; + Resetter = function() { + _this = this; + }; + + Resetter.prototype = { + + startFarGrabNonColliding: function() { + this.resetObjects(); + }, + + clickReleaseOnEntity: function() { + this.resetObjects(); + }, + + resetObjects: function() { + var ids = Entities.findEntities(this.initialProperties.position, 75); + var i; + for (i = 0; i < ids.length; i++) { + var id = ids[i]; + var properties = Entities.getEntityProperties(id, "name"); + if (properties.name === "Hifi-Basketball") { + Entities.deleteEntity(id); + } + } + + this.createBasketballs(); + }, + + createBasketballs: function() { + var NUMBER_OF_BALLS = 4; + var DIAMETER = 0.30; + var basketballURL = HIFI_PUBLIC_BUCKET + "models/content/basketball2.fbx"; + var basketballCollisionSoundURL = HIFI_PUBLIC_BUCKET + "sounds/basketball/basketball.wav"; + + var position = { + x: 542.86, + y: 494.84, + z: 475.06 + }; + var collidingBalls = []; + + var i; + for (i = 0; i < NUMBER_OF_BALLS; i++) { + var ballPosition = { + x: position.x, + y: position.y + DIAMETER * 2, + z: position.z + (DIAMETER) - (DIAMETER * i) + }; + var newPosition = { + x: position.x + (DIAMETER * 2) - (DIAMETER * i), + y: position.y + DIAMETER * 2, + z: position.z + }; + var collidingBall = Entities.addEntity({ + type: "Model", + name: 'Hifi-Basketball', + shapeType: 'Sphere', + position: newPosition, + dimensions: { + x: DIAMETER, + y: DIAMETER, + z: DIAMETER + }, + restitution: 1.0, + linearDamping: 0.00001, + gravity: { + x: 0, + y: -9.8, + z: 0 + }, + collisionsWillMove: true, + collisionsSoundURL: basketballCollisionSoundURL, + ignoreForCollisions: false, + modelURL: basketballURL, + userData: JSON.stringify({ + resetMe: { + resetMe: true + }, + grabbableKey: { + invertSolidWhileHeld: true + } + }) + }); + + collidingBalls.push(collidingBall); + + } + }, + + preload: function(entityID) { + this.initialProperties = Entities.getEntityProperties(entityID); + this.entityID = entityID; + }, + + }; + + return new Resetter(); +}); \ No newline at end of file diff --git a/unpublishedScripts/hiddenEntityReset.js b/unpublishedScripts/hiddenEntityReset.js index e441db3aa6..d81c1a125f 100644 --- a/unpublishedScripts/hiddenEntityReset.js +++ b/unpublishedScripts/hiddenEntityReset.js @@ -22,7 +22,8 @@ var dollScriptURL = Script.resolvePath("../examples/toybox/doll/doll.js"); var lightsScriptURL = Script.resolvePath("../examples/toybox/lights/lightSwitch.js"); var targetsScriptURL = Script.resolvePath('../examples/toybox/ping_pong_gun/wallTarget.js'); - + var basketballResetterScriptURL = Script.resolvePath('basketballsResetter.js'); + var targetsResetterScriptURL = Script.resolvePath('targetsResetter.js'); ResetSwitch = function() { _this = this; @@ -110,9 +111,12 @@ }); createPingPongBallGun(); + createTargets(); + createTargetResetter(); createBasketballHoop(); createBasketballRack(); + createBasketballResetter(); createGates(); @@ -120,8 +124,6 @@ // Handles toggling of all sconce lights createLights(); - - createCat({ x: 551.09, y: 494.98, @@ -135,7 +137,6 @@ z: 503.91 }); - createTargets(); } @@ -275,10 +276,11 @@ }) }); - var collidingBalls = []; + function createCollidingBalls() { var position = rackStartPosition; + var collidingBalls = []; var i; for (i = 0; i < NUMBER_OF_BALLS; i++) { @@ -334,6 +336,103 @@ } + function createBasketballResetter() { + + var position = { + x: 542.86, + y: 494.44, + z: 475.06 + }; + + var dimensions = { + x: 0.5, + y: 0.1, + z: 0.01 + }; + + var rotation = Quat.fromPitchYawRollDegrees(0, 0, 0); + + var resetter = Entities.addEntity({ + type: "Text", + position: position, + name: "Basketball Resetter", + script: basketballResetterScriptURL, + rotation: rotation, + dimensions: dimensions, + backgroundColor: { + red: 0, + green: 0, + blue: 0 + }, + textColor: { + red: 255, + green: 255, + blue: 255 + }, + text: "RESET BALLS", + lineHeight: 0.07, + faceCamera: true, + userData: JSON.stringify({ + resetMe: { + resetMe: true + }, + grabbableKey: { + wantsTrigger: true + } + }) + }); + + + } + + function createTargetResetter() { + var dimensions = { + x: 0.5, + y: 0.1, + z: 0.01 + }; + + var position = { + x: 548.68, + y: 495.30, + z: 509.74 + }; + + var rotation = Quat.fromPitchYawRollDegrees(0, 0, 0); + + var resetter = Entities.addEntity({ + type: "Text", + position: position, + name: "Target Resetter", + script: targetsResetterScriptURL, + rotation: rotation, + dimensions: dimensions, + backgroundColor: { + red: 0, + green: 0, + blue: 0 + }, + textColor: { + red: 255, + green: 255, + blue: 255 + }, + faceCamera: true, + text: "RESET TARGETS", + lineHeight: 0.07, + userData: JSON.stringify({ + resetMe: { + resetMe: true + }, + grabbableKey: { + wantsTrigger: true + } + }) + + }); + } + + function createTargets() { var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/target.fbx'; diff --git a/unpublishedScripts/immediateClientReset.js b/unpublishedScripts/immediateClientReset.js index 0a2e9383a2..2088160727 100644 --- a/unpublishedScripts/immediateClientReset.js +++ b/unpublishedScripts/immediateClientReset.js @@ -8,15 +8,11 @@ /*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */ - var masterResetScript = Script.resolvePath("masterReset.js"); var hiddenEntityScriptURL = Script.resolvePath("hiddenEntityReset.js"); - Script.include(masterResetScript); - - function createHiddenMasterSwitch() { var resetKey = "resetMe"; @@ -31,7 +27,6 @@ function createHiddenMasterSwitch() { }); } - var entities = Entities.findEntities(MyAvatar.position, 100); entities.forEach(function(entity) { @@ -41,5 +36,7 @@ entities.forEach(function(entity) { Entities.deleteEntity(entity); } }); + createHiddenMasterSwitch(); + MasterReset(); \ No newline at end of file diff --git a/unpublishedScripts/masterReset.js b/unpublishedScripts/masterReset.js index 956db41235..099c903ea3 100644 --- a/unpublishedScripts/masterReset.js +++ b/unpublishedScripts/masterReset.js @@ -14,16 +14,16 @@ var utilitiesScript = Script.resolvePath("../examples/libraries/utils.js"); Script.include(utilitiesScript); - var sprayPaintScriptURL = Script.resolvePath("../examples/toybox/spray_paint/sprayPaintCan.js"); - var catScriptURL = Script.resolvePath("../examples/toybox/cat/cat.js"); - var flashlightScriptURL = Script.resolvePath('../examples/toybox/flashlight/flashlight.js'); - var pingPongScriptURL = Script.resolvePath('../examples/toybox/ping_pong_gun/pingPongGun.js'); - var wandScriptURL = Script.resolvePath("../examples/toybox/bubblewand/wand.js"); - var dollScriptURL = Script.resolvePath("../examples/toybox/doll/doll.js"); - var lightsScriptURL = Script.resolvePath("../examples/toybox/lights/lightSwitch.js"); - var targetsScriptURL = Script.resolvePath('../examples/toybox/ping_pong_gun/wallTarget.js'); - - +var sprayPaintScriptURL = Script.resolvePath("../examples/toybox/spray_paint/sprayPaintCan.js"); +var catScriptURL = Script.resolvePath("../examples/toybox/cat/cat.js"); +var flashlightScriptURL = Script.resolvePath('../examples/toybox/flashlight/flashlight.js'); +var pingPongScriptURL = Script.resolvePath('../examples/toybox/ping_pong_gun/pingPongGun.js'); +var wandScriptURL = Script.resolvePath("../examples/toybox/bubblewand/wand.js"); +var dollScriptURL = Script.resolvePath("../examples/toybox/doll/doll.js"); +var lightsScriptURL = Script.resolvePath("../examples/toybox/lights/lightSwitch.js"); +var targetsScriptURL = Script.resolvePath('../examples/toybox/ping_pong_gun/wallTarget.js'); +var basketballResetterScriptURL = Script.resolvePath('basketballsResetter.js'); +var targetsResetterScriptURL = Script.resolvePath('targetsResetter.js'); MasterReset = function() { var resetKey = "resetMe"; @@ -84,9 +84,12 @@ MasterReset = function() { }); createPingPongBallGun(); + createTargets(); + createTargetResetter(); createBasketballHoop(); createBasketballRack(); + createBasketballResetter(); createGates(); @@ -109,7 +112,7 @@ MasterReset = function() { z: 503.91 }); - createTargets(); + } @@ -201,6 +204,7 @@ MasterReset = function() { }); } + function createBasketballRack() { var NUMBER_OF_BALLS = 4; var DIAMETER = 0.30; @@ -249,10 +253,11 @@ MasterReset = function() { }) }); - var collidingBalls = []; + function createCollidingBalls() { var position = rackStartPosition; + var collidingBalls = []; var i; for (i = 0; i < NUMBER_OF_BALLS; i++) { @@ -308,6 +313,105 @@ MasterReset = function() { } + + function createBasketballResetter() { + + var position = { + x: 542.86, + y: 494.44, + z: 475.06 + }; + + var dimensions = { + x: 0.5, + y: 0.1, + z: 0.01 + }; + + var rotation = Quat.fromPitchYawRollDegrees(0, 0, 0); + + var resetter = Entities.addEntity({ + type: "Text", + position: position, + name: "Basketball Resetter", + script: basketballResetterScriptURL, + rotation: rotation, + dimensions: dimensions, + backgroundColor: { + red: 0, + green: 0, + blue: 0 + }, + textColor: { + red: 255, + green: 255, + blue: 255 + }, + text: "RESET BALLS", + lineHeight: 0.07, + faceCamera: true, + userData: JSON.stringify({ + resetMe: { + resetMe: true + }, + grabbableKey: { + wantsTrigger: true + } + }) + }); + + + } + + function createTargetResetter() { + var dimensions = { + x: 0.5, + y: 0.1, + z: 0.01 + }; + + var position = { + x: 548.68, + y: 495.30, + z: 509.74 + }; + + var rotation = Quat.fromPitchYawRollDegrees(0, 0, 0); + + var resetter = Entities.addEntity({ + type: "Text", + position: position, + name: "Target Resetter", + script: targetsResetterScriptURL, + rotation: rotation, + dimensions: dimensions, + backgroundColor: { + red: 0, + green: 0, + blue: 0 + }, + textColor: { + red: 255, + green: 255, + blue: 255 + }, + faceCamera: true, + text: "RESET TARGETS", + lineHeight: 0.07, + userData: JSON.stringify({ + resetMe: { + resetMe: true + }, + grabbableKey: { + wantsTrigger: true + } + }) + + }); + } + + + function createTargets() { var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/target.fbx'; diff --git a/unpublishedScripts/targetsResetter.js b/unpublishedScripts/targetsResetter.js new file mode 100644 index 0000000000..716e98e1e1 --- /dev/null +++ b/unpublishedScripts/targetsResetter.js @@ -0,0 +1,128 @@ +// +// +// Created by James B. Pollack @imgntn on 10/26/2015 +// Copyright 2015 High Fidelity, Inc. +// +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + +(function() { + var targetsScriptURL = Script.resolvePath('../examples/toybox/ping_pong_gun/wallTarget.js'); + + var _this; + Resetter = function() { + _this = this; + }; + + Resetter.prototype = { + + startFarGrabNonColliding: function() { + this.resetObjects(); + }, + + clickReleaseOnEntity: function() { + this.resetObjects(); + }, + + resetObjects: function() { + var ids = Entities.findEntities(this.initialProperties.position, 50); + for (var i = 0; i < ids.length; i++) { + var id = ids[i]; + var properties = Entities.getEntityProperties(id, "name"); + if (properties.name === "Hifi-Target") { + Entities.deleteEntity(id); + } + } + this.createTargets(); + }, + + preload: function(entityID) { + this.initialProperties = Entities.getEntityProperties(entityID); + this.entityID = entityID; + }, + + createTargets: function() { + + var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/target.fbx'; + var COLLISION_HULL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/target_collision_hull.obj'; + + var MINIMUM_MOVE_LENGTH = 0.05; + var RESET_DISTANCE = 0.5; + var TARGET_USER_DATA_KEY = 'hifi-ping_pong_target'; + var NUMBER_OF_TARGETS = 6; + var TARGETS_PER_ROW = 3; + + var TARGET_DIMENSIONS = { + x: 0.06, + y: 0.42, + z: 0.42 + }; + + var VERTICAL_SPACING = TARGET_DIMENSIONS.y + 0.5; + var HORIZONTAL_SPACING = TARGET_DIMENSIONS.z + 0.5; + + + var startPosition = { + x: 548.68, + y: 497.30, + z: 509.74 + }; + + var rotation = Quat.fromPitchYawRollDegrees(0, -55.25, 0); + + var targets = []; + + function addTargets() { + var i; + var row = -1; + for (i = 0; i < NUMBER_OF_TARGETS; i++) { + + if (i % TARGETS_PER_ROW === 0) { + row++; + } + + var vHat = Quat.getFront(rotation); + var spacer = HORIZONTAL_SPACING * (i % TARGETS_PER_ROW) + (row * HORIZONTAL_SPACING / 2); + var multiplier = Vec3.multiply(spacer, vHat); + var position = Vec3.sum(startPosition, multiplier); + position.y = startPosition.y - (row * VERTICAL_SPACING); + + var targetProperties = { + name: 'Hifi-Target', + type: 'Model', + modelURL: MODEL_URL, + shapeType: 'compound', + collisionsWillMove: true, + dimensions: TARGET_DIMENSIONS, + compoundShapeURL: COLLISION_HULL_URL, + position: position, + rotation: rotation, + script: targetsScriptURL, + userData: JSON.stringify({ + originalPositionKey: { + originalPosition: position + }, + resetMe: { + resetMe: true + }, + grabbableKey: { + grabbable: false + } + }) + }; + + var target = Entities.addEntity(targetProperties); + targets.push(target); + + } + } + + addTargets(); + + } + + }; + + return new Resetter(); +}); \ No newline at end of file From 90131f129129129cfb05b27c5aae58304f7a62b3 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 26 Oct 2015 16:00:14 -0700 Subject: [PATCH 08/16] make target reset wider --- unpublishedScripts/hiddenEntityReset.js | 2 +- unpublishedScripts/masterReset.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/unpublishedScripts/hiddenEntityReset.js b/unpublishedScripts/hiddenEntityReset.js index d81c1a125f..574504fd9f 100644 --- a/unpublishedScripts/hiddenEntityReset.js +++ b/unpublishedScripts/hiddenEntityReset.js @@ -387,7 +387,7 @@ function createTargetResetter() { var dimensions = { - x: 0.5, + x: 1, y: 0.1, z: 0.01 }; diff --git a/unpublishedScripts/masterReset.js b/unpublishedScripts/masterReset.js index 099c903ea3..b90fbeb703 100644 --- a/unpublishedScripts/masterReset.js +++ b/unpublishedScripts/masterReset.js @@ -365,7 +365,7 @@ MasterReset = function() { function createTargetResetter() { var dimensions = { - x: 0.5, + x: 1, y: 0.1, z: 0.01 }; @@ -377,7 +377,7 @@ MasterReset = function() { }; var rotation = Quat.fromPitchYawRollDegrees(0, 0, 0); - + var resetter = Entities.addEntity({ type: "Text", position: position, From da5db326e829e59c866ad514fc65a80a3975402a Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 26 Oct 2015 16:03:10 -0700 Subject: [PATCH 09/16] make cat quieter --- examples/toybox/AC_scripts/toybox_sounds.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/toybox/AC_scripts/toybox_sounds.js b/examples/toybox/AC_scripts/toybox_sounds.js index 10c7135196..ee87943f00 100644 --- a/examples/toybox/AC_scripts/toybox_sounds.js +++ b/examples/toybox/AC_scripts/toybox_sounds.js @@ -65,7 +65,7 @@ var soundMap = [{ y: 495.60, z: 502.08 }, - volume: 0.05, + volume: 0.03, loop: true } }, { From 2d873012a34dbeaf6ed546034508ecc1488a817d Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 26 Oct 2015 17:51:55 -0700 Subject: [PATCH 10/16] make reset buttons invisible entities instead of text --- unpublishedScripts/hiddenEntityReset.js | 61 +++++++------------------ unpublishedScripts/masterReset.js | 60 ++++++------------------ 2 files changed, 31 insertions(+), 90 deletions(-) diff --git a/unpublishedScripts/hiddenEntityReset.js b/unpublishedScripts/hiddenEntityReset.js index 574504fd9f..ff2f2fa0cc 100644 --- a/unpublishedScripts/hiddenEntityReset.js +++ b/unpublishedScripts/hiddenEntityReset.js @@ -339,39 +339,24 @@ function createBasketballResetter() { var position = { - x: 542.86, - y: 494.44, - z: 475.06 + x: 543.58, + y: 495.47, + z: 469.59 }; var dimensions = { - x: 0.5, - y: 0.1, - z: 0.01 + x: 1.65, + y: 1.71, + z: 1.75 }; - var rotation = Quat.fromPitchYawRollDegrees(0, 0, 0); - var resetter = Entities.addEntity({ type: "Text", position: position, name: "Basketball Resetter", script: basketballResetterScriptURL, - rotation: rotation, dimensions: dimensions, - backgroundColor: { - red: 0, - green: 0, - blue: 0 - }, - textColor: { - red: 255, - green: 255, - blue: 255 - }, - text: "RESET BALLS", - lineHeight: 0.07, - faceCamera: true, + visible: false, userData: JSON.stringify({ resetMe: { resetMe: true @@ -387,39 +372,24 @@ function createTargetResetter() { var dimensions = { - x: 1, - y: 0.1, - z: 0.01 + x: 0.21, + y: 0.61, + z: 0.21 }; var position = { - x: 548.68, - y: 495.30, - z: 509.74 + x: 548.42, + y: 496.40, + z: 509.61 }; - var rotation = Quat.fromPitchYawRollDegrees(0, 0, 0); - var resetter = Entities.addEntity({ - type: "Text", + type: "Box", position: position, name: "Target Resetter", script: targetsResetterScriptURL, - rotation: rotation, dimensions: dimensions, - backgroundColor: { - red: 0, - green: 0, - blue: 0 - }, - textColor: { - red: 255, - green: 255, - blue: 255 - }, - faceCamera: true, - text: "RESET TARGETS", - lineHeight: 0.07, + visible: false, userData: JSON.stringify({ resetMe: { resetMe: true @@ -433,6 +403,7 @@ } + function createTargets() { var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/target.fbx'; diff --git a/unpublishedScripts/masterReset.js b/unpublishedScripts/masterReset.js index b90fbeb703..2b4f978cf9 100644 --- a/unpublishedScripts/masterReset.js +++ b/unpublishedScripts/masterReset.js @@ -317,39 +317,24 @@ MasterReset = function() { function createBasketballResetter() { var position = { - x: 542.86, - y: 494.44, - z: 475.06 + x: 543.58, + y: 495.47, + z: 469.59 }; var dimensions = { - x: 0.5, - y: 0.1, - z: 0.01 + x: 1.65, + y: 1.71, + z: 1.75 }; - var rotation = Quat.fromPitchYawRollDegrees(0, 0, 0); - var resetter = Entities.addEntity({ type: "Text", position: position, name: "Basketball Resetter", script: basketballResetterScriptURL, - rotation: rotation, dimensions: dimensions, - backgroundColor: { - red: 0, - green: 0, - blue: 0 - }, - textColor: { - red: 255, - green: 255, - blue: 255 - }, - text: "RESET BALLS", - lineHeight: 0.07, - faceCamera: true, + visible:false, userData: JSON.stringify({ resetMe: { resetMe: true @@ -365,39 +350,24 @@ MasterReset = function() { function createTargetResetter() { var dimensions = { - x: 1, - y: 0.1, - z: 0.01 + x: 0.21, + y: 0.61, + z: 0.21 }; var position = { - x: 548.68, - y: 495.30, - z: 509.74 + x: 548.42, + y: 496.40, + z: 509.61 }; - var rotation = Quat.fromPitchYawRollDegrees(0, 0, 0); - var resetter = Entities.addEntity({ - type: "Text", + type: "Box", position: position, name: "Target Resetter", script: targetsResetterScriptURL, - rotation: rotation, dimensions: dimensions, - backgroundColor: { - red: 0, - green: 0, - blue: 0 - }, - textColor: { - red: 255, - green: 255, - blue: 255 - }, - faceCamera: true, - text: "RESET TARGETS", - lineHeight: 0.07, + visible:false, userData: JSON.stringify({ resetMe: { resetMe: true From 7a7f649bf7132c0f7adb66be02a0652dd1738e06 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 26 Oct 2015 17:55:13 -0700 Subject: [PATCH 11/16] change from far grab to near grab --- unpublishedScripts/basketballsResetter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpublishedScripts/basketballsResetter.js b/unpublishedScripts/basketballsResetter.js index 8574bc6e92..6335312d57 100644 --- a/unpublishedScripts/basketballsResetter.js +++ b/unpublishedScripts/basketballsResetter.js @@ -17,7 +17,7 @@ var HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; Resetter.prototype = { - startFarGrabNonColliding: function() { + startNearGrabNonColliding: function() { this.resetObjects(); }, From c8e1aca4b672eb7136ca62d378439d386595acb3 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 26 Oct 2015 18:10:45 -0700 Subject: [PATCH 12/16] fix box dimensions --- unpublishedScripts/hiddenEntityReset.js | 2 +- unpublishedScripts/masterReset.js | 2 +- unpublishedScripts/targetsResetter.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/unpublishedScripts/hiddenEntityReset.js b/unpublishedScripts/hiddenEntityReset.js index ff2f2fa0cc..43d23e4b3c 100644 --- a/unpublishedScripts/hiddenEntityReset.js +++ b/unpublishedScripts/hiddenEntityReset.js @@ -351,7 +351,7 @@ }; var resetter = Entities.addEntity({ - type: "Text", + type: "Box", position: position, name: "Basketball Resetter", script: basketballResetterScriptURL, diff --git a/unpublishedScripts/masterReset.js b/unpublishedScripts/masterReset.js index 2b4f978cf9..74eb3c85ac 100644 --- a/unpublishedScripts/masterReset.js +++ b/unpublishedScripts/masterReset.js @@ -329,7 +329,7 @@ MasterReset = function() { }; var resetter = Entities.addEntity({ - type: "Text", + type: "Box", position: position, name: "Basketball Resetter", script: basketballResetterScriptURL, diff --git a/unpublishedScripts/targetsResetter.js b/unpublishedScripts/targetsResetter.js index 716e98e1e1..a522c19593 100644 --- a/unpublishedScripts/targetsResetter.js +++ b/unpublishedScripts/targetsResetter.js @@ -17,7 +17,7 @@ Resetter.prototype = { - startFarGrabNonColliding: function() { + startNearGrabNonColliding: function() { this.resetObjects(); }, From 4c64da9ce5d22ccf6d98b0dc34a5debd9222130f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 27 Oct 2015 10:27:32 -0700 Subject: [PATCH 13/16] try to avoid negative roll-over when moving to or from server time --- libraries/physics/src/ObjectAction.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libraries/physics/src/ObjectAction.cpp b/libraries/physics/src/ObjectAction.cpp index 8ed06aea5d..ff8382a143 100644 --- a/libraries/physics/src/ObjectAction.cpp +++ b/libraries/physics/src/ObjectAction.cpp @@ -247,15 +247,29 @@ bool ObjectAction::lifetimeIsOver() { } quint64 ObjectAction::localTimeToServerTime(quint64 timeValue) const { + // 0 indicates no expiration if (timeValue == 0) { return 0; } - return timeValue + getEntityServerClockSkew(); + + int serverClockSkew = getEntityServerClockSkew(); + if (serverClockSkew < 0 && timeValue <= (quint64)(-serverClockSkew)) { + return 1; // non-zero but long-expired value to avoid negative roll-over + } + + return timeValue + serverClockSkew; } quint64 ObjectAction::serverTimeToLocalTime(quint64 timeValue) const { + // 0 indicates no expiration if (timeValue == 0) { return 0; } - return timeValue - getEntityServerClockSkew(); + + int serverClockSkew = getEntityServerClockSkew(); + if (serverClockSkew > 0 && timeValue <= (quint64)serverClockSkew) { + return 1; // non-zero but long-expired value to avoid negative roll-over + } + + return timeValue - serverClockSkew; } From 367175b8a64e6ef9e5953861047479fb53a07241 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Wed, 28 Oct 2015 10:49:19 -0700 Subject: [PATCH 14/16] Reduce lock time. --- interface/src/avatar/AvatarManager.cpp | 7 +- interface/src/avatar/MyAvatar.cpp | 110 +++++++++++++------------ 2 files changed, 58 insertions(+), 59 deletions(-) diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index 4352934315..9783590b05 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -355,9 +355,6 @@ AvatarSharedPointer AvatarManager::getAvatarBySessionID(const QUuid& sessionID) if (sessionID == _myAvatar->getSessionUUID()) { return std::static_pointer_cast(_myAvatar); } - AvatarSharedPointer avatar; - withAvatarHash([&avatar, &sessionID] (const AvatarHash& hash) { - avatar = hash[sessionID]; - }); - return avatar; + QReadLocker locker(&_hashLock); + return _avatarHash[sessionID]; } diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index c6711c3324..a69c22813a 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1018,72 +1018,74 @@ void MyAvatar::updateLookAtTargetAvatar() { const float KEEP_LOOKING_AT_CURRENT_ANGLE_FACTOR = 1.3f; const float GREATEST_LOOKING_AT_DISTANCE = 10.0f; - DependencyManager::get()->withAvatarHash([&] (const AvatarHash& hash) { - foreach (const AvatarSharedPointer& avatarPointer, hash) { - auto avatar = static_pointer_cast(avatarPointer); - bool isCurrentTarget = avatar->getIsLookAtTarget(); - float distanceTo = glm::length(avatar->getHead()->getEyePosition() - cameraPosition); - avatar->setIsLookAtTarget(false); - if (!avatar->isMyAvatar() && avatar->isInitialized() && (distanceTo < GREATEST_LOOKING_AT_DISTANCE * getScale())) { - float angleTo = glm::angle(lookForward, glm::normalize(avatar->getHead()->getEyePosition() - cameraPosition)); - if (angleTo < (smallestAngleTo * (isCurrentTarget ? KEEP_LOOKING_AT_CURRENT_ANGLE_FACTOR : 1.0f))) { - _lookAtTargetAvatar = avatarPointer; - _targetAvatarPosition = avatarPointer->getPosition(); - smallestAngleTo = angleTo; - } - if (isLookingAtMe(avatar)) { + AvatarHash hash; + DependencyManager::get()->withAvatarHash([&] (const AvatarHash& locked) { + hash = locked; // make a shallow copy and operate on that, to minimize lock time + }); + foreach (const AvatarSharedPointer& avatarPointer, hash) { + auto avatar = static_pointer_cast(avatarPointer); + bool isCurrentTarget = avatar->getIsLookAtTarget(); + float distanceTo = glm::length(avatar->getHead()->getEyePosition() - cameraPosition); + avatar->setIsLookAtTarget(false); + if (!avatar->isMyAvatar() && avatar->isInitialized() && (distanceTo < GREATEST_LOOKING_AT_DISTANCE * getScale())) { + float angleTo = glm::angle(lookForward, glm::normalize(avatar->getHead()->getEyePosition() - cameraPosition)); + if (angleTo < (smallestAngleTo * (isCurrentTarget ? KEEP_LOOKING_AT_CURRENT_ANGLE_FACTOR : 1.0f))) { + _lookAtTargetAvatar = avatarPointer; + _targetAvatarPosition = avatarPointer->getPosition(); + smallestAngleTo = angleTo; + } + if (isLookingAtMe(avatar)) { - // Alter their gaze to look directly at my camera; this looks more natural than looking at my avatar's face. - glm::vec3 lookAtPosition = avatar->getHead()->getLookAtPosition(); // A position, in world space, on my avatar. + // Alter their gaze to look directly at my camera; this looks more natural than looking at my avatar's face. + glm::vec3 lookAtPosition = avatar->getHead()->getLookAtPosition(); // A position, in world space, on my avatar. - // The camera isn't at the point midway between the avatar eyes. (Even without an HMD, the head can be offset a bit.) - // Let's get everything to world space: - glm::vec3 avatarLeftEye = getHead()->getLeftEyePosition(); - glm::vec3 avatarRightEye = getHead()->getRightEyePosition(); - // When not in HMD, these might both answer identity (i.e., the bridge of the nose). That's ok. - // By my inpsection of the code and live testing, getEyeOffset and getEyePose are the same. (Application hands identity as offset matrix.) - // This might be more work than needed for any given use, but as we explore different formulations, we go mad if we don't work in world space. - glm::mat4 leftEye = qApp->getEyeOffset(Eye::Left); - glm::mat4 rightEye = qApp->getEyeOffset(Eye::Right); - glm::vec3 leftEyeHeadLocal = glm::vec3(leftEye[3]); - glm::vec3 rightEyeHeadLocal = glm::vec3(rightEye[3]); - auto humanSystem = qApp->getViewFrustum(); - glm::vec3 humanLeftEye = humanSystem->getPosition() + (humanSystem->getOrientation() * leftEyeHeadLocal); - glm::vec3 humanRightEye = humanSystem->getPosition() + (humanSystem->getOrientation() * rightEyeHeadLocal); + // The camera isn't at the point midway between the avatar eyes. (Even without an HMD, the head can be offset a bit.) + // Let's get everything to world space: + glm::vec3 avatarLeftEye = getHead()->getLeftEyePosition(); + glm::vec3 avatarRightEye = getHead()->getRightEyePosition(); + // When not in HMD, these might both answer identity (i.e., the bridge of the nose). That's ok. + // By my inpsection of the code and live testing, getEyeOffset and getEyePose are the same. (Application hands identity as offset matrix.) + // This might be more work than needed for any given use, but as we explore different formulations, we go mad if we don't work in world space. + glm::mat4 leftEye = qApp->getEyeOffset(Eye::Left); + glm::mat4 rightEye = qApp->getEyeOffset(Eye::Right); + glm::vec3 leftEyeHeadLocal = glm::vec3(leftEye[3]); + glm::vec3 rightEyeHeadLocal = glm::vec3(rightEye[3]); + auto humanSystem = qApp->getViewFrustum(); + glm::vec3 humanLeftEye = humanSystem->getPosition() + (humanSystem->getOrientation() * leftEyeHeadLocal); + glm::vec3 humanRightEye = humanSystem->getPosition() + (humanSystem->getOrientation() * rightEyeHeadLocal); - // First find out where (in world space) the person is looking relative to that bridge-of-the-avatar point. - // (We will be adding that offset to the camera position, after making some other adjustments.) - glm::vec3 gazeOffset = lookAtPosition - getHead()->getEyePosition(); + // First find out where (in world space) the person is looking relative to that bridge-of-the-avatar point. + // (We will be adding that offset to the camera position, after making some other adjustments.) + glm::vec3 gazeOffset = lookAtPosition - getHead()->getEyePosition(); - // Scale by proportional differences between avatar and human. - float humanEyeSeparationInModelSpace = glm::length(humanLeftEye - humanRightEye); - float avatarEyeSeparation = glm::length(avatarLeftEye - avatarRightEye); - gazeOffset = gazeOffset * humanEyeSeparationInModelSpace / avatarEyeSeparation; + // Scale by proportional differences between avatar and human. + float humanEyeSeparationInModelSpace = glm::length(humanLeftEye - humanRightEye); + float avatarEyeSeparation = glm::length(avatarLeftEye - avatarRightEye); + gazeOffset = gazeOffset * humanEyeSeparationInModelSpace / avatarEyeSeparation; - // If the camera is also not oriented with the head, adjust by getting the offset in head-space... - /* Not needed (i.e., code is a no-op), but I'm leaving the example code here in case something like this is needed someday. - glm::quat avatarHeadOrientation = getHead()->getOrientation(); - glm::vec3 gazeOffsetLocalToHead = glm::inverse(avatarHeadOrientation) * gazeOffset; - // ... and treat that as though it were in camera space, bringing it back to world space. - // But camera is fudged to make the picture feel like the avatar's orientation. - glm::quat humanOrientation = humanSystem->getOrientation(); // or just avatar getOrienation() ? - gazeOffset = humanOrientation * gazeOffsetLocalToHead; - glm::vec3 corrected = humanSystem->getPosition() + gazeOffset; - */ + // If the camera is also not oriented with the head, adjust by getting the offset in head-space... + /* Not needed (i.e., code is a no-op), but I'm leaving the example code here in case something like this is needed someday. + glm::quat avatarHeadOrientation = getHead()->getOrientation(); + glm::vec3 gazeOffsetLocalToHead = glm::inverse(avatarHeadOrientation) * gazeOffset; + // ... and treat that as though it were in camera space, bringing it back to world space. + // But camera is fudged to make the picture feel like the avatar's orientation. + glm::quat humanOrientation = humanSystem->getOrientation(); // or just avatar getOrienation() ? + gazeOffset = humanOrientation * gazeOffsetLocalToHead; + glm::vec3 corrected = humanSystem->getPosition() + gazeOffset; + */ - // And now we can finally add that offset to the camera. - glm::vec3 corrected = qApp->getViewFrustum()->getPosition() + gazeOffset; + // And now we can finally add that offset to the camera. + glm::vec3 corrected = qApp->getViewFrustum()->getPosition() + gazeOffset; - avatar->getHead()->setCorrectedLookAtPosition(corrected); + avatar->getHead()->setCorrectedLookAtPosition(corrected); - } else { - avatar->getHead()->clearCorrectedLookAtPosition(); - } } else { avatar->getHead()->clearCorrectedLookAtPosition(); } + } else { + avatar->getHead()->clearCorrectedLookAtPosition(); } - }); + } auto avatarPointer = _lookAtTargetAvatar.lock(); if (avatarPointer) { static_pointer_cast(avatarPointer)->setIsLookAtTarget(true); From bc0e14cb71275d36459f17f7deb00fdb0bc390b3 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Wed, 28 Oct 2015 13:58:44 -0700 Subject: [PATCH 15/16] Don't render avatar's renderBoundingCollisionShapes before the data is there. (Found while trying to repro "Deadlock in AvatarData::nextAttitude() on main thread" https://app.asana.com/0/32622044445063/61023569045356) --- interface/src/avatar/Avatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 9f4e7ee3cf..00bcf1d271 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -454,7 +454,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) { */ bool renderBounding = Menu::getInstance()->isOptionChecked(MenuOption::RenderBoundingCollisionShapes); - if (renderBounding && shouldRenderHead(renderArgs)) { + if (renderBounding && shouldRenderHead(renderArgs) && _skeletonModel.isRenderable()) { _skeletonModel.renderBoundingCollisionShapes(*renderArgs->_batch, 0.7f); } From 62e56d3f131443908d05a731a07e6b6472ec9fae Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Wed, 28 Oct 2015 16:44:53 -0700 Subject: [PATCH 16/16] Don't go to wrong position on startup/teleport. This fixes one cause of being in the wrong place. https://app.asana.com/0/32622044445063/61787931469907 --- interface/src/avatar/MyAvatar.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index f7fad2bd2b..4d860b7acd 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -208,6 +208,11 @@ void MyAvatar::update(float deltaTime) { setPosition(_goToPosition); setOrientation(_goToOrientation); _goToPending = false; + // updateFromHMDSensorMatrix (called from paintGL) expects that the sensorToWorldMatrix is updated for any position changes + // that happen between render and Application::update (which calls updateSensorToWorldMatrix to do so). + // However, render/MyAvatar::update/Application::update don't always match (e.g., when using the separate avatar update thread), + // so we update now. It's ok if it updates again in the normal way. + updateSensorToWorldMatrix(); } if (_referential) {