From ad389e5072efb2be5961bc014f6b99143bb47b16 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 8 Jan 2018 15:27:41 -0800 Subject: [PATCH] make avatar walk-speed adjustable from js. add a tablet button to control walking vs running --- interface/src/avatar/MyAvatar.cpp | 10 +++++++++- interface/src/avatar/MyAvatar.h | 8 ++++++++ scripts/system/run.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 scripts/system/run.js diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index de2381342d..601985ff2a 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2100,7 +2100,7 @@ void MyAvatar::updateActionMotor(float deltaTime) { _actionMotorVelocity = motorSpeed * direction; } else { // we're interacting with a floor --> simple horizontal speed and exponential decay - _actionMotorVelocity = getSensorToWorldScale() * DEFAULT_AVATAR_MAX_WALKING_SPEED * direction; + _actionMotorVelocity = getSensorToWorldScale() * _walkSpeed.get() * direction; } float boomChange = getDriveKey(ZOOM); @@ -2692,6 +2692,14 @@ float MyAvatar::getUserEyeHeight() const { return userHeight - userHeight * ratio; } +float MyAvatar::getWalkSpeed() const { + return _walkSpeed.get(); +} + +void MyAvatar::setWalkSpeed(float value) { + _walkSpeed.set(value); +} + glm::vec3 MyAvatar::getPositionForAudio() { switch (_audioListenerMode) { case AudioListenerMode::FROM_HEAD: diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index ab74460d4e..59f7cdb935 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -163,6 +163,8 @@ class MyAvatar : public Avatar { Q_PROPERTY(QUuid SELF_ID READ getSelfID CONSTANT) + Q_PROPERTY(float walkSpeed READ getWalkSpeed WRITE setWalkSpeed); + const QString DOMINANT_LEFT_HAND = "left"; const QString DOMINANT_RIGHT_HAND = "right"; @@ -557,6 +559,9 @@ public: const QUuid& getSelfID() const { return AVATAR_SELF_ID; } + void setWalkSpeed(float value); + float getWalkSpeed() const; + public slots: void increaseSize(); void decreaseSize(); @@ -841,6 +846,9 @@ private: // height of user in sensor space, when standing erect. ThreadSafeValueCache _userHeight { DEFAULT_AVATAR_HEIGHT }; + + // max unscaled forward movement speed + ThreadSafeValueCache _walkSpeed { DEFAULT_AVATAR_MAX_WALKING_SPEED }; }; QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode); diff --git a/scripts/system/run.js b/scripts/system/run.js new file mode 100644 index 0000000000..849e67e4ba --- /dev/null +++ b/scripts/system/run.js @@ -0,0 +1,28 @@ +"use strict"; + +/* global Script, Tablet, MyAvatar */ + +(function() { // BEGIN LOCAL_SCOPE + var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + var button = tablet.addButton({ + icon: Script.resolvePath("run.svg"), + text: "Run", + sortOrder: 15 + }); + + function onClicked() { + if (MyAvatar.walkSpeed < 4) { + MyAvatar.walkSpeed = 4.5; + } else { + MyAvatar.walkSpeed = 3.0; + } + } + + function cleanup() { + button.clicked.disconnect(onClicked); + tablet.removeButton(button); + } + + + button.clicked.connect(onClicked); +})