From e421141ec503a48cb58125e02bc1a3a45b573928 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 30 Jun 2015 09:52:54 -0700 Subject: [PATCH] experimenting with input plugins --- cmake/externals/sixense/CMakeLists.txt | 60 +++++++++++++++++++ interface/CMakeLists.txt | 4 +- .../resources/{ => styles}/visage/tracker.cfg | 0 interface/src/Application.cpp | 37 +++++++----- interface/src/Application.h | 5 +- interface/src/Menu.cpp | 4 +- interface/src/devices/Joystick.h | 2 +- interface/src/devices/KeyboardMouseDevice.h | 2 +- interface/src/devices/SDL2Manager.cpp | 12 ++-- interface/src/devices/SDL2Manager.h | 2 +- .../ControllerScriptingInterface.cpp | 27 +++++---- .../scripting/ControllerScriptingInterface.h | 2 +- libraries/input-plugins/CMakeLists.txt | 22 +++++++ .../src/input-plugins}/UserInputMapper.cpp | 8 +-- .../src/input-plugins}/UserInputMapper.h | 11 +++- .../input-plugins/sixense}/SixenseManager.cpp | 36 +++++++---- .../input-plugins/sixense}/SixenseManager.h | 7 ++- 17 files changed, 173 insertions(+), 68 deletions(-) create mode 100644 cmake/externals/sixense/CMakeLists.txt rename interface/resources/{ => styles}/visage/tracker.cfg (100%) create mode 100644 libraries/input-plugins/CMakeLists.txt rename {interface/src/ui => libraries/input-plugins/src/input-plugins}/UserInputMapper.cpp (98%) rename {interface/src/ui => libraries/input-plugins/src/input-plugins}/UserInputMapper.h (98%) rename {interface/src/devices => libraries/input-plugins/src/input-plugins/sixense}/SixenseManager.cpp (97%) rename {interface/src/devices => libraries/input-plugins/src/input-plugins/sixense}/SixenseManager.h (98%) diff --git a/cmake/externals/sixense/CMakeLists.txt b/cmake/externals/sixense/CMakeLists.txt new file mode 100644 index 0000000000..c80b492509 --- /dev/null +++ b/cmake/externals/sixense/CMakeLists.txt @@ -0,0 +1,60 @@ +include(ExternalProject) +include(SelectLibraryConfigurations) + +set(EXTERNAL_NAME Sixense) + +string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) + +ExternalProject_Add( + ${EXTERNAL_NAME} + URL ./SixenseSDK_062612.zip + URL_MD5 10cc8dc470d2ac1244a88cf04bc549cc + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + LOG_DOWNLOAD 1 +) + +if (APPLE) + find_library(SIXENSE_LIBRARY_RELEASE lib/osx_x64/release_dll/libsixense_x64.dylib HINTS ${SIXENSE_SEARCH_DIRS}) + find_library(SIXENSE_LIBRARY_DEBUG lib/osx_x64/debug_dll/libsixensed_x64.dylib HINTS ${SIXENSE_SEARCH_DIRS}) +elseif (UNIX) + find_library(SIXENSE_LIBRARY_RELEASE lib/linux_x64/release/libsixense_x64.so HINTS ${SIXENSE_SEARCH_DIRS}) + # find_library(SIXENSE_LIBRARY_DEBUG lib/linux_x64/debug/libsixensed_x64.so HINTS ${SIXENSE_SEARCH_DIRS}) +elseif (WIN32) +endif () + + + +ExternalProject_Get_Property(${EXTERNAL_NAME} SOURCE_DIR) + +set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${SOURCE_DIR}/include CACHE TYPE INTERNAL) + +if (WIN32) + + if ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") + set(ARCH_DIR "x64") + set(ARCH_SUFFIX "_x64") + else() + set(ARCH_DIR "Win32") + set(ARCH_SUFFIX "") + endif() + + # FIXME need to account for different architectures + set(${EXTERNAL_NAME_UPPER}_LIBRARIES "${SOURCE_DIR}/lib/${ARCH_DIR}/release_dll/sixense${ARCH_SUFFIX}.lib" CACHE TYPE INTERNAL) + add_paths_to_fixup_libs(${SOURCE_DIR}/bin/win32) + +elseif(APPLE) + + # FIXME need to account for different architectures + set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${SOURCE_DIR}/lib/osx32/libopenvr_api.dylib CACHE TYPE INTERNAL) + add_paths_to_fixup_libs(${SOURCE_DIR}/bin/osx32) + +elseif(NOT ANDROID) + + # FIXME need to account for different architectures + set(${EXTERNAL_NAME_UPPER}_LIBRARIES ${SOURCE_DIR}/lib/linux32/libopenvr_api.so CACHE TYPE INTERNAL) + add_paths_to_fixup_libs(${SOURCE_DIR}/bin/linux32) + +endif() + diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 62ccbb9935..278ad710f4 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -2,7 +2,7 @@ set(TARGET_NAME interface) project(${TARGET_NAME}) # set a default root dir for each of our optional externals if it was not passed -set(OPTIONAL_EXTERNALS "Faceshift" "Sixense" "LeapMotion" "RtMidi" "SDL2" "RSSDK") +set(OPTIONAL_EXTERNALS "Faceshift" "LeapMotion" "RtMidi" "SDL2" "RSSDK") foreach(EXTERNAL ${OPTIONAL_EXTERNALS}) string(TOUPPER ${EXTERNAL} ${EXTERNAL}_UPPERCASE) if (NOT ${${EXTERNAL}_UPPERCASE}_ROOT_DIR) @@ -128,7 +128,7 @@ target_include_directories(${TARGET_NAME} PRIVATE ${LIBOVR_INCLUDE_DIRS}) # link required hifi libraries link_hifi_libraries(shared octree environment gpu model render fbx networking entities avatars audio audio-client auto-updater animation script-engine physics - render-utils entities-renderer ui plugins display-plugins) + render-utils entities-renderer ui plugins display-plugins input-plugins) add_dependency_external_projects(sdl2) diff --git a/interface/resources/visage/tracker.cfg b/interface/resources/styles/visage/tracker.cfg similarity index 100% rename from interface/resources/visage/tracker.cfg rename to interface/resources/styles/visage/tracker.cfg diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 28efe433f5..5df5bfe82b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -73,6 +73,7 @@ #include #include #include +#include #include #include #include @@ -98,6 +99,7 @@ #include #include #include +#include #include #include "Application.h" @@ -312,6 +314,7 @@ bool setupEssentials(int& argc, char** argv) { auto autoUpdater = DependencyManager::set(); auto pathUtils = DependencyManager::set(); auto actionFactory = DependencyManager::set(); + auto userInputMapper = DependencyManager::set(); return true; } @@ -607,9 +610,12 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : this, &Application::checkSkeleton, Qt::QueuedConnection); // Setup the userInputMapper with the actions + auto userInputMapper = DependencyManager::get(); + connect(userInputMapper.data(), &UserInputMapper::actionEvent, &_controllerScriptingInterface, &AbstractControllerScriptingInterface::actionEvent); + // Setup the keyboardMouseDevice and the user input mapper with the default bindings - _keyboardMouseDevice.registerToUserInputMapper(_userInputMapper); - _keyboardMouseDevice.assignDefaultInputMapping(_userInputMapper); + _keyboardMouseDevice.registerToUserInputMapper(*userInputMapper); + _keyboardMouseDevice.assignDefaultInputMapping(*userInputMapper); // check first run... if (_firstRun.get()) { @@ -2505,7 +2511,8 @@ void Application::update(float deltaTime) { SDL2Manager::getInstance()->update(); } - _userInputMapper.update(deltaTime); + auto userInputMapper = DependencyManager::get(); + userInputMapper->update(deltaTime); _keyboardMouseDevice.update(); // Dispatch input events @@ -2515,19 +2522,19 @@ void Application::update(float deltaTime) { _myAvatar->clearDriveKeys(); if (_myCamera.getMode() != CAMERA_MODE_INDEPENDENT) { 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(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)); + _myAvatar->setDriveKeys(BOOM_IN, userInputMapper->getActionState(UserInputMapper::BOOM_IN)); + _myAvatar->setDriveKeys(BOOM_OUT, userInputMapper->getActionState(UserInputMapper::BOOM_OUT)); } updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process... diff --git a/interface/src/Application.h b/interface/src/Application.h index 0aef17a357..ad621fd42c 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -54,7 +54,7 @@ #include "Stars.h" #include "avatar/Avatar.h" #include "avatar/MyAvatar.h" -#include "devices/SixenseManager.h" +//#include "devices/SixenseManager.h" #include "scripting/ControllerScriptingInterface.h" #include "scripting/WebWindowClass.h" #include "ui/BandwidthDialog.h" @@ -69,7 +69,6 @@ #include "ui/ApplicationCompositor.h" #include "ui/RunningScriptsWidget.h" #include "ui/ToolWindow.h" -#include "ui/UserInputMapper.h" #include "devices/KeyboardMouseDevice.h" #include "octree/OctreeFade.h" #include "octree/OctreePacketProcessor.h" @@ -149,7 +148,6 @@ public: static glm::quat getOrientationForPath() { return getInstance()->_myAvatar->getOrientation(); } static glm::vec3 getPositionForAudio() { return getInstance()->_myAvatar->getHead()->getPosition(); } static glm::quat getOrientationForAudio() { return getInstance()->_myAvatar->getHead()->getFinalOrientationInWorldFrame(); } - static UserInputMapper* getUserInputMapper() { return &getInstance()->_userInputMapper; } static void initPlugins(); static void shutdownPlugins(); @@ -556,7 +554,6 @@ private: OctreeQuery _octreeQuery; // NodeData derived class for querying octee cells from octree servers KeyboardMouseDevice _keyboardMouseDevice; // Default input device, the good old keyboard mouse and maybe touchpad - UserInputMapper _userInputMapper; // User input mapper allowing to mapp different real devices to the action channels that the application has to offer MyAvatar* _myAvatar; // TODO: move this and relevant code to AvatarManager (or MyAvatar as the case may be) Camera _myCamera; // My view onto the world Camera _mirrorCamera; // Cammera for mirror view diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 311b095d1d..25b05d552b 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -30,7 +30,7 @@ #include "devices/DdeFaceTracker.h" #include "devices/Faceshift.h" #include "devices/RealSense.h" -#include "devices/SixenseManager.h" +//#include "devices/SixenseManager.h" #include "MainWindow.h" #include "scripting/MenuScriptingInterface.h" #if defined(Q_OS_MAC) || defined(Q_OS_WIN) @@ -468,6 +468,7 @@ Menu::Menu() { addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::DisplayHandTargets, 0, false); addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::ShowIKConstraints, 0, false); +#if 0 MenuWrapper* sixenseOptionsMenu = handOptionsMenu->addMenu("Sixense"); #ifdef __APPLE__ addCheckableActionToQMenuAndActionHash(sixenseOptionsMenu, @@ -490,6 +491,7 @@ Menu::Menu() { SLOT(setLowVelocityFilter(bool))); addCheckableActionToQMenuAndActionHash(sixenseOptionsMenu, MenuOption::SixenseMouseInput, 0, true); addCheckableActionToQMenuAndActionHash(sixenseOptionsMenu, MenuOption::SixenseLasers, 0, false); +#endif MenuWrapper* leapOptionsMenu = handOptionsMenu->addMenu("Leap Motion"); addCheckableActionToQMenuAndActionHash(leapOptionsMenu, MenuOption::LeapMotionOnHMD, 0, false); diff --git a/interface/src/devices/Joystick.h b/interface/src/devices/Joystick.h index c546a82aaa..74df26d8d2 100644 --- a/interface/src/devices/Joystick.h +++ b/interface/src/devices/Joystick.h @@ -20,7 +20,7 @@ #undef main #endif -#include "ui/UserInputMapper.h" +#include class Joystick : public QObject { Q_OBJECT diff --git a/interface/src/devices/KeyboardMouseDevice.h b/interface/src/devices/KeyboardMouseDevice.h index ce044b2a13..3c6eefeac3 100755 --- a/interface/src/devices/KeyboardMouseDevice.h +++ b/interface/src/devices/KeyboardMouseDevice.h @@ -14,7 +14,7 @@ #include #include -#include "ui/UserInputMapper.h" +#include class KeyboardMouseDevice { public: diff --git a/interface/src/devices/SDL2Manager.cpp b/interface/src/devices/SDL2Manager.cpp index e039a80b0d..fac0230f45 100644 --- a/interface/src/devices/SDL2Manager.cpp +++ b/interface/src/devices/SDL2Manager.cpp @@ -46,8 +46,9 @@ _isInitialized(false) if (!_openJoysticks.contains(id)) { Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller); _openJoysticks[id] = joystick; - joystick->registerToUserInputMapper(*Application::getUserInputMapper()); - joystick->assignDefaultInputMapping(*Application::getUserInputMapper()); + auto userInputMapper = DependencyManager::get(); + joystick->registerToUserInputMapper(*userInputMapper); + joystick->assignDefaultInputMapping(*userInputMapper); emit joystickAdded(joystick); } } @@ -84,6 +85,7 @@ void SDL2Manager::focusOutEvent() { void SDL2Manager::update() { #ifdef HAVE_SDL2 if (_isInitialized) { + auto userInputMapper = DependencyManager::get(); for (auto joystick : _openJoysticks) { joystick->update(); } @@ -132,14 +134,14 @@ void SDL2Manager::update() { if (!_openJoysticks.contains(id)) { Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller); _openJoysticks[id] = joystick; - joystick->registerToUserInputMapper(*Application::getUserInputMapper()); - joystick->assignDefaultInputMapping(*Application::getUserInputMapper()); + joystick->registerToUserInputMapper(*userInputMapper); + joystick->assignDefaultInputMapping(*userInputMapper); emit joystickAdded(joystick); } } else if (event.type == SDL_CONTROLLERDEVICEREMOVED) { Joystick* joystick = _openJoysticks[event.cdevice.which]; _openJoysticks.remove(event.cdevice.which); - Application::getUserInputMapper()->removeDevice(joystick->getDeviceID()); + userInputMapper->removeDevice(joystick->getDeviceID()); emit joystickRemoved(joystick); } } diff --git a/interface/src/devices/SDL2Manager.h b/interface/src/devices/SDL2Manager.h index 0a32570ee2..9ab82df374 100644 --- a/interface/src/devices/SDL2Manager.h +++ b/interface/src/devices/SDL2Manager.h @@ -16,7 +16,7 @@ #include #endif -#include "ui/UserInputMapper.h" +#include #include "devices/Joystick.h" diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index 7a3f4a99b5..0e12ba676d 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -17,7 +17,7 @@ #include "Application.h" #include "devices/MotionTracker.h" -#include "devices/SixenseManager.h" +//#include "devices/SixenseManager.h" #include "ControllerScriptingInterface.h" @@ -81,13 +81,14 @@ void inputChannelFromScriptValue(const QScriptValue& object, UserInputMapper::In QScriptValue actionToScriptValue(QScriptEngine* engine, const UserInputMapper::Action& action) { QScriptValue obj = engine->newObject(); - QVector inputChannels = Application::getUserInputMapper()->getInputChannelsForAction(action); + auto userInputMapper = DependencyManager::get(); + QVector inputChannels = userInputMapper->getInputChannelsForAction(action); QScriptValue _inputChannels = engine->newArray(inputChannels.size()); for (int i = 0; i < inputChannels.size(); i++) { _inputChannels.setProperty(i, inputChannelToScriptValue(engine, inputChannels[i])); } obj.setProperty("action", (int) action); - obj.setProperty("actionName", Application::getUserInputMapper()->getActionName(action)); + obj.setProperty("actionName", userInputMapper->getActionName(action)); obj.setProperty("inputChannels", _inputChannels); return obj; } @@ -427,43 +428,43 @@ void ControllerScriptingInterface::updateInputControllers() { } QVector ControllerScriptingInterface::getAllActions() { - return Application::getUserInputMapper()->getAllActions(); + return DependencyManager::get()->getAllActions(); } QVector ControllerScriptingInterface::getInputChannelsForAction(UserInputMapper::Action action) { - return Application::getUserInputMapper()->getInputChannelsForAction(action); + return DependencyManager::get()->getInputChannelsForAction(action); } QString ControllerScriptingInterface::getDeviceName(unsigned int device) { - return Application::getUserInputMapper()->getDeviceName((unsigned short) device); + return DependencyManager::get()->getDeviceName((unsigned short)device); } QVector ControllerScriptingInterface::getAllInputsForDevice(unsigned int device) { - return Application::getUserInputMapper()->getAllInputsForDevice(device); + return DependencyManager::get()->getAllInputsForDevice(device); } bool ControllerScriptingInterface::addInputChannel(UserInputMapper::InputChannel inputChannel) { - return Application::getUserInputMapper()->addInputChannel(inputChannel._action, inputChannel._input, inputChannel._modifier, inputChannel._scale); + return DependencyManager::get()->addInputChannel(inputChannel._action, inputChannel._input, inputChannel._modifier, inputChannel._scale); } bool ControllerScriptingInterface::removeInputChannel(UserInputMapper::InputChannel inputChannel) { - return Application::getUserInputMapper()->removeInputChannel(inputChannel); + return DependencyManager::get()->removeInputChannel(inputChannel); } QVector ControllerScriptingInterface::getAvailableInputs(unsigned int device) { - return Application::getUserInputMapper()->getAvailableInputs((unsigned short) device); + return DependencyManager::get()->getAvailableInputs((unsigned short)device); } void ControllerScriptingInterface::resetAllDeviceBindings() { - Application::getUserInputMapper()->resetAllDeviceBindings(); + DependencyManager::get()->resetAllDeviceBindings(); } void ControllerScriptingInterface::resetDevice(unsigned int device) { - Application::getUserInputMapper()->resetDevice(device); + DependencyManager::get()->resetDevice(device); } int ControllerScriptingInterface::findDevice(QString name) { - return Application::getUserInputMapper()->findDevice(name); + return DependencyManager::get()->findDevice(name); } InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) : diff --git a/interface/src/scripting/ControllerScriptingInterface.h b/interface/src/scripting/ControllerScriptingInterface.h index f15ee43ca3..d6e25f1747 100644 --- a/interface/src/scripting/ControllerScriptingInterface.h +++ b/interface/src/scripting/ControllerScriptingInterface.h @@ -14,7 +14,7 @@ #include -#include "ui/UserInputMapper.h" +#include #include class PalmData; diff --git a/libraries/input-plugins/CMakeLists.txt b/libraries/input-plugins/CMakeLists.txt new file mode 100644 index 0000000000..b3f9a590d9 --- /dev/null +++ b/libraries/input-plugins/CMakeLists.txt @@ -0,0 +1,22 @@ +set(TARGET_NAME input-plugins) + +setup_hifi_library() + +# use setup_hifi_library macro to setup our project and link appropriate Qt modules +link_hifi_libraries(shared plugins) + +GroupSources("src/input-plugins") + +add_dependency_external_projects(glm) +find_package(GLM REQUIRED) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) + +add_dependency_external_projects(OpenVR) +find_package(OpenVR REQUIRED) +target_include_directories(${TARGET_NAME} PRIVATE ${OPENVR_INCLUDE_DIRS}) +target_link_libraries(${TARGET_NAME} ${OPENVR_LIBRARIES}) + +add_dependency_external_projects(Sixense) +find_package(Sixense REQUIRED) +target_include_directories(${TARGET_NAME} PRIVATE ${SIXENSE_INCLUDE_DIRS}) +target_link_libraries(${TARGET_NAME} ${SIXENSE_LIBRARIES}) diff --git a/interface/src/ui/UserInputMapper.cpp b/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp similarity index 98% rename from interface/src/ui/UserInputMapper.cpp rename to libraries/input-plugins/src/input-plugins/UserInputMapper.cpp index 3afd09da65..a636c5dfc6 100755 --- a/interface/src/ui/UserInputMapper.cpp +++ b/libraries/input-plugins/src/input-plugins/UserInputMapper.cpp @@ -8,15 +8,9 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - -#include "Application.h" #include "UserInputMapper.h" - -// UserInputMapper Class - // Default contruct allocate the poutput size with the current hardcoded action channels UserInputMapper::UserInputMapper() { assignDefaulActionScales(); @@ -211,7 +205,7 @@ void UserInputMapper::update(float deltaTime) { for (auto i = 0; i < NUM_ACTIONS; i++) { _actionStates[i] *= _actionScales[i]; if (_actionStates[i] > 0) { - emit Application::getInstance()->getControllerScriptingInterface()->actionEvent(i, _actionStates[i]); + emit actionEvent(i, _actionStates[i]); } } } diff --git a/interface/src/ui/UserInputMapper.h b/libraries/input-plugins/src/input-plugins/UserInputMapper.h similarity index 98% rename from interface/src/ui/UserInputMapper.h rename to libraries/input-plugins/src/input-plugins/UserInputMapper.h index 800f181dcb..587208f717 100755 --- a/interface/src/ui/UserInputMapper.h +++ b/libraries/input-plugins/src/input-plugins/UserInputMapper.h @@ -13,14 +13,17 @@ #define hifi_UserInputMapper_h #include -#include #include #include #include +#include +#include + -class UserInputMapper : public QObject { +class UserInputMapper : public QObject, public Dependency { Q_OBJECT + SINGLETON_DEPENDENCY Q_ENUMS(Action) public: typedef unsigned short uint16; @@ -208,6 +211,10 @@ public: UserInputMapper(); +signals: + void actionEvent(int action, float state); + + protected: typedef std::map DevicesMap; DevicesMap _registeredDevices; diff --git a/interface/src/devices/SixenseManager.cpp b/libraries/input-plugins/src/input-plugins/sixense/SixenseManager.cpp similarity index 97% rename from interface/src/devices/SixenseManager.cpp rename to libraries/input-plugins/src/input-plugins/sixense/SixenseManager.cpp index a8e45914dd..9cd365a390 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/libraries/input-plugins/src/input-plugins/sixense/SixenseManager.cpp @@ -10,14 +10,18 @@ // #include +#include -#include #include +#include -#include "Application.h" #include "SixenseManager.h" #include "UserActivityLogger.h" -#include "InterfaceLogging.h" +#include "../UserInputMapper.h" + +Q_DECLARE_LOGGING_CATEGORY(sixense) +Q_LOGGING_CATEGORY(sixense, "hifi.devices.sixense") + // These bits aren't used for buttons, so they can be used as masks: const unsigned int LEFT_MASK = 0; @@ -152,8 +156,10 @@ void SixenseManager::setFilter(bool filter) { } void SixenseManager::update(float deltaTime) { +#if 0 #ifdef HAVE_SIXENSE Hand* hand = DependencyManager::get()->getMyAvatar()->getHand(); + auto userInputMapper = DependencyManager::get(); if (_isInitialized && _isEnabled) { _buttonPressedMap.clear(); #ifdef __APPLE__ @@ -164,7 +170,8 @@ void SixenseManager::update(float deltaTime) { if (sixenseGetNumActiveControllers() == 0) { _hydrasConnected = false; if (_deviceID != 0) { - Application::getUserInputMapper()->removeDevice(_deviceID); + + userInputMapper->removeDevice(_deviceID); _deviceID = 0; if (_prevPalms[0]) { _prevPalms[0]->setActive(false); @@ -179,8 +186,8 @@ void SixenseManager::update(float deltaTime) { PerformanceTimer perfTimer("sixense"); if (!_hydrasConnected) { _hydrasConnected = true; - registerToUserInputMapper(*Application::getUserInputMapper()); - getInstance().assignDefaultInputMapping(*Application::getUserInputMapper()); + registerToUserInputMapper(*userInputMapper); + getInstance().assignDefaultInputMapping(*userInputMapper); UserActivityLogger::getInstance().connectedDevice("spatial_controller", "hydra"); } @@ -335,6 +342,7 @@ void SixenseManager::update(float deltaTime) { } } #endif // HAVE_SIXENSE +#endif } //Constants for getCursorPixelRangeMultiplier() @@ -351,8 +359,10 @@ float SixenseManager::getCursorPixelRangeMult() const { void SixenseManager::toggleSixense(bool shouldEnable) { if (shouldEnable && !isInitialized()) { initialize(); +#if 0 setFilter(Menu::getInstance()->isOptionChecked(MenuOption::FilterSixense)); setLowVelocityFilter(Menu::getInstance()->isOptionChecked(MenuOption::LowVelocityFilter)); +#endif } setIsEnabled(shouldEnable); } @@ -395,11 +405,11 @@ void SixenseManager::updateCalibration(const sixenseControllerData* controllers) glm::vec3 zAxis = glm::normalize(glm::cross(xAxis, yAxis)); xAxis = glm::normalize(glm::cross(yAxis, zAxis)); _orbRotation = glm::inverse(glm::quat_cast(glm::mat3(xAxis, yAxis, zAxis))); - qCDebug(interfaceapp, "succeess: sixense calibration"); + qCDebug(sixense, "succeess: sixense calibration"); } break; default: - qCDebug(interfaceapp, "failed: sixense calibration"); + qCDebug(sixense, "failed: sixense calibration"); break; } @@ -418,7 +428,7 @@ void SixenseManager::updateCalibration(const sixenseControllerData* controllers) if (_calibrationState == CALIBRATION_STATE_IDLE) { float reach = glm::distance(positionLeft, positionRight); if (reach > 2.0f * MINIMUM_ARM_REACH) { - qCDebug(interfaceapp, "started: sixense calibration"); + qCDebug(sixense, "started: sixense calibration"); _averageLeft = positionLeft; _averageRight = positionRight; _reachLeft = _averageLeft; @@ -451,7 +461,7 @@ void SixenseManager::updateCalibration(const sixenseControllerData* controllers) _lastDistance = 0.0f; _reachUp = 0.5f * (_reachLeft + _reachRight); _calibrationState = CALIBRATION_STATE_Y; - qCDebug(interfaceapp, "success: sixense calibration: left"); + qCDebug(sixense, "success: sixense calibration: left"); } } else if (_calibrationState == CALIBRATION_STATE_Y) { @@ -470,7 +480,7 @@ void SixenseManager::updateCalibration(const sixenseControllerData* controllers) _lastDistance = 0.0f; _lockExpiry = now + LOCK_DURATION; _calibrationState = CALIBRATION_STATE_Z; - qCDebug(interfaceapp, "success: sixense calibration: up"); + qCDebug(sixense, "success: sixense calibration: up"); } } } @@ -492,7 +502,7 @@ void SixenseManager::updateCalibration(const sixenseControllerData* controllers) if (fabsf(_lastDistance) > 0.05f * MINIMUM_ARM_REACH) { // lock has expired so clamp the data and move on _calibrationState = CALIBRATION_STATE_COMPLETE; - qCDebug(interfaceapp, "success: sixense calibration: forward"); + qCDebug(sixense, "success: sixense calibration: forward"); // TODO: it is theoretically possible to detect that the controllers have been // accidentally switched (left hand is holding right controller) and to swap the order. } @@ -502,6 +512,7 @@ void SixenseManager::updateCalibration(const sixenseControllerData* controllers) //Injecting mouse movements and clicks void SixenseManager::emulateMouse(PalmData* palm, int index) { +#if 0 MyAvatar* avatar = DependencyManager::get()->getMyAvatar(); QPoint pos; @@ -616,6 +627,7 @@ void SixenseManager::emulateMouse(PalmData* palm, int index) { _triggerPressed[index] = false; } +#endif } #endif // HAVE_SIXENSE diff --git a/interface/src/devices/SixenseManager.h b/libraries/input-plugins/src/input-plugins/sixense/SixenseManager.h similarity index 98% rename from interface/src/devices/SixenseManager.h rename to libraries/input-plugins/src/input-plugins/sixense/SixenseManager.h index c27b3ca0e2..7cd683e06a 100644 --- a/interface/src/devices/SixenseManager.h +++ b/libraries/input-plugins/src/input-plugins/sixense/SixenseManager.h @@ -14,11 +14,14 @@ #include #include +#include "../UserInputMapper.h" + +#define HAVE_SIXENSE #ifdef HAVE_SIXENSE #include #include - #include "sixense.h" + #include #ifdef __APPLE__ #include @@ -26,8 +29,6 @@ #endif -#include "ui/UserInputMapper.h" - class PalmData; const unsigned int BUTTON_0 = 1U << 0; // the skinny button between 1 and 2