From f5c690cc8d7baee9dc5e6ec0987a3c81c92b1017 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 7 Jul 2014 09:32:24 -0700 Subject: [PATCH] Add Leapmotion support for Apple build - Add LEapmotion support in the CMake files - fix a template syntax in DeviceHEader not compiling on mac - add a missing #ifdef protection in Leapmotion --- cmake/modules/FindLeapMotion.cmake | 3 +++ interface/CMakeLists.txt | 4 ++++ interface/src/devices/DeviceTracker.cpp | 3 ++- interface/src/devices/DeviceTracker.h | 22 ++++++++++------------ interface/src/devices/Leapmotion.cpp | 8 +++++--- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/cmake/modules/FindLeapMotion.cmake b/cmake/modules/FindLeapMotion.cmake index d1c0c81773..0200f5d475 100644 --- a/cmake/modules/FindLeapMotion.cmake +++ b/cmake/modules/FindLeapMotion.cmake @@ -23,6 +23,9 @@ else (LEAPMOTION_LIBRARIES AND LEAPMOTION_INCLUDE_DIRS) if (WIN32) find_library(LEAPMOTION_LIBRARIES Leap.lib ${LEAPMOTION_ROOT_DIR}/lib/x86) endif (WIN32) + if (APPLE) + find_library(LEAPMOTION_LIBRARIES libLeap.dylib ${LEAPMOTION_ROOT_DIR}/lib) + endif (OSX) if (LEAPMOTION_INCLUDE_DIRS AND LEAPMOTION_LIBRARIES) set(LEAPMOTION_FOUND TRUE) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 302c19b015..04b2b786be 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -214,6 +214,10 @@ endif (PRIOVR_FOUND AND NOT DISABLE_PRIOVR) if (LEAPMOTION_FOUND AND NOT DISABLE_LEAPMOTION) add_definitions(-DHAVE_LEAPMOTION) include_directories(SYSTEM "${LEAPMOTION_INCLUDE_DIRS}") + + if (APPLE OR UNIX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${LEAPMOTION_INCLUDE_DIRS}") + endif () target_link_libraries(${TARGET_NAME} "${LEAPMOTION_LIBRARIES}") endif (LEAPMOTION_FOUND AND NOT DISABLE_LEAPMOTION) diff --git a/interface/src/devices/DeviceTracker.cpp b/interface/src/devices/DeviceTracker.cpp index 4ae5b7995f..d6c54dc435 100644 --- a/interface/src/devices/DeviceTracker.cpp +++ b/interface/src/devices/DeviceTracker.cpp @@ -12,7 +12,8 @@ #include "DeviceTracker.h" // The singleton managing the connected devices -DeviceTracker::Singleton DeviceTracker::Singleton::_singleton; +//template <> DeviceTracker::Singleton DeviceTracker::Singleton::_singleton; +//TemplateSingleton::_singleton; int DeviceTracker::init() { return Singleton::get()->_devicesMap.size(); diff --git a/interface/src/devices/DeviceTracker.h b/interface/src/devices/DeviceTracker.h index e7e2d287dd..8a02246cd3 100644 --- a/interface/src/devices/DeviceTracker.h +++ b/interface/src/devices/DeviceTracker.h @@ -18,16 +18,11 @@ //-------------------------------------------------------------------------------------- // Singleton template class //-------------------------------------------------------------------------------------- -template < class T > -class TemplateSingleton -{ - static TemplateSingleton< T > _singleton; - T* _one; - +template < typename T > +class TemplateSingleton { public: - static T* get() - { + static T* get() { if ( !_singleton._one ) { _singleton._one = new T(); } @@ -38,14 +33,18 @@ public: _one(0) { } - ~TemplateSingleton() - { + ~TemplateSingleton() { if ( _one ) { delete _one; _one = 0; } } +private: + static TemplateSingleton< T > _singleton; + T* _one; }; +template +TemplateSingleton TemplateSingleton::_singleton; /// Base class for device trackers. class DeviceTracker : public QObject { @@ -78,8 +77,7 @@ protected: private: - struct SingletonData - { + struct SingletonData { typedef std::map< Name, int > Map; typedef std::vector< DeviceTracker* > Vector; Map _devicesMap; diff --git a/interface/src/devices/Leapmotion.cpp b/interface/src/devices/Leapmotion.cpp index a21a5ea5c4..ea49a656c0 100644 --- a/interface/src/devices/Leapmotion.cpp +++ b/interface/src/devices/Leapmotion.cpp @@ -323,8 +323,8 @@ void Leapmotion::update() { // Get the most recent frame and report some basic information const Leap::Frame frame = _controller.frame(); - static _int64 lastFrame = -1; - _int64 newFrameNb = frame.id(); + static int64_t lastFrame = -1; + int64_t newFrameNb = frame.id(); if ( (lastFrame >= newFrameNb) ) return; @@ -460,7 +460,8 @@ void Leapmotion::update() { } void Leapmotion::reset() { - // By default we assume the _neckBase (in orb frame) is as high above the orb +#ifdef HAVE_LEAPMOTION + // By default we assume the _neckBase (in orb frame) is as high above the orb // as the "torso" is below it. _leapBasePos = glm::vec3(0, -LEAP_Y, LEAP_Z); @@ -469,6 +470,7 @@ void Leapmotion::reset() { glm::vec3 zAxis = glm::normalize(glm::cross(xAxis, yAxis)); xAxis = glm::normalize(glm::cross(yAxis, zAxis)); _leapBaseOri = glm::inverse(glm::quat_cast(glm::mat3(xAxis, yAxis, zAxis))); +#endif } void Leapmotion::updateEnabled() {