From f752534f7c166e3dcf4e453764165674771b1500 Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Thu, 18 Jun 2015 09:52:36 -0700 Subject: [PATCH 01/10] actionEvent signal, captureActions, began work on hmdControls.js --- examples/hmdControls.js | 87 +++++++++++++++++++ interface/src/Application.cpp | 22 ++--- .../ControllerScriptingInterface.cpp | 1 + .../scripting/ControllerScriptingInterface.h | 7 ++ interface/src/ui/UserInputMapper.cpp | 8 +- .../AbstractControllerScriptingInterface.h | 5 ++ 6 files changed, 119 insertions(+), 11 deletions(-) create mode 100644 examples/hmdControls.js diff --git a/examples/hmdControls.js b/examples/hmdControls.js new file mode 100644 index 0000000000..3e73decaec --- /dev/null +++ b/examples/hmdControls.js @@ -0,0 +1,87 @@ +// +// hmdControls.js +// examples +// +// Created by Sam Gondelman on 6/17/15 +// 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 MOVE_DISTANCE = 0.5; +var PITCH_INCREMENT = Math.PI / 8; +var YAW_INCREMENT = Math.PI / 8; +var BOOM_SPEED = 0.5; +var THRESHOLD = 0.2; + +var hmdControls = (function () { + + function onActionEvent(action, state) { + if (state < THRESHOLD) { + return; + } + switch (action) { + case 0: // backward + var direction = Quat.getFront(Camera.getOrientation()); + direction = Vec3.multiply(-1, direction); + direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); + MyAvatar.position = Vec3.sum(MyAvatar.position, direction); + break; + case 1: // forward + var direction = Quat.getFront(Camera.getOrientation()); + direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); + MyAvatar.position = Vec3.sum(MyAvatar.position, direction); + break; + case 2: // left + var direction = Quat.getRight(Camera.getOrientation()); + direction = Vec3.multiply(-1, direction); + direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); + MyAvatar.position = Vec3.sum(MyAvatar.position, direction); + break; + case 3: // right + var direction = Quat.getRight(Camera.getOrientation()); + direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); + MyAvatar.position = Vec3.sum(MyAvatar.position, direction); + break; + case 4: // down + var direction = Quat.getUp(Camera.getOrientation()); + direction = Vec3.multiply(-1, direction); + direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); + MyAvatar.position = Vec3.sum(MyAvatar.position, direction); + break; + case 5: // up + var direction = Quat.getUp(Camera.getOrientation()); + direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); + MyAvatar.position = Vec3.sum(MyAvatar.position, direction); + break; + case 6: // yaw left + MyAvatar.bodyYaw = MyAvatar.bodyYaw + YAW_INCREMENT; + break; + case 7: // yaw right + MyAvatar.bodyYaw = MyAvatar.bodyYaw - YAW_INCREMENT; + break; + case 8: // pitch down + MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch - PITCH_INCREMENT)); + break; + case 9: // pitch up + MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch + PITCH_INCREMENT)); + break; + default: + break; + } + } + + function setUp() { + Controller.captureActionEvents(); + + Controller.actionEvent.connect(onActionEvent); + } + + function tearDown() { + Controller.releaseActionEvents(); + } + + setUp(); + Script.scriptEnding.connect(tearDown); +}()); \ No newline at end of file diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 651e343087..ba6c86cafb 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2505,16 +2505,18 @@ void Application::update(float deltaTime) { // Transfer the user inputs to the driveKeys _myAvatar->clearDriveKeys(); - _myAvatar->setDriveKeys(FWD, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_FORWARD)); - _myAvatar->setDriveKeys(BACK, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_BACKWARD)); - _myAvatar->setDriveKeys(UP, _userInputMapper.getActionState(UserInputMapper::VERTICAL_UP)); - _myAvatar->setDriveKeys(DOWN, _userInputMapper.getActionState(UserInputMapper::VERTICAL_DOWN)); - _myAvatar->setDriveKeys(LEFT, _userInputMapper.getActionState(UserInputMapper::LATERAL_LEFT)); - _myAvatar->setDriveKeys(RIGHT, _userInputMapper.getActionState(UserInputMapper::LATERAL_RIGHT)); - _myAvatar->setDriveKeys(ROT_UP, _userInputMapper.getActionState(UserInputMapper::PITCH_UP)); - _myAvatar->setDriveKeys(ROT_DOWN, _userInputMapper.getActionState(UserInputMapper::PITCH_DOWN)); - _myAvatar->setDriveKeys(ROT_LEFT, _userInputMapper.getActionState(UserInputMapper::YAW_LEFT)); - _myAvatar->setDriveKeys(ROT_RIGHT, _userInputMapper.getActionState(UserInputMapper::YAW_RIGHT)); + if (!_controllerScriptingInterface.areActionsCaptured()) { + _myAvatar->setDriveKeys(FWD, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_FORWARD)); + _myAvatar->setDriveKeys(BACK, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_BACKWARD)); + _myAvatar->setDriveKeys(UP, _userInputMapper.getActionState(UserInputMapper::VERTICAL_UP)); + _myAvatar->setDriveKeys(DOWN, _userInputMapper.getActionState(UserInputMapper::VERTICAL_DOWN)); + _myAvatar->setDriveKeys(LEFT, _userInputMapper.getActionState(UserInputMapper::LATERAL_LEFT)); + _myAvatar->setDriveKeys(RIGHT, _userInputMapper.getActionState(UserInputMapper::LATERAL_RIGHT)); + _myAvatar->setDriveKeys(ROT_UP, _userInputMapper.getActionState(UserInputMapper::PITCH_UP)); + _myAvatar->setDriveKeys(ROT_DOWN, _userInputMapper.getActionState(UserInputMapper::PITCH_DOWN)); + _myAvatar->setDriveKeys(ROT_LEFT, _userInputMapper.getActionState(UserInputMapper::YAW_LEFT)); + _myAvatar->setDriveKeys(ROT_RIGHT, _userInputMapper.getActionState(UserInputMapper::YAW_RIGHT)); + } _myAvatar->setDriveKeys(BOOM_IN, _userInputMapper.getActionState(UserInputMapper::BOOM_IN)); _myAvatar->setDriveKeys(BOOM_OUT, _userInputMapper.getActionState(UserInputMapper::BOOM_OUT)); diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index 5bee51c9b9..0d9cf38705 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -28,6 +28,7 @@ ControllerScriptingInterface::ControllerScriptingInterface() : { } + static int actionMetaTypeId = qRegisterMetaType(); static int inputChannelMetaTypeId = qRegisterMetaType(); static int inputMetaTypeId = qRegisterMetaType(); diff --git a/interface/src/scripting/ControllerScriptingInterface.h b/interface/src/scripting/ControllerScriptingInterface.h index 3a54826195..44b59beded 100644 --- a/interface/src/scripting/ControllerScriptingInterface.h +++ b/interface/src/scripting/ControllerScriptingInterface.h @@ -72,12 +72,15 @@ public: void emitTouchUpdateEvent(const TouchEvent& event) { emit touchUpdateEvent(event); } void emitWheelEvent(QWheelEvent* event) { emit wheelEvent(*event); } + + void emitActionEvents(); bool isKeyCaptured(QKeyEvent* event) const; bool isKeyCaptured(const KeyEvent& event) const; bool isMouseCaptured() const { return _mouseCaptured; } bool isTouchCaptured() const { return _touchCaptured; } bool isWheelCaptured() const { return _wheelCaptured; } + bool areActionsCaptured() const { return _actionsCaptured; } bool isJoystickCaptured(int joystickIndex) const; void updateInputControllers(); @@ -122,6 +125,9 @@ public slots: virtual void captureWheelEvents() { _wheelCaptured = true; } virtual void releaseWheelEvents() { _wheelCaptured = false; } + + virtual void captureActionEvents() { _actionsCaptured = true; } + virtual void releaseActionEvents() { _actionsCaptured = false; } virtual void captureJoystick(int joystickIndex); virtual void releaseJoystick(int joystickIndex); @@ -142,6 +148,7 @@ private: bool _mouseCaptured; bool _touchCaptured; bool _wheelCaptured; + bool _actionsCaptured; QMultiMap _capturedKeys; QSet _capturedJoysticks; diff --git a/interface/src/ui/UserInputMapper.cpp b/interface/src/ui/UserInputMapper.cpp index 127aead761..985353e31e 100755 --- a/interface/src/ui/UserInputMapper.cpp +++ b/interface/src/ui/UserInputMapper.cpp @@ -8,9 +8,12 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "UserInputMapper.h" #include +#include "Application.h" + +#include "UserInputMapper.h" + // UserInputMapper Class @@ -207,6 +210,9 @@ void UserInputMapper::update(float deltaTime) { // Scale all the channel step with the scale for (auto i = 0; i < NUM_ACTIONS; i++) { _actionStates[i] *= _actionScales[i]; + if (_actionStates[i] > 0) { + emit Application::getInstance()->getControllerScriptingInterface()->actionEvent(i, _actionStates[i]); + } } } diff --git a/libraries/script-engine/src/AbstractControllerScriptingInterface.h b/libraries/script-engine/src/AbstractControllerScriptingInterface.h index 43076039a9..52c18bc8cf 100644 --- a/libraries/script-engine/src/AbstractControllerScriptingInterface.h +++ b/libraries/script-engine/src/AbstractControllerScriptingInterface.h @@ -83,6 +83,9 @@ public slots: virtual void captureWheelEvents() = 0; virtual void releaseWheelEvents() = 0; + + virtual void captureActionEvents() = 0; + virtual void releaseActionEvents() = 0; virtual void captureJoystick(int joystickIndex) = 0; virtual void releaseJoystick(int joystickIndex) = 0; @@ -111,6 +114,8 @@ signals: void touchUpdateEvent(const TouchEvent& event); void wheelEvent(const WheelEvent& event); + + void actionEvent(int action, float state); }; From fd0efd91ff60425b1d0c457c2734dabd5337f764 Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Thu, 18 Jun 2015 13:59:37 -0700 Subject: [PATCH 02/10] added shift action, added timers and fast mode to hmdControls.js --- examples/hmdControls.js | 82 ++++++++++++++++--- interface/src/devices/Joystick.cpp | 2 + interface/src/devices/KeyboardMouseDevice.cpp | 2 + interface/src/devices/SixenseManager.cpp | 4 + interface/src/ui/UserInputMapper.cpp | 2 + interface/src/ui/UserInputMapper.h | 2 + 6 files changed, 81 insertions(+), 13 deletions(-) diff --git a/examples/hmdControls.js b/examples/hmdControls.js index 3e73decaec..aa3990acf2 100644 --- a/examples/hmdControls.js +++ b/examples/hmdControls.js @@ -9,73 +9,129 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -var MOVE_DISTANCE = 0.5; -var PITCH_INCREMENT = Math.PI / 8; -var YAW_INCREMENT = Math.PI / 8; +var MOVE_DISTANCE = 0.3; +var PITCH_INCREMENT = 0.5; // degrees +var VR_PITCH_INCREMENT = 15.0; // degrees +var YAW_INCREMENT = 0.5; // degrees +var VR_YAW_INCREMENT = 15.0; // degrees var BOOM_SPEED = 0.5; var THRESHOLD = 0.2; +var CAMERA_UPDATE_TIME = 0.5; +var pitchTimer = CAMERA_UPDATE_TIME; +var yawTimer = CAMERA_UPDATE_TIME; + +var shifted = false; +var SHIFT_UPDATE_TIME = 0.5; +var shiftTimer = SHIFT_UPDATE_TIME; +var SHIFT_MAG = 4.0; + var hmdControls = (function () { function onActionEvent(action, state) { if (state < THRESHOLD) { + if (action == 6 || action == 7) { + yawTimer = CAMERA_UPDATE_TIME; + } else if (action == 8 || action == 9) { + pitchTimer = CAMERA_UPDATE_TIME; + } return; } switch (action) { case 0: // backward var direction = Quat.getFront(Camera.getOrientation()); direction = Vec3.multiply(-1, direction); - direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); + direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); MyAvatar.position = Vec3.sum(MyAvatar.position, direction); break; case 1: // forward var direction = Quat.getFront(Camera.getOrientation()); - direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); + direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); MyAvatar.position = Vec3.sum(MyAvatar.position, direction); break; case 2: // left var direction = Quat.getRight(Camera.getOrientation()); direction = Vec3.multiply(-1, direction); - direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); + direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); MyAvatar.position = Vec3.sum(MyAvatar.position, direction); break; case 3: // right var direction = Quat.getRight(Camera.getOrientation()); - direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); + direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); MyAvatar.position = Vec3.sum(MyAvatar.position, direction); break; case 4: // down var direction = Quat.getUp(Camera.getOrientation()); direction = Vec3.multiply(-1, direction); - direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); + direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); MyAvatar.position = Vec3.sum(MyAvatar.position, direction); break; case 5: // up var direction = Quat.getUp(Camera.getOrientation()); - direction = Vec3.multiply(Vec3.normalize(direction), MOVE_DISTANCE); + direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); MyAvatar.position = Vec3.sum(MyAvatar.position, direction); break; case 6: // yaw left - MyAvatar.bodyYaw = MyAvatar.bodyYaw + YAW_INCREMENT; + if (yawTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) { + MyAvatar.bodyYaw = MyAvatar.bodyYaw + (shifted ? SHIFT_MAG * VR_YAW_INCREMENT : VR_YAW_INCREMENT); + yawTimer = CAMERA_UPDATE_TIME; + } else if (!Menu.isOptionChecked("Enable VR Mode")) { + MyAvatar.bodyYaw = MyAvatar.bodyYaw + (shifted ? SHIFT_MAG * YAW_INCREMENT : YAW_INCREMENT); + } break; case 7: // yaw right - MyAvatar.bodyYaw = MyAvatar.bodyYaw - YAW_INCREMENT; + if (yawTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) { + MyAvatar.bodyYaw = MyAvatar.bodyYaw - (shifted ? SHIFT_MAG * VR_YAW_INCREMENT : VR_YAW_INCREMENT); + yawTimer = CAMERA_UPDATE_TIME; + } else if (!Menu.isOptionChecked("Enable VR Mode")) { + MyAvatar.bodyYaw = MyAvatar.bodyYaw - (shifted ? SHIFT_MAG * YAW_INCREMENT : YAW_INCREMENT); + } break; case 8: // pitch down - MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch - PITCH_INCREMENT)); + if (pitchTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) { + MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch - (shifted ? SHIFT_MAG * VR_PITCH_INCREMENT : VR_PITCH_INCREMENT))); + pitchTimer = CAMERA_UPDATE_TIME; + } else if (!Menu.isOptionChecked("Enable VR Mode")) { + MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch - (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT))); + } break; case 9: // pitch up - MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch + PITCH_INCREMENT)); + if (pitchTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) { + MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch + (shifted ? SHIFT_MAG * VR_PITCH_INCREMENT : VR_PITCH_INCREMENT))); + pitchTimer = CAMERA_UPDATE_TIME; + } else if (!Menu.isOptionChecked("Enable VR Mode")) { + MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch + (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT))); + } + break; + case 12: // shift + if (shiftTimer < 0.0) { + shifted = !shifted; + shiftTimer = SHIFT_UPDATE_TIME; + } break; default: break; } } + function update(dt) { + if (yawTimer >= 0.0) { + yawTimer = yawTimer - dt; + } + if (pitchTimer >= 0.0) { + pitchTimer = pitchTimer - dt; + } + if (shiftTimer >= 0.0) { + shiftTimer = shiftTimer - dt; + } + } + function setUp() { Controller.captureActionEvents(); Controller.actionEvent.connect(onActionEvent); + + Script.update.connect(update); } function tearDown() { diff --git a/interface/src/devices/Joystick.cpp b/interface/src/devices/Joystick.cpp index 07f3c4873c..fcfee85b75 100644 --- a/interface/src/devices/Joystick.cpp +++ b/interface/src/devices/Joystick.cpp @@ -210,6 +210,8 @@ void Joystick::assignDefaultInputMapping(UserInputMapper& mapper) { // Zoom mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(RIGHT_SHOULDER), makeInput(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER), BOOM_SPEED/2.0f); mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(LEFT_SHOULDER), makeInput(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER), BOOM_SPEED/2.0f); + + mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(SDL_CONTROLLER_BUTTON_LEFTSHOULDER)); #endif } diff --git a/interface/src/devices/KeyboardMouseDevice.cpp b/interface/src/devices/KeyboardMouseDevice.cpp index 9fadf7be82..e070e002c2 100755 --- a/interface/src/devices/KeyboardMouseDevice.cpp +++ b/interface/src/devices/KeyboardMouseDevice.cpp @@ -276,6 +276,8 @@ void KeyboardMouseDevice::assignDefaultInputMapping(UserInputMapper& mapper) { mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(MOUSE_AXIS_WHEEL_X_POS), BUTTON_YAW_SPEED); #endif + + mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(Qt::Key_Space)); } diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index c2a53508e3..c94dd52f4f 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -724,6 +724,10 @@ void SixenseManager::assignDefaultInputMapping(UserInputMapper& mapper) { mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(BUTTON_3, 1), BUTTON_MOVE_SPEED); mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(BUTTON_1, 1), BUTTON_MOVE_SPEED); + + mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(BUTTON_2, 0)); + mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(BUTTON_2, 1)); + } float SixenseManager::getButton(int channel) const { diff --git a/interface/src/ui/UserInputMapper.cpp b/interface/src/ui/UserInputMapper.cpp index 985353e31e..b5fcbebda6 100755 --- a/interface/src/ui/UserInputMapper.cpp +++ b/interface/src/ui/UserInputMapper.cpp @@ -247,6 +247,7 @@ void UserInputMapper::assignDefaulActionScales() { _actionScales[PITCH_UP] = 1.0f; // 1 degree per unit _actionScales[BOOM_IN] = 1.0f; // 1m per unit _actionScales[BOOM_OUT] = 1.0f; // 1m per unit + _actionStates[SHIFT] = 1.0f; // on } // This is only necessary as long as the actions are hardcoded @@ -264,4 +265,5 @@ void UserInputMapper::createActionNames() { _actionNames[PITCH_UP] = "PITCH_UP"; _actionNames[BOOM_IN] = "BOOM_IN"; _actionNames[BOOM_OUT] = "BOOM_OUT"; + _actionNames[SHIFT] = "SHIFT"; } \ No newline at end of file diff --git a/interface/src/ui/UserInputMapper.h b/interface/src/ui/UserInputMapper.h index 91aa724ea6..0093c36eec 100755 --- a/interface/src/ui/UserInputMapper.h +++ b/interface/src/ui/UserInputMapper.h @@ -139,6 +139,8 @@ public: BOOM_IN, BOOM_OUT, + + SHIFT, NUM_ACTIONS, }; From 53bbd519a3da0246156c0888ae65e63fac4e3cb1 Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Thu, 18 Jun 2015 14:37:09 -0700 Subject: [PATCH 03/10] two new customizable actions for use in js --- interface/src/devices/Joystick.cpp | 11 +++++------ interface/src/devices/KeyboardMouseDevice.cpp | 3 ++- interface/src/devices/SixenseManager.cpp | 3 +++ interface/src/ui/UserInputMapper.cpp | 4 ++++ interface/src/ui/UserInputMapper.h | 3 +++ 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/interface/src/devices/Joystick.cpp b/interface/src/devices/Joystick.cpp index fcfee85b75..8418b39712 100644 --- a/interface/src/devices/Joystick.cpp +++ b/interface/src/devices/Joystick.cpp @@ -173,9 +173,7 @@ void Joystick::assignDefaultInputMapping(UserInputMapper& mapper) { // Button controls mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(SDL_CONTROLLER_BUTTON_Y), DPAD_MOVE_SPEED); - mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(SDL_CONTROLLER_BUTTON_A), DPAD_MOVE_SPEED); - mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(SDL_CONTROLLER_BUTTON_X), JOYSTICK_YAW_SPEED); - mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(SDL_CONTROLLER_BUTTON_B), JOYSTICK_YAW_SPEED); + mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(SDL_CONTROLLER_BUTTON_X), DPAD_MOVE_SPEED); // Zoom mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(RIGHT_SHOULDER), BOOM_SPEED); @@ -203,15 +201,16 @@ void Joystick::assignDefaultInputMapping(UserInputMapper& mapper) { // Button controls mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(SDL_CONTROLLER_BUTTON_Y), makeInput(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER), DPAD_MOVE_SPEED/2.0f); - mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(SDL_CONTROLLER_BUTTON_A), makeInput(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER), DPAD_MOVE_SPEED/2.0f); - mapper.addInputChannel(UserInputMapper::YAW_LEFT, makeInput(SDL_CONTROLLER_BUTTON_X), makeInput(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_YAW_SPEED/2.0f); - mapper.addInputChannel(UserInputMapper::YAW_RIGHT, makeInput(SDL_CONTROLLER_BUTTON_B), makeInput(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER), JOYSTICK_YAW_SPEED/2.0f); + mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(SDL_CONTROLLER_BUTTON_X), makeInput(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER), DPAD_MOVE_SPEED/2.0f); // Zoom mapper.addInputChannel(UserInputMapper::BOOM_IN, makeInput(RIGHT_SHOULDER), makeInput(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER), BOOM_SPEED/2.0f); mapper.addInputChannel(UserInputMapper::BOOM_OUT, makeInput(LEFT_SHOULDER), makeInput(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER), BOOM_SPEED/2.0f); mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(SDL_CONTROLLER_BUTTON_LEFTSHOULDER)); + + mapper.addInputChannel(UserInputMapper::ACTION1, makeInput(SDL_CONTROLLER_BUTTON_B)); + mapper.addInputChannel(UserInputMapper::ACTION2, makeInput(SDL_CONTROLLER_BUTTON_A)); #endif } diff --git a/interface/src/devices/KeyboardMouseDevice.cpp b/interface/src/devices/KeyboardMouseDevice.cpp index e070e002c2..e04c27ae88 100755 --- a/interface/src/devices/KeyboardMouseDevice.cpp +++ b/interface/src/devices/KeyboardMouseDevice.cpp @@ -278,7 +278,8 @@ void KeyboardMouseDevice::assignDefaultInputMapping(UserInputMapper& mapper) { #endif mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(Qt::Key_Space)); - + mapper.addInputChannel(UserInputMapper::ACTION1, makeInput(Qt::Key_R)); + mapper.addInputChannel(UserInputMapper::ACTION2, makeInput(Qt::Key_T)); } float KeyboardMouseDevice::getButton(int channel) const { diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index c94dd52f4f..cfcc479172 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -727,6 +727,9 @@ void SixenseManager::assignDefaultInputMapping(UserInputMapper& mapper) { mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(BUTTON_2, 0)); mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(BUTTON_2, 1)); + + mapper.addInputChannel(UserInputMapper::ACTION1, makeInput(BUTTON_4, 0)); + mapper.addInputChannel(UserInputMapper::ACTION2, makeInput(BUTTON_4, 1)); } diff --git a/interface/src/ui/UserInputMapper.cpp b/interface/src/ui/UserInputMapper.cpp index b5fcbebda6..af5c98c44b 100755 --- a/interface/src/ui/UserInputMapper.cpp +++ b/interface/src/ui/UserInputMapper.cpp @@ -248,6 +248,8 @@ void UserInputMapper::assignDefaulActionScales() { _actionScales[BOOM_IN] = 1.0f; // 1m per unit _actionScales[BOOM_OUT] = 1.0f; // 1m per unit _actionStates[SHIFT] = 1.0f; // on + _actionStates[ACTION1] = 1.0f; // default + _actionStates[ACTION2] = 1.0f; // default } // This is only necessary as long as the actions are hardcoded @@ -266,4 +268,6 @@ void UserInputMapper::createActionNames() { _actionNames[BOOM_IN] = "BOOM_IN"; _actionNames[BOOM_OUT] = "BOOM_OUT"; _actionNames[SHIFT] = "SHIFT"; + _actionNames[ACTION1] = "ACTION1"; + _actionNames[ACTION2] = "ACTION2"; } \ No newline at end of file diff --git a/interface/src/ui/UserInputMapper.h b/interface/src/ui/UserInputMapper.h index 0093c36eec..800f181dcb 100755 --- a/interface/src/ui/UserInputMapper.h +++ b/interface/src/ui/UserInputMapper.h @@ -141,6 +141,9 @@ public: BOOM_OUT, SHIFT, + + ACTION1, + ACTION2, NUM_ACTIONS, }; From c84a6cbf28819dfca728bca6c301b8113fbe4930 Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Thu, 18 Jun 2015 16:05:58 -0700 Subject: [PATCH 04/10] added warping --- examples/hmdControls.js | 113 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 104 insertions(+), 9 deletions(-) diff --git a/examples/hmdControls.js b/examples/hmdControls.js index aa3990acf2..6634c48491 100644 --- a/examples/hmdControls.js +++ b/examples/hmdControls.js @@ -11,7 +11,6 @@ var MOVE_DISTANCE = 0.3; var PITCH_INCREMENT = 0.5; // degrees -var VR_PITCH_INCREMENT = 15.0; // degrees var YAW_INCREMENT = 0.5; // degrees var VR_YAW_INCREMENT = 15.0; // degrees var BOOM_SPEED = 0.5; @@ -26,6 +25,32 @@ var SHIFT_UPDATE_TIME = 0.5; var shiftTimer = SHIFT_UPDATE_TIME; var SHIFT_MAG = 4.0; +var warpActive = false; +var WARP_UPDATE_TIME = .5; +var warpTimer = WARP_UPDATE_TIME; + +var warpPosition = { x: 0, y: 0, z: 0 }; + +var WARP_SPHERE_SIZE = 1; +var warpSphere = Overlays.addOverlay("sphere", { + position: { x: 0, y: 0, z: 0 }, + size: WARP_SPHERE_SIZE, + color: { red: 0, green: 255, blue: 0 }, + alpha: 1.0, + solid: true, + visible: false, +}); + +var WARP_LINE_HEIGHT = 10; +var warpLine = Overlays.addOverlay("line3d", { + start: { x: 0, y: 0, z:0 }, + end: { x: 0, y: 0, z: 0 }, + color: { red: 0, green: 255, blue: 255}, + alpha: 1, + lineWidth: 5, + visible: false, +}); + var hmdControls = (function () { function onActionEvent(action, state) { @@ -88,18 +113,12 @@ var hmdControls = (function () { } break; case 8: // pitch down - if (pitchTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) { - MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch - (shifted ? SHIFT_MAG * VR_PITCH_INCREMENT : VR_PITCH_INCREMENT))); - pitchTimer = CAMERA_UPDATE_TIME; - } else if (!Menu.isOptionChecked("Enable VR Mode")) { + if (!Menu.isOptionChecked("Enable VR Mode")) { MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch - (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT))); } break; case 9: // pitch up - if (pitchTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) { - MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch + (shifted ? SHIFT_MAG * VR_PITCH_INCREMENT : VR_PITCH_INCREMENT))); - pitchTimer = CAMERA_UPDATE_TIME; - } else if (!Menu.isOptionChecked("Enable VR Mode")) { + if (!Menu.isOptionChecked("Enable VR Mode")) { MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch + (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT))); } break; @@ -109,6 +128,23 @@ var hmdControls = (function () { shiftTimer = SHIFT_UPDATE_TIME; } break; + case 13: // action1 = start/end warp + if (warpTimer < 0.0) { + warpActive = !warpActive; + if (!warpActive) { + finishWarp(); + } + warpTimer = WARP_UPDATE_TIME; + } + break; + case 14: // action2 = cancel warp + warpActive = false; + Overlays.editOverlay(warpSphere, { + visible: false, + }); + Overlays.editOverlay(warpLine, { + visible: false, + }); default: break; } @@ -124,6 +160,65 @@ var hmdControls = (function () { if (shiftTimer >= 0.0) { shiftTimer = shiftTimer - dt; } + if (warpTimer >= 0.0) { + warpTimer = warpTimer - dt; + } + + if (warpActive) { + updateWarp(); + } + } + + function updateWarp() { + var look = Quat.getFront(Camera.getOrientation()); + var pitch = Math.asin(look.y); + + // Get relative to looking straight down + pitch += Math.PI / 2; + + // Scale up + pitch *= 2; + var distance = pitch * pitch * pitch; + + var warpDirection = Vec3.normalize({ x: look.x, y: 0, z: look.z }); + warpPosition = Vec3.multiply(warpDirection, distance); + warpPosition = Vec3.sum(MyAvatar.position, warpPosition); + + // Commented out until ray picking can be fixed + // var pickRay = { + // origin: Vec3.sum(warpPosition, WARP_PICK_OFFSET), + // direction: { x: 0, y: -1, z: 0 } + // }; + + // var intersection = Entities.findRayIntersection(pickRay); + + // if (intersection.intersects && intersection.distance < WARP_PICK_MAX_DISTANCE) { + // // Warp 1 meter above the object - this is an approximation + // // TODO Get the actual offset to the Avatar's feet and plant them to + // // the object. + // warpPosition = Vec3.sum(intersection.intersection, { x: 0, y: 1, z:0 }); + // } + + // Adjust overlays to match warp position + Overlays.editOverlay(warpSphere, { + position: warpPosition, + visible: true, + }); + Overlays.editOverlay(warpLine, { + start: warpPosition, + end: Vec3.sum(warpPosition, { x: 0, y: WARP_LINE_HEIGHT, z: 0 }), + visible: true, + }); + } + + function finishWarp() { + Overlays.editOverlay(warpSphere, { + visible: false, + }); + Overlays.editOverlay(warpLine, { + visible: false, + }); + MyAvatar.position = warpPosition; } function setUp() { From 012a508eb2d286bbc793e89f24df07e3d82717f5 Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Thu, 18 Jun 2015 16:25:12 -0700 Subject: [PATCH 05/10] removed extraneous code --- examples/hmdControls.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/hmdControls.js b/examples/hmdControls.js index 6634c48491..9b8b0e8ea5 100644 --- a/examples/hmdControls.js +++ b/examples/hmdControls.js @@ -17,7 +17,6 @@ var BOOM_SPEED = 0.5; var THRESHOLD = 0.2; var CAMERA_UPDATE_TIME = 0.5; -var pitchTimer = CAMERA_UPDATE_TIME; var yawTimer = CAMERA_UPDATE_TIME; var shifted = false; @@ -154,9 +153,6 @@ var hmdControls = (function () { if (yawTimer >= 0.0) { yawTimer = yawTimer - dt; } - if (pitchTimer >= 0.0) { - pitchTimer = pitchTimer - dt; - } if (shiftTimer >= 0.0) { shiftTimer = shiftTimer - dt; } From decae5c1f1d50d67f2c39f76449ccfb7dd007982 Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Thu, 18 Jun 2015 18:43:47 -0700 Subject: [PATCH 06/10] finished hmdControls.js --- examples/hmdControls.js | 79 +++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/examples/hmdControls.js b/examples/hmdControls.js index 9b8b0e8ea5..803d00ef94 100644 --- a/examples/hmdControls.js +++ b/examples/hmdControls.js @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -var MOVE_DISTANCE = 0.3; +var MOVE_DISTANCE = 10.0; var PITCH_INCREMENT = 0.5; // degrees var YAW_INCREMENT = 0.5; // degrees var VR_YAW_INCREMENT = 15.0; // degrees @@ -50,52 +50,63 @@ var warpLine = Overlays.addOverlay("line3d", { visible: false, }); +var velocity = { x: 0, y: 0, z: 0 }; +var VERY_LONG_TIME = 1000000.0; + var hmdControls = (function () { + function findAction(name) { + var actions = Controller.getAllActions(); + for (var i = 0; i < actions.length; i++) { + if (actions[i].actionName == name) { + return i; + } + } + // If the action isn't found, it will default to the first available action + return 0; + } + function onActionEvent(action, state) { if (state < THRESHOLD) { - if (action == 6 || action == 7) { + if (action == findAction("YAW_LEFT") || action == findAction("YAW_RIGHT")) { yawTimer = CAMERA_UPDATE_TIME; - } else if (action == 8 || action == 9) { + } else if (action == findAction("PITCH_UP") || action == findAction("PITCH_DOWN")) { pitchTimer = CAMERA_UPDATE_TIME; } return; } switch (action) { - case 0: // backward - var direction = Quat.getFront(Camera.getOrientation()); - direction = Vec3.multiply(-1, direction); + case findAction("LONGITUDINAL_BACKWARD"): + var direction = {x: 0.0, y: 0.0, z:1.0}; direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); - MyAvatar.position = Vec3.sum(MyAvatar.position, direction); + velocity = Vec3.sum(velocity, direction); break; - case 1: // forward - var direction = Quat.getFront(Camera.getOrientation()); + case findAction("LONGITUDINAL_FORWARD"): + var direction = {x: 0.0, y: 0.0, z:-1.0}; direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); - MyAvatar.position = Vec3.sum(MyAvatar.position, direction); + velocity = Vec3.sum(velocity, direction); break; - case 2: // left - var direction = Quat.getRight(Camera.getOrientation()); - direction = Vec3.multiply(-1, direction); + case findAction("LATERAL_LEFT"): + var direction = {x:-1.0, y: 0.0, z: 0.0} direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); - MyAvatar.position = Vec3.sum(MyAvatar.position, direction); + velocity = Vec3.sum(velocity, direction); break; - case 3: // right - var direction = Quat.getRight(Camera.getOrientation()); + case findAction("LATERAL_RIGHT"): + var direction = {x:1.0, y: 0.0, z: 0.0}; direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); - MyAvatar.position = Vec3.sum(MyAvatar.position, direction); + velocity = Vec3.sum(velocity, direction); break; - case 4: // down - var direction = Quat.getUp(Camera.getOrientation()); - direction = Vec3.multiply(-1, direction); + case findAction("VERTICAL_DOWN"): + var direction = {x: 0.0, y: -1.0, z: 0.0}; direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); - MyAvatar.position = Vec3.sum(MyAvatar.position, direction); + velocity = Vec3.sum(velocity, direction); break; - case 5: // up - var direction = Quat.getUp(Camera.getOrientation()); + case findAction("VERTICAL_UP"): + var direction = {x: 0.0, y: 1.0, z: 0.0}; direction = Vec3.multiply(Vec3.normalize(direction), shifted ? SHIFT_MAG * MOVE_DISTANCE : MOVE_DISTANCE); - MyAvatar.position = Vec3.sum(MyAvatar.position, direction); + velocity = Vec3.sum(velocity, direction); break; - case 6: // yaw left + case findAction("YAW_LEFT"): if (yawTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) { MyAvatar.bodyYaw = MyAvatar.bodyYaw + (shifted ? SHIFT_MAG * VR_YAW_INCREMENT : VR_YAW_INCREMENT); yawTimer = CAMERA_UPDATE_TIME; @@ -103,7 +114,7 @@ var hmdControls = (function () { MyAvatar.bodyYaw = MyAvatar.bodyYaw + (shifted ? SHIFT_MAG * YAW_INCREMENT : YAW_INCREMENT); } break; - case 7: // yaw right + case findAction("YAW_RIGHT"): if (yawTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) { MyAvatar.bodyYaw = MyAvatar.bodyYaw - (shifted ? SHIFT_MAG * VR_YAW_INCREMENT : VR_YAW_INCREMENT); yawTimer = CAMERA_UPDATE_TIME; @@ -111,23 +122,23 @@ var hmdControls = (function () { MyAvatar.bodyYaw = MyAvatar.bodyYaw - (shifted ? SHIFT_MAG * YAW_INCREMENT : YAW_INCREMENT); } break; - case 8: // pitch down + case findAction("PITCH_DOWN"): if (!Menu.isOptionChecked("Enable VR Mode")) { MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch - (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT))); } break; - case 9: // pitch up + case findAction("PITCH_UP"): if (!Menu.isOptionChecked("Enable VR Mode")) { MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch + (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT))); } break; - case 12: // shift + case findAction("SHIFT"): // speed up if (shiftTimer < 0.0) { shifted = !shifted; shiftTimer = SHIFT_UPDATE_TIME; } break; - case 13: // action1 = start/end warp + case findAction("ACTION1"): // start/end warp if (warpTimer < 0.0) { warpActive = !warpActive; if (!warpActive) { @@ -136,7 +147,7 @@ var hmdControls = (function () { warpTimer = WARP_UPDATE_TIME; } break; - case 14: // action2 = cancel warp + case findAction("ACTION2"): // cancel warp warpActive = false; Overlays.editOverlay(warpSphere, { visible: false, @@ -163,6 +174,10 @@ var hmdControls = (function () { if (warpActive) { updateWarp(); } + + MyAvatar.motorVelocity = velocity; + MyAvatar.motorTimescale = 0.0; + velocity = { x: 0, y: 0, z: 0 }; } function updateWarp() { @@ -227,6 +242,8 @@ var hmdControls = (function () { function tearDown() { Controller.releaseActionEvents(); + MyAvatar.motorVelocity = {x:0.0, y:0.0, z:0.0} + MyAvatar.motorTimescale = VERY_LONG_TIME; } setUp(); From aab8161fa4a7c3b79ea89d5bde5d2d6e017a035d Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Thu, 18 Jun 2015 18:57:04 -0700 Subject: [PATCH 07/10] remove unused function --- interface/src/scripting/ControllerScriptingInterface.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/interface/src/scripting/ControllerScriptingInterface.h b/interface/src/scripting/ControllerScriptingInterface.h index 44b59beded..083b5fbe1a 100644 --- a/interface/src/scripting/ControllerScriptingInterface.h +++ b/interface/src/scripting/ControllerScriptingInterface.h @@ -72,8 +72,6 @@ public: void emitTouchUpdateEvent(const TouchEvent& event) { emit touchUpdateEvent(event); } void emitWheelEvent(QWheelEvent* event) { emit wheelEvent(*event); } - - void emitActionEvents(); bool isKeyCaptured(QKeyEvent* event) const; bool isKeyCaptured(const KeyEvent& event) const; From 9cfe8ecc011f07b06bf4fdde0593c49ad8ba4232 Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Thu, 18 Jun 2015 18:59:10 -0700 Subject: [PATCH 08/10] added hmdControls.js to hmdDefaults.js --- examples/hmdDefaults.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/hmdDefaults.js b/examples/hmdDefaults.js index 0096b11777..2b5f333644 100644 --- a/examples/hmdDefaults.js +++ b/examples/hmdDefaults.js @@ -13,4 +13,5 @@ Script.load("progress.js"); Script.load("lobby.js"); Script.load("notifications.js"); Script.load("controllers/oculus/goTo.js"); +Script.load("hmdControls.js"); //Script.load("scripts.js"); // Not created yet From e78ce8055acfa74259da7abd4455f976f83ed1ab Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Fri, 19 Jun 2015 11:17:36 -0700 Subject: [PATCH 09/10] hmdControls turns on when you enter VR mode, turns off when you exit, can toggle with CTRL+G --- examples/defaultScripts.js | 1 + examples/hmdControls.js | 58 ++++++++++++++++++++++++------ interface/src/devices/Joystick.cpp | 2 +- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/examples/defaultScripts.js b/examples/defaultScripts.js index 601b5254df..7bd108f86c 100644 --- a/examples/defaultScripts.js +++ b/examples/defaultScripts.js @@ -19,4 +19,5 @@ Script.load("grab.js"); Script.load("pointer.js"); Script.load("directory.js"); Script.load("mouseLook.js"); +Script.load("hmdControls.js"); Script.load("dialTone.js"); diff --git a/examples/hmdControls.js b/examples/hmdControls.js index 803d00ef94..9efcbc9db9 100644 --- a/examples/hmdControls.js +++ b/examples/hmdControls.js @@ -11,8 +11,10 @@ var MOVE_DISTANCE = 10.0; var PITCH_INCREMENT = 0.5; // degrees +var pitchChange = 0; // degrees var YAW_INCREMENT = 0.5; // degrees var VR_YAW_INCREMENT = 15.0; // degrees +var yawChange = 0; var BOOM_SPEED = 0.5; var THRESHOLD = 0.2; @@ -53,8 +55,17 @@ var warpLine = Overlays.addOverlay("line3d", { var velocity = { x: 0, y: 0, z: 0 }; var VERY_LONG_TIME = 1000000.0; +var active = Menu.isOptionChecked("Enable VR Mode"); +var prevVRMode = Menu.isOptionChecked("Enable VR Mode"); + var hmdControls = (function () { + function onKeyPressEvent(event) { + if (event.text == 'g' && event.isMeta) { + active = !active; + } + } + function findAction(name) { var actions = Controller.getAllActions(); for (var i = 0; i < actions.length; i++) { @@ -67,6 +78,9 @@ var hmdControls = (function () { } function onActionEvent(action, state) { + if (!active) { + return; + } if (state < THRESHOLD) { if (action == findAction("YAW_LEFT") || action == findAction("YAW_RIGHT")) { yawTimer = CAMERA_UPDATE_TIME; @@ -108,28 +122,28 @@ var hmdControls = (function () { break; case findAction("YAW_LEFT"): if (yawTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) { - MyAvatar.bodyYaw = MyAvatar.bodyYaw + (shifted ? SHIFT_MAG * VR_YAW_INCREMENT : VR_YAW_INCREMENT); + yawChange = yawChange + (shifted ? SHIFT_MAG * VR_YAW_INCREMENT : VR_YAW_INCREMENT); yawTimer = CAMERA_UPDATE_TIME; } else if (!Menu.isOptionChecked("Enable VR Mode")) { - MyAvatar.bodyYaw = MyAvatar.bodyYaw + (shifted ? SHIFT_MAG * YAW_INCREMENT : YAW_INCREMENT); + yawChange = yawChange + (shifted ? SHIFT_MAG * YAW_INCREMENT : YAW_INCREMENT); } break; case findAction("YAW_RIGHT"): if (yawTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) { - MyAvatar.bodyYaw = MyAvatar.bodyYaw - (shifted ? SHIFT_MAG * VR_YAW_INCREMENT : VR_YAW_INCREMENT); + yawChange = yawChange - (shifted ? SHIFT_MAG * VR_YAW_INCREMENT : VR_YAW_INCREMENT); yawTimer = CAMERA_UPDATE_TIME; } else if (!Menu.isOptionChecked("Enable VR Mode")) { - MyAvatar.bodyYaw = MyAvatar.bodyYaw - (shifted ? SHIFT_MAG * YAW_INCREMENT : YAW_INCREMENT); + yawChange = yawChange - (shifted ? SHIFT_MAG * YAW_INCREMENT : YAW_INCREMENT); } break; case findAction("PITCH_DOWN"): if (!Menu.isOptionChecked("Enable VR Mode")) { - MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch - (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT))); + pitchChange = pitchChange - (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT); } break; case findAction("PITCH_UP"): if (!Menu.isOptionChecked("Enable VR Mode")) { - MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch + (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT))); + pitchChange = pitchChange + (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT); } break; case findAction("SHIFT"): // speed up @@ -161,6 +175,11 @@ var hmdControls = (function () { } function update(dt) { + if (prevVRMode != Menu.isOptionChecked("Enable VR Mode")) { + active = Menu.isOptionChecked("Enable VR Mode"); + prevVRMode = Menu.isOptionChecked("Enable VR Mode"); + } + if (yawTimer >= 0.0) { yawTimer = yawTimer - dt; } @@ -175,9 +194,28 @@ var hmdControls = (function () { updateWarp(); } - MyAvatar.motorVelocity = velocity; - MyAvatar.motorTimescale = 0.0; - velocity = { x: 0, y: 0, z: 0 }; + if (active) { + Controller.captureActionEvents(); + + print(yawChange); + print(pitchChange); + print(JSON.stringify(velocity)); + + MyAvatar.bodyYaw = MyAvatar.bodyYaw + yawChange; + MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch + pitchChange)); + yawChange = 0; + pitchChange = 0; + + MyAvatar.motorVelocity = velocity; + MyAvatar.motorTimescale = 0.0; + velocity = { x: 0, y: 0, z: 0 }; + } else { + Controller.releaseActionEvents(); + yawChange = 0; + pitchChange = 0; + MyAvatar.motorVelocity = {x:0.0, y:0.0, z:0.0} + MyAvatar.motorTimescale = VERY_LONG_TIME; + } } function updateWarp() { @@ -233,7 +271,7 @@ var hmdControls = (function () { } function setUp() { - Controller.captureActionEvents(); + Controller.keyPressEvent.connect(onKeyPressEvent); Controller.actionEvent.connect(onActionEvent); diff --git a/interface/src/devices/Joystick.cpp b/interface/src/devices/Joystick.cpp index 8418b39712..91f3b98bac 100644 --- a/interface/src/devices/Joystick.cpp +++ b/interface/src/devices/Joystick.cpp @@ -17,7 +17,7 @@ #include "Joystick.h" -const float CONTROLLER_THRESHOLD = 0.25f; +const float CONTROLLER_THRESHOLD = 0.3f; #ifdef HAVE_SDL2 const float MAX_AXIS = 32768.0f; From a0d4b7ec7c918066beb0ae70097640162c244705 Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Fri, 19 Jun 2015 16:11:43 -0700 Subject: [PATCH 10/10] without script, doesn't limit you to constant degree turns --- examples/hmdControls.js | 4 ---- interface/src/avatar/MyAvatar.cpp | 26 +++----------------------- interface/src/avatar/MyAvatar.h | 1 - 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/examples/hmdControls.js b/examples/hmdControls.js index 9efcbc9db9..e14ddca3ef 100644 --- a/examples/hmdControls.js +++ b/examples/hmdControls.js @@ -197,10 +197,6 @@ var hmdControls = (function () { if (active) { Controller.captureActionEvents(); - print(yawChange); - print(pitchChange); - print(JSON.stringify(velocity)); - MyAvatar.bodyYaw = MyAvatar.bodyYaw + yawChange; MyAvatar.headPitch = Math.max(-180, Math.min(180, MyAvatar.headPitch + pitchChange)); yawChange = 0; diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 586e7a1f56..148d9cc08c 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -76,7 +76,6 @@ const float MyAvatar::ZOOM_DEFAULT = 1.5f; MyAvatar::MyAvatar() : Avatar(), - _turningKeyPressTime(0.0f), _gravity(0.0f, 0.0f, 0.0f), _wasPushing(false), _isPushing(false), @@ -1205,28 +1204,9 @@ bool MyAvatar::shouldRenderHead(const RenderArgs* renderArgs, const glm::vec3& c } void MyAvatar::updateOrientation(float deltaTime) { - // Gather rotation information from keyboard - const float TIME_BETWEEN_HMD_TURNS = 0.5f; - const float HMD_TURN_DEGREES = 22.5f; - if (!qApp->isHMDMode()) { - // Smoothly rotate body with arrow keys if not in HMD - _bodyYawDelta -= _driveKeys[ROT_RIGHT] * YAW_SPEED * deltaTime; - _bodyYawDelta += _driveKeys[ROT_LEFT] * YAW_SPEED * deltaTime; - } else { - // Jump turns if in HMD - if (_driveKeys[ROT_RIGHT] || _driveKeys[ROT_LEFT]) { - if (_turningKeyPressTime == 0.0f) { - setOrientation(getOrientation() * - glm::quat(glm::radians(glm::vec3(0.f, _driveKeys[ROT_LEFT] ? HMD_TURN_DEGREES : -HMD_TURN_DEGREES, 0.0f)))); - } - _turningKeyPressTime += deltaTime; - if (_turningKeyPressTime > TIME_BETWEEN_HMD_TURNS) { - _turningKeyPressTime = 0.0f; - } - } else { - _turningKeyPressTime = 0.0f; - } - } + // Smoothly rotate body with arrow keys + _bodyYawDelta -= _driveKeys[ROT_RIGHT] * YAW_SPEED * deltaTime; + _bodyYawDelta += _driveKeys[ROT_LEFT] * YAW_SPEED * deltaTime; getHead()->setBasePitch(getHead()->getBasePitch() + (_driveKeys[ROT_UP] - _driveKeys[ROT_DOWN]) * PITCH_SPEED * deltaTime); // update body orientation by movement inputs diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 7adaf908f4..c4a9362fef 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -210,7 +210,6 @@ private: virtual void setFaceModelURL(const QUrl& faceModelURL); virtual void setSkeletonModelURL(const QUrl& skeletonModelURL); - float _turningKeyPressTime; glm::vec3 _gravity; float _driveKeys[MAX_DRIVE_KEYS];