From 3e9474e8784408673f2461886463facfe9c98026 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 16 Mar 2017 14:30:33 -0700 Subject: [PATCH] CR --- interface/src/avatar/MyAvatar.h | 14 ++++++-------- scripts/tutorials/entity_scripts/sit.js | 18 ++++++++---------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 731ba89299..14142726ea 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -89,8 +89,6 @@ class MyAvatar : public Avatar { Q_PROPERTY(bool hmdLeanRecenterEnabled READ getHMDLeanRecenterEnabled WRITE setHMDLeanRecenterEnabled) Q_PROPERTY(bool characterControllerEnabled READ getCharacterControllerEnabled WRITE setCharacterControllerEnabled) - Q_ENUMS(DriveKeys) - public: explicit MyAvatar(RigPointer rig); ~MyAvatar(); @@ -185,13 +183,13 @@ public: // Set what driving keys are being pressed to control thrust levels void clearDriveKeys(); void setDriveKey(int key, float val) { _driveKeys[key] = val; }; - float getDriveKey(int key) const { return isDriveKeyCaptured(key) ? 0.0f : _driveKeys[key]; }; + float getDriveKey(int key) const { return isDriveKeyDisabled(key) ? 0.0f : _driveKeys[key]; }; Q_INVOKABLE float getRawDriveKey(int key) const { return _driveKeys[key]; }; void relayDriveKeysToCharacterController(); - Q_INVOKABLE void captureDriveKey(int key) { _capturedDriveKeys.set(key); } - Q_INVOKABLE void releaseDriveKey(int key) { _capturedDriveKeys.reset(key); } - Q_INVOKABLE bool isDriveKeyCaptured(int key) const { return _capturedDriveKeys.test(key); } + Q_INVOKABLE void disableDriveKey(int key) { _disabledDriveKeys.set(key); } + Q_INVOKABLE void enableDriveKey(int key) { _disabledDriveKeys.reset(key); } + Q_INVOKABLE bool isDriveKeyDisabled(int key) const { return _disabledDriveKeys.test(key); } eyeContactTarget getEyeContactTarget(); @@ -397,8 +395,8 @@ private: void clampScaleChangeToDomainLimits(float desiredScale); glm::mat4 computeCameraRelativeHandControllerMatrix(const glm::mat4& controllerSensorMatrix) const; - std::array _driveKeys; - std::bitset _capturedDriveKeys; + float _driveKeys[MAX_DRIVE_KEYS]; + std::bitset _disabledDriveKeys; bool _wasPushing; bool _isPushing; diff --git a/scripts/tutorials/entity_scripts/sit.js b/scripts/tutorials/entity_scripts/sit.js index 42cf7685ad..5fff9877b0 100644 --- a/scripts/tutorials/entity_scripts/sit.js +++ b/scripts/tutorials/entity_scripts/sit.js @@ -19,7 +19,7 @@ this.entityID = null; this.animStateHandlerID = null; this.interval = null; - this.sitDownTimestamp = null; + this.sitDownSettlePeriod = null; this.lastTimeNoDriveKeys = null; this.preload = function(entityID) { @@ -100,8 +100,9 @@ } print("Sitting down (" + this.entityID + ")"); - this.sitDownTimestamp = Date.now(); - this.lastTimeNoDriveKeys = this.sitDownTimestamp; + var now = Date.now(); + this.sitDownSettlePeriod = now + IK_SETTLE_TIME; + this.lastTimeNoDriveKeys = now; var previousValue = Settings.getValue(SETTING_KEY); Settings.setValue(SETTING_KEY, this.entityID); @@ -125,7 +126,7 @@ }, ["headType"]); Script.update.connect(this, this.update); for (var i in OVERRIDEN_DRIVE_KEYS) { - MyAvatar.captureDriveKey(OVERRIDEN_DRIVE_KEYS[i]); + MyAvatar.disableDriveKey(OVERRIDEN_DRIVE_KEYS[i]); } } @@ -134,7 +135,7 @@ MyAvatar.removeAnimationStateHandler(this.animStateHandlerID); Script.update.disconnect(this, this.update); for (var i in OVERRIDEN_DRIVE_KEYS) { - MyAvatar.releaseDriveKey(OVERRIDEN_DRIVE_KEYS[i]); + MyAvatar.enableDriveKey(OVERRIDEN_DRIVE_KEYS[i]); } this.setSeatUser(null); @@ -232,11 +233,8 @@ } // Allow some time for the IK to settle - if (ikError > MAX_IK_ERROR) { - var elapsed = now - this.sitDownTimestamp; - if (elapsed > IK_SETTLE_TIME) { - shouldStandUp = true; - } + if (ikError > MAX_IK_ERROR && now > this.sitDownSettlePeriod) { + shouldStandUp = true; }