From 0231ed133cae4af1ae2df74e9c62f9d3e7773a4b Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Mon, 18 Nov 2013 12:09:52 -0800 Subject: [PATCH] Optional compilation for Sixense. --- cmake/modules/FindSixense.cmake | 4 ++-- interface/CMakeLists.txt | 10 ++++++++-- interface/external/Sixense/readme.txt | 11 +++++++++++ interface/src/devices/SixenseManager.cpp | 25 ++++++++++++++++++++---- 4 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 interface/external/Sixense/readme.txt diff --git a/cmake/modules/FindSixense.cmake b/cmake/modules/FindSixense.cmake index b8692d4fb5..cf23b2218c 100644 --- a/cmake/modules/FindSixense.cmake +++ b/cmake/modules/FindSixense.cmake @@ -19,9 +19,9 @@ else (SIXENSE_LIBRARIES AND SIXENSE_INCLUDE_DIRS) find_path(SIXENSE_INCLUDE_DIRS sixense.h ${SIXENSE_ROOT_DIR}/include) if (APPLE) - find_library(SIXENSE_LIBRARIES libsixense.dylib ${SIXENSE_ROOT_DIR}/lib/MacOS/) + find_library(SIXENSE_LIBRARIES libsixense_x64.dylib ${SIXENSE_ROOT_DIR}/lib/osx_x64/release_dll) elseif (UNIX) - find_library(SIXENSE_LIBRARIES libsixense_x64.so ${SIXENSE_ROOT_DIR}/lib/UNIX/) + find_library(SIXENSE_LIBRARIES libsixense_x64.so ${SIXENSE_ROOT_DIR}/lib/linux_x64/release) endif () if (SIXENSE_INCLUDE_DIRS AND SIXENSE_LIBRARIES) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 6629398bf7..735989dfbf 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -108,6 +108,14 @@ if (OPENNI_FOUND AND NOT DISABLE_OPENNI) target_link_libraries(${TARGET_NAME} ${OPENNI_LIBRARIES}) endif (OPENNI_FOUND AND NOT DISABLE_OPENNI) +# likewise with Sixense library for Razer Hydra +if (SIXENSE_FOUND AND NOT DISABLE_SIXENSE) + add_definitions(-DHAVE_SIXENSE) + include_directories(SYSTEM ${SIXENSE_INCLUDE_DIRS}) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${SIXENSE_INCLUDE_DIRS}") + target_link_libraries(${TARGET_NAME} ${SIXENSE_LIBRARIES}) +endif (SIXENSE_FOUND AND NOT DISABLE_SIXENSE) + qt5_use_modules(${TARGET_NAME} Core Gui Multimedia Network OpenGL Svg WebKit WebKitWidgets) # include headers for interface and InterfaceConfig. @@ -127,7 +135,6 @@ include_directories( ${LEAP_INCLUDE_DIRS} ${MOTIONDRIVER_INCLUDE_DIRS} ${OPENCV_INCLUDE_DIRS} - ${SIXENSE_INCLUDE_DIRS} ) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${OPENCV_INCLUDE_DIRS}") @@ -138,7 +145,6 @@ target_link_libraries( ${MOTIONDRIVER_LIBRARIES} ${OPENCV_LIBRARIES} ${ZLIB_LIBRARIES} - ${SIXENSE_LIBRARIES} ) if (APPLE) diff --git a/interface/external/Sixense/readme.txt b/interface/external/Sixense/readme.txt new file mode 100644 index 0000000000..4672765b25 --- /dev/null +++ b/interface/external/Sixense/readme.txt @@ -0,0 +1,11 @@ + +Instructions for adding the Sixense driver to Interface +Andrzej Kapolka, November 18, 2013 + +NOTE: Without doing step 2, you will crash at program start time. + +1. Copy the Sixense sdk folders (lib, include) into the interface/external/Sixense folder. This readme.txt should be there as well. + +2. IMPORTANT: Copy the file interface/external/Leap/lib/libc++/libLeap.dylib to /usr/lib + +3. Delete your build directory, run cmake and build, and you should be all set. diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index 24110da227..96481db4c8 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -6,20 +6,27 @@ // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. // -#include "sixense.h" +#ifdef HAVE_SIXENSE + #include "sixense.h" +#endif #include "Application.h" #include "SixenseManager.h" SixenseManager::SixenseManager() { +#ifdef HAVE_SIXENSE sixenseInit(); +#endif } SixenseManager::~SixenseManager() { +#ifdef HAVE_SIXENSE sixenseExit(); +#endif } void SixenseManager::update() { +#ifdef HAVE_SIXENSE if (sixenseGetNumActiveControllers() == 0) { return; } @@ -33,21 +40,31 @@ void SixenseManager::update() { } sixenseControllerData data; sixenseGetNewestData(i, &data); + + // set palm position and normal based on Hydra position/orientation PalmData palm(&hand); palm.setActive(true); glm::vec3 position(-data.pos[0], data.pos[1], -data.pos[2]); palm.setRawPosition(position); glm::quat rotation(data.rot_quat[3], -data.rot_quat[0], data.rot_quat[1], -data.rot_quat[2]); - palm.setRawNormal(rotation * glm::vec3(0.0f, -1.0f, 0.0f)); + const glm::vec3 PALM_VECTOR(0.0f, -1.0f, 0.0f); + palm.setRawNormal(rotation * PALM_VECTOR); + + // initialize the "finger" based on the direction FingerData finger(&palm, &hand); finger.setActive(true); finger.setRawRootPosition(position); - finger.setRawTipPosition(position + rotation * glm::vec3(0.0f, 0.0f, 100.0f)); + const glm::vec3 FINGER_VECTOR(0.0f, 0.0f, 100.0f); + finger.setRawTipPosition(position + rotation * FINGER_VECTOR); + + // three fingers indicates to the skeleton that we have enough data to determine direction palm.getFingers().clear(); palm.getFingers().push_back(finger); palm.getFingers().push_back(finger); palm.getFingers().push_back(finger); + hand.getPalms().push_back(palm); - } + } +#endif }