diff --git a/examples/defaultScripts.js b/examples/defaultScripts.js index d9f19c6a4c..fb76b62dbe 100644 --- a/examples/defaultScripts.js +++ b/examples/defaultScripts.js @@ -18,4 +18,5 @@ Script.load("users.js"); Script.load("grab.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 new file mode 100644 index 0000000000..e14ddca3ef --- /dev/null +++ b/examples/hmdControls.js @@ -0,0 +1,285 @@ +// +// 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 = 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; + +var CAMERA_UPDATE_TIME = 0.5; +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 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 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++) { + 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 (!active) { + return; + } + if (state < THRESHOLD) { + if (action == findAction("YAW_LEFT") || action == findAction("YAW_RIGHT")) { + yawTimer = CAMERA_UPDATE_TIME; + } else if (action == findAction("PITCH_UP") || action == findAction("PITCH_DOWN")) { + pitchTimer = CAMERA_UPDATE_TIME; + } + return; + } + switch (action) { + 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); + velocity = Vec3.sum(velocity, direction); + break; + 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); + velocity = Vec3.sum(velocity, direction); + break; + 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); + velocity = Vec3.sum(velocity, direction); + break; + 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); + velocity = Vec3.sum(velocity, direction); + break; + 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); + velocity = Vec3.sum(velocity, direction); + break; + 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); + velocity = Vec3.sum(velocity, direction); + break; + case findAction("YAW_LEFT"): + if (yawTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) { + yawChange = yawChange + (shifted ? SHIFT_MAG * VR_YAW_INCREMENT : VR_YAW_INCREMENT); + yawTimer = CAMERA_UPDATE_TIME; + } else if (!Menu.isOptionChecked("Enable VR Mode")) { + yawChange = yawChange + (shifted ? SHIFT_MAG * YAW_INCREMENT : YAW_INCREMENT); + } + break; + case findAction("YAW_RIGHT"): + if (yawTimer < 0.0 && Menu.isOptionChecked("Enable VR Mode")) { + yawChange = yawChange - (shifted ? SHIFT_MAG * VR_YAW_INCREMENT : VR_YAW_INCREMENT); + yawTimer = CAMERA_UPDATE_TIME; + } else if (!Menu.isOptionChecked("Enable VR Mode")) { + yawChange = yawChange - (shifted ? SHIFT_MAG * YAW_INCREMENT : YAW_INCREMENT); + } + break; + case findAction("PITCH_DOWN"): + if (!Menu.isOptionChecked("Enable VR Mode")) { + pitchChange = pitchChange - (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT); + } + break; + case findAction("PITCH_UP"): + if (!Menu.isOptionChecked("Enable VR Mode")) { + pitchChange = pitchChange + (shifted ? SHIFT_MAG * PITCH_INCREMENT : PITCH_INCREMENT); + } + break; + case findAction("SHIFT"): // speed up + if (shiftTimer < 0.0) { + shifted = !shifted; + shiftTimer = SHIFT_UPDATE_TIME; + } + break; + case findAction("ACTION1"): // start/end warp + if (warpTimer < 0.0) { + warpActive = !warpActive; + if (!warpActive) { + finishWarp(); + } + warpTimer = WARP_UPDATE_TIME; + } + break; + case findAction("ACTION2"): // cancel warp + warpActive = false; + Overlays.editOverlay(warpSphere, { + visible: false, + }); + Overlays.editOverlay(warpLine, { + visible: false, + }); + default: + break; + } + } + + 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; + } + if (shiftTimer >= 0.0) { + shiftTimer = shiftTimer - dt; + } + if (warpTimer >= 0.0) { + warpTimer = warpTimer - dt; + } + + if (warpActive) { + updateWarp(); + } + + if (active) { + Controller.captureActionEvents(); + + 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() { + 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() { + Controller.keyPressEvent.connect(onKeyPressEvent); + + Controller.actionEvent.connect(onActionEvent); + + Script.update.connect(update); + } + + function tearDown() { + Controller.releaseActionEvents(); + MyAvatar.motorVelocity = {x:0.0, y:0.0, z:0.0} + MyAvatar.motorTimescale = VERY_LONG_TIME; + } + + setUp(); + Script.scriptEnding.connect(tearDown); +}()); \ No newline at end of file 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 diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a2b5cc8b00..bde557c430 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2451,16 +2451,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/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 16cba72fcb..6904a1f975 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 618184cce8..948cec9eb1 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]; diff --git a/interface/src/devices/Joystick.cpp b/interface/src/devices/Joystick.cpp index 07f3c4873c..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; @@ -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,13 +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 9fadf7be82..e04c27ae88 100755 --- a/interface/src/devices/KeyboardMouseDevice.cpp +++ b/interface/src/devices/KeyboardMouseDevice.cpp @@ -276,7 +276,10 @@ 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)); + 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 c16611d2e8..12b6f4263b 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -732,6 +732,13 @@ 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)); + + mapper.addInputChannel(UserInputMapper::ACTION1, makeInput(BUTTON_4, 0)); + mapper.addInputChannel(UserInputMapper::ACTION2, makeInput(BUTTON_4, 1)); + } float SixenseManager::getButton(int channel) const { diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index 851c523c5d..7a3f4a99b5 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 392891c676..f15ee43ca3 100644 --- a/interface/src/scripting/ControllerScriptingInterface.h +++ b/interface/src/scripting/ControllerScriptingInterface.h @@ -79,6 +79,7 @@ public: 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(); @@ -123,6 +124,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); @@ -143,6 +147,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 fd2f384fb6..3afd09da65 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]); + } } } @@ -241,6 +247,9 @@ 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 + _actionStates[ACTION1] = 1.0f; // default + _actionStates[ACTION2] = 1.0f; // default } // This is only necessary as long as the actions are hardcoded @@ -258,4 +267,7 @@ void UserInputMapper::createActionNames() { _actionNames[PITCH_UP] = "PITCH_UP"; _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 91aa724ea6..800f181dcb 100755 --- a/interface/src/ui/UserInputMapper.h +++ b/interface/src/ui/UserInputMapper.h @@ -139,6 +139,11 @@ public: BOOM_IN, BOOM_OUT, + + SHIFT, + + ACTION1, + ACTION2, NUM_ACTIONS, }; diff --git a/libraries/script-engine/src/AbstractControllerScriptingInterface.h b/libraries/script-engine/src/AbstractControllerScriptingInterface.h index f0ae3bbacb..b44e13f012 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; @@ -112,6 +115,8 @@ signals: void touchUpdateEvent(const TouchEvent& event); void wheelEvent(const WheelEvent& event); + + void actionEvent(int action, float state); };