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
This commit is contained in:
samcake 2014-07-07 09:32:24 -07:00
parent d56ab21192
commit f5c690cc8d
5 changed files with 24 additions and 16 deletions

View file

@ -23,6 +23,9 @@ else (LEAPMOTION_LIBRARIES AND LEAPMOTION_INCLUDE_DIRS)
if (WIN32) if (WIN32)
find_library(LEAPMOTION_LIBRARIES Leap.lib ${LEAPMOTION_ROOT_DIR}/lib/x86) find_library(LEAPMOTION_LIBRARIES Leap.lib ${LEAPMOTION_ROOT_DIR}/lib/x86)
endif (WIN32) endif (WIN32)
if (APPLE)
find_library(LEAPMOTION_LIBRARIES libLeap.dylib ${LEAPMOTION_ROOT_DIR}/lib)
endif (OSX)
if (LEAPMOTION_INCLUDE_DIRS AND LEAPMOTION_LIBRARIES) if (LEAPMOTION_INCLUDE_DIRS AND LEAPMOTION_LIBRARIES)
set(LEAPMOTION_FOUND TRUE) set(LEAPMOTION_FOUND TRUE)

View file

@ -214,6 +214,10 @@ endif (PRIOVR_FOUND AND NOT DISABLE_PRIOVR)
if (LEAPMOTION_FOUND AND NOT DISABLE_LEAPMOTION) if (LEAPMOTION_FOUND AND NOT DISABLE_LEAPMOTION)
add_definitions(-DHAVE_LEAPMOTION) add_definitions(-DHAVE_LEAPMOTION)
include_directories(SYSTEM "${LEAPMOTION_INCLUDE_DIRS}") 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}") target_link_libraries(${TARGET_NAME} "${LEAPMOTION_LIBRARIES}")
endif (LEAPMOTION_FOUND AND NOT DISABLE_LEAPMOTION) endif (LEAPMOTION_FOUND AND NOT DISABLE_LEAPMOTION)

View file

@ -12,7 +12,8 @@
#include "DeviceTracker.h" #include "DeviceTracker.h"
// The singleton managing the connected devices // The singleton managing the connected devices
DeviceTracker::Singleton DeviceTracker::Singleton::_singleton; //template <> DeviceTracker::Singleton DeviceTracker::Singleton::_singleton;
//TemplateSingleton<DeviceTracker::SingletonData>::_singleton;
int DeviceTracker::init() { int DeviceTracker::init() {
return Singleton::get()->_devicesMap.size(); return Singleton::get()->_devicesMap.size();

View file

@ -18,16 +18,11 @@
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Singleton template class // Singleton template class
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
template < class T > template < typename T >
class TemplateSingleton class TemplateSingleton {
{
static TemplateSingleton< T > _singleton;
T* _one;
public: public:
static T* get() static T* get() {
{
if ( !_singleton._one ) { if ( !_singleton._one ) {
_singleton._one = new T(); _singleton._one = new T();
} }
@ -38,14 +33,18 @@ public:
_one(0) _one(0)
{ {
} }
~TemplateSingleton() ~TemplateSingleton() {
{
if ( _one ) { if ( _one ) {
delete _one; delete _one;
_one = 0; _one = 0;
} }
} }
private:
static TemplateSingleton< T > _singleton;
T* _one;
}; };
template <typename T>
TemplateSingleton<T> TemplateSingleton<T>::_singleton;
/// Base class for device trackers. /// Base class for device trackers.
class DeviceTracker : public QObject { class DeviceTracker : public QObject {
@ -78,8 +77,7 @@ protected:
private: private:
struct SingletonData struct SingletonData {
{
typedef std::map< Name, int > Map; typedef std::map< Name, int > Map;
typedef std::vector< DeviceTracker* > Vector; typedef std::vector< DeviceTracker* > Vector;
Map _devicesMap; Map _devicesMap;

View file

@ -323,8 +323,8 @@ void Leapmotion::update() {
// Get the most recent frame and report some basic information // Get the most recent frame and report some basic information
const Leap::Frame frame = _controller.frame(); const Leap::Frame frame = _controller.frame();
static _int64 lastFrame = -1; static int64_t lastFrame = -1;
_int64 newFrameNb = frame.id(); int64_t newFrameNb = frame.id();
if ( (lastFrame >= newFrameNb) ) if ( (lastFrame >= newFrameNb) )
return; return;
@ -460,7 +460,8 @@ void Leapmotion::update() {
} }
void Leapmotion::reset() { 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. // as the "torso" is below it.
_leapBasePos = glm::vec3(0, -LEAP_Y, LEAP_Z); _leapBasePos = glm::vec3(0, -LEAP_Y, LEAP_Z);
@ -469,6 +470,7 @@ void Leapmotion::reset() {
glm::vec3 zAxis = glm::normalize(glm::cross(xAxis, yAxis)); glm::vec3 zAxis = glm::normalize(glm::cross(xAxis, yAxis));
xAxis = glm::normalize(glm::cross(yAxis, zAxis)); xAxis = glm::normalize(glm::cross(yAxis, zAxis));
_leapBaseOri = glm::inverse(glm::quat_cast(glm::mat3(xAxis, yAxis, zAxis))); _leapBaseOri = glm::inverse(glm::quat_cast(glm::mat3(xAxis, yAxis, zAxis)));
#endif
} }
void Leapmotion::updateEnabled() { void Leapmotion::updateEnabled() {