[Bf-blender-cvs] [57424a2] HMD_viewport: Added OpenHMD Ghost manager Added OpenHMD Ghost event Added OpenHMD windowmanager event type for vr camera transform updates Began integration if the OpenHMDManager with the ghost system (only updated from the GHOST_SystemX11 for now)

Galadus noreply at git.blender.org
Wed Mar 16 16:10:49 CET 2016


Commit: 57424a2401995de3855dc0dabb1a5b2259eade15
Author: Galadus
Date:   Wed Mar 9 21:44:53 2016 +0100
Branches: HMD_viewport
https://developer.blender.org/rB57424a2401995de3855dc0dabb1a5b2259eade15

Added OpenHMD Ghost manager
Added OpenHMD Ghost event
Added OpenHMD windowmanager event type for vr camera transform updates
Began integration if the OpenHMDManager with the ghost system (only updated from the GHOST_SystemX11 for now)

===================================================================

M	build_files/cmake/macros.cmake
M	intern/ghost/CMakeLists.txt
M	intern/ghost/GHOST_Types.h
A	intern/ghost/intern/GHOST_EventOpenHMD.h
A	intern/ghost/intern/GHOST_OpenHMDManager.cpp
A	intern/ghost/intern/GHOST_OpenHMDManager.h
M	intern/ghost/intern/GHOST_System.cpp
M	intern/ghost/intern/GHOST_System.h
M	intern/ghost/intern/GHOST_SystemX11.cpp
M	release/datafiles/locale
M	release/scripts/addons
M	release/scripts/addons_contrib
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/wm_event_types.h

===================================================================

diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index df0c365..ab56dea 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -481,6 +481,9 @@ function(setup_liblinks
 		endif()
 	endif()
 
+	#FIXMELIKEABAWS
+	target_link_libraries(${target} "/usr/local/lib/libopenhmd.a" "/usr/lib/x86_64-linux-gnu/libhidapi-libusb.a" "/usr/lib/x86_64-linux-gnu/libusb-1.0.a" "/lib/x86_64-linux-gnu/libudev.so.1")
+
 	# We put CLEW and CUEW here because OPENSUBDIV_LIBRARIES dpeends on them..
 	if(WITH_CYCLES OR WITH_COMPOSITOR OR WITH_OPENSUBDIV)
 		target_link_libraries(${target} "extern_clew")
diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt
index d31e947..b04c38f 100644
--- a/intern/ghost/CMakeLists.txt
+++ b/intern/ghost/CMakeLists.txt
@@ -53,6 +53,12 @@ set(SRC
 	intern/GHOST_Window.cpp
 	intern/GHOST_WindowManager.cpp
 
+# TODO koen made it compile, ugly
+	intern/GHOST_OpenHMDManager.h
+	intern/GHOST_OpenHMDManager.cpp
+	intern/GHOST_EventOpenHMD.h
+
+
 	GHOST_C-api.h
 	GHOST_IEvent.h
 	GHOST_IEventConsumer.h
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index 29508a8..62c44ac 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -76,7 +76,7 @@ typedef enum {
 	GHOST_kSuccess
 } GHOST_TSuccess;
 
-/* Xtilt and Ytilt represent how much the pen is tilted away from 
+/* Xtilt and Ytilt represent how much the pen is tilted away from
  * vertically upright in either the X or Y direction, with X and Y the
  * axes of the tablet surface.
  * In other words, Xtilt and Ytilt are components of a vector created by projecting
@@ -186,12 +186,12 @@ typedef enum {
 	GHOST_kEventWindowUpdate,
 	GHOST_kEventWindowSize,
 	GHOST_kEventWindowMove,
-	
+
 	GHOST_kEventDraggingEntered,
 	GHOST_kEventDraggingUpdated,
 	GHOST_kEventDraggingExited,
 	GHOST_kEventDraggingDropDone,
-	
+
 	GHOST_kEventOpenMainFile, // Needed for Cocoa to open double-clicked .blend file at startup
 	GHOST_kEventNativeResolutionChange, // Needed for Cocoa when window moves to other display
 
@@ -201,6 +201,8 @@ typedef enum {
 	GHOST_kEventImeComposition,
 	GHOST_kEventImeCompositionEnd,
 
+	GHOST_kEventOpenHMD,
+
 	GHOST_kNumEventTypes
 } GHOST_TEventType;
 
@@ -210,9 +212,9 @@ typedef enum {
 	GHOST_kStandardCursorDefault = 0,
 	GHOST_kStandardCursorRightArrow,
 	GHOST_kStandardCursorLeftArrow,
-	GHOST_kStandardCursorInfo, 
+	GHOST_kStandardCursorInfo,
 	GHOST_kStandardCursorDestroy,
-	GHOST_kStandardCursorHelp,    
+	GHOST_kStandardCursorHelp,
 	GHOST_kStandardCursorCycle,
 	GHOST_kStandardCursorSpray,
 	GHOST_kStandardCursorWait,
@@ -229,7 +231,7 @@ typedef enum {
 	GHOST_kStandardCursorBottomRightCorner,
 	GHOST_kStandardCursorBottomLeftCorner,
 	GHOST_kStandardCursorCopy,
-	GHOST_kStandardCursorCustom, 
+	GHOST_kStandardCursorCustom,
 	GHOST_kStandardCursorPencil,
 
 	GHOST_kStandardCursorNumCursors
@@ -243,7 +245,7 @@ typedef enum {
 	GHOST_kKeyLinefeed,
 	GHOST_kKeyClear,
 	GHOST_kKeyEnter  = 0x0D,
-	
+
 	GHOST_kKeyEsc    = 0x1B,
 	GHOST_kKeySpace  = ' ',
 	GHOST_kKeyQuote  = 0x27,
@@ -300,7 +302,7 @@ typedef enum {
 	GHOST_kKeyBackslash    = 0x5C,
 	GHOST_kKeyAccentGrave  = '`',
 
-	
+
 	GHOST_kKeyLeftShift = 0x100,
 	GHOST_kKeyRightShift,
 	GHOST_kKeyLeftControl,
@@ -372,7 +374,7 @@ typedef enum {
 	GHOST_kKeyF22,
 	GHOST_kKeyF23,
 	GHOST_kKeyF24,
-	
+
 	// Multimedia keypad buttons
 	GHOST_kKeyMediaPlay,
 	GHOST_kKeyMediaStop,
@@ -413,7 +415,7 @@ typedef enum {
 	GHOST_kTrackpadEventSwipe, /* Reserved, not used for now */
 	GHOST_kTrackpadEventMagnify
 } GHOST_TTrackpadEventSubTypes;
-	
+
 
 typedef struct {
 	/** The event subtype */
@@ -516,6 +518,10 @@ typedef struct {
 } GHOST_TEventKeyData;
 
 typedef struct {
+    float orientation[4]; //orientation quaternion of the HMD
+} GHOST_TEventOpenHMDData;
+
+typedef struct {
 	/** Number of pixels on a line. */
 	GHOST_TUns32 xPixels;
 	/** Number of lines. */
diff --git a/intern/ghost/intern/GHOST_EventOpenHMD.h b/intern/ghost/intern/GHOST_EventOpenHMD.h
new file mode 100644
index 0000000..8149447
--- /dev/null
+++ b/intern/ghost/intern/GHOST_EventOpenHMD.h
@@ -0,0 +1,20 @@
+#ifndef __GHOST_EVENTOPENHMD_H_
+#define __GHOST_EVENTOPENHMD_H_
+
+#include "GHOST_Event.h"
+
+class GHOST_EventOpenHMD : public GHOST_Event
+{
+public:
+    GHOST_EventOpenHMD (GHOST_TUns64 time, GHOST_IWindow *window)
+		: GHOST_Event(time, GHOST_kEventOpenHMD, window)
+	{
+		m_data = &m_orientationData;
+	}
+
+protected:
+    GHOST_TEventOpenHMDData m_orientationData;
+
+};
+
+#endif // __GHOST_EVENTOPENHMD_H_
diff --git a/intern/ghost/intern/GHOST_OpenHMDManager.cpp b/intern/ghost/intern/GHOST_OpenHMDManager.cpp
new file mode 100644
index 0000000..0adeb8b
--- /dev/null
+++ b/intern/ghost/intern/GHOST_OpenHMDManager.cpp
@@ -0,0 +1,85 @@
+#include "GHOST_OpenHMDManager.h"
+
+// TODO replace with blender internal openhmd files
+#include <openhmd/openhmd.h>
+
+#include "GHOST_EventOpenHMD.h"
+#include "GHOST_WindowManager.h"
+
+GHOST_OpenHMDManager::GHOST_OpenHMDManager(GHOST_System& sys)
+    : m_system(sys),
+      m_available(false),
+      m_context(NULL),
+      m_device(NULL)
+{
+	m_context = ohmd_ctx_create();
+    if (m_context != NULL) {
+
+        int num_devices = ohmd_ctx_probe(m_context);
+        if (num_devices > 0) {
+            m_available = true;
+
+            printf("Found %i OpenHMD devices", num_devices);
+            for (int i = 0; i < num_devices; ++i) {
+                printf("Device %i\n", i);
+                printf("vendor: %s\n", ohmd_list_gets(m_context, i, OHMD_VENDOR));
+                printf("product: %s\n", ohmd_list_gets(m_context, i, OHMD_PRODUCT));
+                printf("path: %s\n", ohmd_list_gets(m_context, i, OHMD_PATH));
+            }
+
+            //can't fail?
+            m_device = ohmd_list_open_device(m_context, 0);
+        }
+        else {
+            printf("No available devices in OpenHMD Context\n");
+
+            ohmd_ctx_destroy(m_context);
+            m_context = NULL;
+        }
+    }
+    else {
+        printf("Failed to create OpenHMD Context\n");
+    }
+
+
+    /*
+	ohmd_device_geti(hmd, OHMD_SCREEN_HORIZONTAL_RESOLUTION, &ival);
+	ohmd_device_geti(hmd, OHMD_SCREEN_VERTICAL_RESOLUTION, &ival);
+	ohmd_device_getf(hmd, OHMD_SCREEN_HORIZONTAL_SIZE, &fval);
+	ohmd_device_getf(hmd, OHMD_SCREEN_VERTICAL_SIZE, &fval);
+	ohmd_device_getf(hmd, OHMD_LENS_HORIZONTAL_SEPARATION, &fval);
+	ohmd_device_getf(hmd, OHMD_LENS_VERTICAL_POSITION, &fval);
+	ohmd_device_getf(hmd, OHMD_LEFT_EYE_FOV, &fval);
+	ohmd_device_getf(hmd, OHMD_LEFT_EYE_ASPECT_RATIO, &fval);
+    */
+}
+
+GHOST_OpenHMDManager::~GHOST_OpenHMDManager()
+{
+    if (m_available) {
+        ohmd_ctx_destroy(m_context);
+        m_context = NULL;
+        m_device = NULL;
+        m_available = false;
+    }
+}
+
+bool GHOST_OpenHMDManager::processEvents()
+{
+	if (m_available) {
+        ohmd_ctx_update(m_context);
+
+        GHOST_TUns64 now = m_system.getMilliSeconds();
+
+        GHOST_EventOpenHMD *event = new GHOST_EventOpenHMD(now, m_system.getWindowManager()->getActiveWindow());
+        GHOST_TEventOpenHMDData* data = (GHOST_TEventOpenHMDData*) event->getData();
+
+        ohmd_device_getf(m_device, OHMD_ROTATION_QUAT, data->orientation);
+
+        m_system.pushEvent(event);
+        return true;
+	}
+	else {
+        return false;
+	}
+}
diff --git a/intern/ghost/intern/GHOST_OpenHMDManager.h b/intern/ghost/intern/GHOST_OpenHMDManager.h
new file mode 100644
index 0000000..1d20e4b
--- /dev/null
+++ b/intern/ghost/intern/GHOST_OpenHMDManager.h
@@ -0,0 +1,105 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s):
+ *   Mike Erwin
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __GHOST_OPENHMDMANAGER_H__
+#define __GHOST_OPENHMDMANAGER_H__
+
+#include "GHOST_System.h"
+
+// TODO probably shouldn't forward declare this here
+struct ohmd_context;
+struct ohmd_device;
+
+class GHOST_OpenHMDManager
+{
+public:
+    GHOST_OpenHMDManager(GHOST_System&); // TODO maybe cut out dependency on the system? (only used for getMilliSeconds and none of the others without platform implementations use it)
+    virtual ~GHOST_OpenHMDManager();
+
+    bool processEvents();
+
+protected:
+    GHOST_System&   m_system;
+
+private:
+    bool            m_available;
+
+    ohmd_context*   m_context;
+    ohmd_device*    m_device;
+
+
+
+
+
+    /*
+	// whether multi-axis functionality is available (via the OS or driver)
+	// does not imply that a device is plugged in or being used
+	virtual bool available() = 0;
+
+	// each platform's device detection should call this
+	// use standard USB/HID identifiers
+	bool setDevice(unsigned short vendor_id, unsigned short product_id);
+
+	// the latest raw axis data from the device
+	// NOTE: axis data should be in blender view coordinates
+	//       +X is to the right
+	//       +Y is up
+	//       +Z is out of the screen
+	//       for rotations, look from origin to each +axis
+	//       rotations are + when CCW, - when CW
+	// each platform is responsible for getting axis data into this form
+	// these values should not be scaled (just shuffled or flipped)
+	void updateTranslation(const short t[3], GHOST_TUns64 time);
+	void updateRotation(const short r[3], GHOST_TUns64 time);
+
+	// processes and sends most recent raw data as an NDOFMotion event
+	// returns whether an event was sent
+	bool sendMotionEvent();
+
+protected:
+	GHOST_System& m_system;
+
+priva

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list