From 42316e713d9330e33d6cf3da4d08d3264cad442a Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 16 Mar 2017 16:24:52 -0700 Subject: [PATCH] CR drive keys --- interface/src/avatar/MyAvatar.cpp | 68 ++++++++++++++++++++++++- interface/src/avatar/MyAvatar.h | 16 +++--- scripts/tutorials/entity_scripts/sit.js | 8 +-- 3 files changed, 77 insertions(+), 15 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index c38d1ed607..cc40c8eab2 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2091,8 +2091,27 @@ bool MyAvatar::getCharacterControllerEnabled() { } void MyAvatar::clearDriveKeys() { - for (int i = 0; i < MAX_DRIVE_KEYS; ++i) { - setDriveKey(i, 0.0f); + _driveKeys.fill(0.0f); +} + +void MyAvatar::setDriveKey(int key, float val) { + try { + _driveKeys.at(key) = val; + } catch (const std::exception& exception) { + qCCritical(interfaceapp) << Q_FUNC_INFO << ": Index out of bounds"; + } +} + +float MyAvatar::getDriveKey(int key) const { + return isDriveKeyDisabled(key) ? 0.0f : getRawDriveKey(key); +} + +float MyAvatar::getRawDriveKey(int key) const { + try { + return _driveKeys.at(key); + } catch (const std::exception& exception) { + qCCritical(interfaceapp) << Q_FUNC_INFO << ": Index out of bounds"; + return 0.0f; } } @@ -2102,6 +2121,51 @@ void MyAvatar::relayDriveKeysToCharacterController() { } } +void MyAvatar::disableDriveKey(int key) { + try { + _disabledDriveKeys.set(key); + } catch (const std::exception& exception) { + qCCritical(interfaceapp) << Q_FUNC_INFO << ": Index out of bounds"; + } +} + +void MyAvatar::enableDriveKey(int key) { + try { + _disabledDriveKeys.reset(key); + } catch (const std::exception& exception) { + qCCritical(interfaceapp) << Q_FUNC_INFO << ": Index out of bounds"; + } +} + +void MyAvatar::disableDriveKeys(std::vector key) { + try { + std::for_each(std::begin(key), std::end(key), [&](int val){ + _disabledDriveKeys.set(val); + }); + } catch (const std::exception& exception) { + qCCritical(interfaceapp) << Q_FUNC_INFO << ": Index out of bounds"; + } +} + +void MyAvatar::enableDriveKeys(std::vector key) { + try { + std::for_each(std::begin(key), std::end(key), [&](int val) { + _disabledDriveKeys.reset(val); + }); + } catch (const std::exception& exception) { + qCCritical(interfaceapp) << Q_FUNC_INFO << ": Index out of bounds"; + } +} + +bool MyAvatar::isDriveKeyDisabled(int key) const { + try { + return _disabledDriveKeys.test(key); + } catch (const std::exception& exception) { + qCCritical(interfaceapp) << Q_FUNC_INFO << ": Index out of bounds"; + return false; + } +} + glm::vec3 MyAvatar::getWorldBodyPosition() const { return transformPoint(_sensorToWorldMatrix, extractTranslation(_bodySensorMatrix)); } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 14142726ea..cae445c226 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -182,14 +182,16 @@ 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 isDriveKeyDisabled(key) ? 0.0f : _driveKeys[key]; }; - Q_INVOKABLE float getRawDriveKey(int key) const { return _driveKeys[key]; }; + void setDriveKey(int key, float val); + float getDriveKey(int key) const; + Q_INVOKABLE float getRawDriveKey(int key) const; void relayDriveKeysToCharacterController(); - 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); } + Q_INVOKABLE void disableDriveKey(int key); + Q_INVOKABLE void enableDriveKey(int key); + Q_INVOKABLE void disableDriveKeys(std::vector key); + Q_INVOKABLE void enableDriveKeys(std::vector key); + Q_INVOKABLE bool isDriveKeyDisabled(int key) const; eyeContactTarget getEyeContactTarget(); @@ -395,7 +397,7 @@ private: void clampScaleChangeToDomainLimits(float desiredScale); glm::mat4 computeCameraRelativeHandControllerMatrix(const glm::mat4& controllerSensorMatrix) const; - float _driveKeys[MAX_DRIVE_KEYS]; + std::array _driveKeys; std::bitset _disabledDriveKeys; bool _wasPushing; diff --git a/scripts/tutorials/entity_scripts/sit.js b/scripts/tutorials/entity_scripts/sit.js index 5fff9877b0..420a77e2b8 100644 --- a/scripts/tutorials/entity_scripts/sit.js +++ b/scripts/tutorials/entity_scripts/sit.js @@ -125,18 +125,14 @@ return { headType: 0 }; }, ["headType"]); Script.update.connect(this, this.update); - for (var i in OVERRIDEN_DRIVE_KEYS) { - MyAvatar.disableDriveKey(OVERRIDEN_DRIVE_KEYS[i]); - } + MyAvatar.disableDriveKey(OVERRIDEN_DRIVE_KEYS); } this.standUp = function() { print("Standing up (" + this.entityID + ")"); MyAvatar.removeAnimationStateHandler(this.animStateHandlerID); Script.update.disconnect(this, this.update); - for (var i in OVERRIDEN_DRIVE_KEYS) { - MyAvatar.enableDriveKey(OVERRIDEN_DRIVE_KEYS[i]); - } + MyAvatar.enableDriveKey(OVERRIDEN_DRIVE_KEYS); this.setSeatUser(null); if (Settings.getValue(SETTING_KEY) === this.entityID) {