From 9c401607b101784884e251005c6127098d8adcb8 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka <drzej.k@gmail.com> Date: Fri, 15 Nov 2013 18:47:25 -0800 Subject: [PATCH] Missed the actual files. --- cmake/modules/FindSixense.cmake | 44 ++++++++++++++++++++ interface/src/devices/SixenseManager.cpp | 53 ++++++++++++++++++++++++ interface/src/devices/SixenseManager.h | 22 ++++++++++ 3 files changed, 119 insertions(+) create mode 100644 cmake/modules/FindSixense.cmake create mode 100644 interface/src/devices/SixenseManager.cpp create mode 100644 interface/src/devices/SixenseManager.h diff --git a/cmake/modules/FindSixense.cmake b/cmake/modules/FindSixense.cmake new file mode 100644 index 0000000000..b8692d4fb5 --- /dev/null +++ b/cmake/modules/FindSixense.cmake @@ -0,0 +1,44 @@ +# Try to find the Sixense controller library +# +# You must provide a SIXENSE_ROOT_DIR which contains lib and include directories +# +# Once done this will define +# +# SIXENSE_FOUND - system found Sixense +# SIXENSE_INCLUDE_DIRS - the Sixense include directory +# SIXENSE_LIBRARIES - Link this to use Sixense +# +# Created on 11/15/2013 by Andrzej Kapolka +# Copyright (c) 2013 High Fidelity +# + +if (SIXENSE_LIBRARIES AND SIXENSE_INCLUDE_DIRS) + # in cache already + set(SIXENSE_FOUND TRUE) +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/) + elseif (UNIX) + find_library(SIXENSE_LIBRARIES libsixense_x64.so ${SIXENSE_ROOT_DIR}/lib/UNIX/) + endif () + + if (SIXENSE_INCLUDE_DIRS AND SIXENSE_LIBRARIES) + set(SIXENSE_FOUND TRUE) + endif (SIXENSE_INCLUDE_DIRS AND SIXENSE_LIBRARIES) + + if (SIXENSE_FOUND) + if (NOT SIXENSE_FIND_QUIETLY) + message(STATUS "Found Sixense: ${SIXENSE_LIBRARIES}") + endif (NOT SIXENSE_FIND_QUIETLY) + else (SIXENSE_FOUND) + if (SIXENSE_FIND_REQUIRED) + message(FATAL_ERROR "Could not find Sixense") + endif (SIXENSE_FIND_REQUIRED) + endif (SIXENSE_FOUND) + + # show the SIXENSE_INCLUDE_DIRS and SIXENSE_LIBRARIES variables only in the advanced view + mark_as_advanced(SIXENSE_INCLUDE_DIRS SIXENSE_LIBRARIES) + +endif (SIXENSE_LIBRARIES AND SIXENSE_INCLUDE_DIRS) diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp new file mode 100644 index 0000000000..24110da227 --- /dev/null +++ b/interface/src/devices/SixenseManager.cpp @@ -0,0 +1,53 @@ +// +// Sixense.cpp +// interface +// +// Created by Andrzej Kapolka on 11/15/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#include "sixense.h" + +#include "Application.h" +#include "SixenseManager.h" + +SixenseManager::SixenseManager() { + sixenseInit(); +} + +SixenseManager::~SixenseManager() { + sixenseExit(); +} + +void SixenseManager::update() { + if (sixenseGetNumActiveControllers() == 0) { + return; + } + Hand& hand = Application::getInstance()->getAvatar()->getHand(); + hand.getPalms().clear(); + + int maxControllers = sixenseGetMaxControllers(); + for (int i = 0; i < maxControllers; i++) { + if (!sixenseIsControllerEnabled(i)) { + continue; + } + sixenseControllerData data; + sixenseGetNewestData(i, &data); + 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)); + FingerData finger(&palm, &hand); + finger.setActive(true); + finger.setRawRootPosition(position); + finger.setRawTipPosition(position + rotation * glm::vec3(0.0f, 0.0f, 100.0f)); + palm.getFingers().clear(); + palm.getFingers().push_back(finger); + palm.getFingers().push_back(finger); + palm.getFingers().push_back(finger); + hand.getPalms().push_back(palm); + } +} + diff --git a/interface/src/devices/SixenseManager.h b/interface/src/devices/SixenseManager.h new file mode 100644 index 0000000000..90b8cf988f --- /dev/null +++ b/interface/src/devices/SixenseManager.h @@ -0,0 +1,22 @@ +// +// SixenseManager.h +// interface +// +// Created by Andrzej Kapolka on 11/15/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#ifndef __interface__SixenseManager__ +#define __interface__SixenseManager__ + +/// Handles interaction with the Sixense SDK (e.g., Razer Hydra). +class SixenseManager { +public: + + SixenseManager(); + ~SixenseManager(); + + void update(); +}; + +#endif /* defined(__interface__SixenseManager__) */