[Bf-blender-cvs] [062d661] HMD_viewport: Expanded OpenHMDManager with additional features

TheOnlyJoey noreply at git.blender.org
Thu Mar 17 18:06:14 CET 2016


Commit: 062d66156b337a39352f42a36c3cbb9daf7fc630
Author: TheOnlyJoey
Date:   Thu Mar 17 18:04:07 2016 +0100
Branches: HMD_viewport
https://developer.blender.org/rB062d66156b337a39352f42a36c3cbb9daf7fc630

Expanded OpenHMDManager with additional features

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

M	intern/ghost/intern/GHOST_OpenHMDManager.cpp
M	intern/ghost/intern/GHOST_OpenHMDManager.h

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

diff --git a/intern/ghost/intern/GHOST_OpenHMDManager.cpp b/intern/ghost/intern/GHOST_OpenHMDManager.cpp
index bbec9d0..b7f384f 100644
--- a/intern/ghost/intern/GHOST_OpenHMDManager.cpp
+++ b/intern/ghost/intern/GHOST_OpenHMDManager.cpp
@@ -19,18 +19,17 @@
  */
 
 #include "GHOST_OpenHMDManager.h"
-
-// TODO replace with blender internal openhmd files
-#include "include/openhmd.h"
-
 #include "GHOST_EventOpenHMD.h"
 #include "GHOST_WindowManager.h"
 
+#include "include/openhmd.h"
+
 GHOST_OpenHMDManager::GHOST_OpenHMDManager(GHOST_System& sys)
-    : m_system(sys),
-      m_available(false),
-      m_context(NULL),
-      m_device(NULL)
+	: m_system(sys),
+	  m_available(false),
+	  m_context(NULL),
+	  m_device(NULL),
+	  m_deviceIndex(-1)
 {
 	m_context = ohmd_ctx_create();
 	if (m_context != NULL) {
@@ -40,7 +39,8 @@ GHOST_OpenHMDManager::GHOST_OpenHMDManager(GHOST_System& sys)
 			m_available = true;
 
 			//can't fail?
-			m_device = ohmd_list_open_device(m_context, 0);
+			m_deviceIndex = 0;
+			m_device = ohmd_list_open_device(m_context, m_deviceIndex);
 		}
 		else {
 			printf("No available devices in OpenHMD Context\n");
@@ -72,19 +72,13 @@ bool GHOST_OpenHMDManager::processEvents()
 		if (!window)
 			return false;
 
-		ohmd_ctx_update(m_context);
 
 		GHOST_TUns64 now = m_system.getMilliSeconds();
-
 		GHOST_EventOpenHMD *event = new GHOST_EventOpenHMD(now, window);
 		GHOST_TEventOpenHMDData* data = (GHOST_TEventOpenHMDData*) event->getData();
-		float quat[4];
 
-		ohmd_device_getf(m_device, OHMD_ROTATION_QUAT, quat);
-		data->orientation[0] = quat[3];
-		data->orientation[1] = quat[0];
-		data->orientation[2] = quat[1];
-		data->orientation[3] = quat[2];
+		ohmd_ctx_update(m_context);
+		getRotationQuat(data->orientation);
 
 		m_system.pushEvent(event);
 		return true;
@@ -105,18 +99,329 @@ bool GHOST_OpenHMDManager::setDevice(const char *requested_vendor_name, const ch
 		return false;
 	}
 
+	bool success = false;
 	int num_devices = ohmd_ctx_probe(m_context);
 	for (int i = 0; i < num_devices; ++i) {
 		const char* device_name = ohmd_list_gets(m_context, i, OHMD_PRODUCT);
 		const char* vendor_name = ohmd_list_gets(m_context, i, OHMD_VENDOR);
 
 		if (strcmp(device_name, requested_device_name) == 0 && strcmp(vendor_name, requested_vendor_name) == 0) {
-			//can't fail
-			m_device = ohmd_list_open_device(m_context, i);
-			return true;
+			success = setDevice(i);
+			break;
 		}
 	}
 
-	// couldn't find a device by that name and vendor, the old device was preserved.
-	return false;
+	return success;
+}
+
+bool GHOST_OpenHMDManager::setDevice(int index)
+{
+	if (!m_available) {
+		return false;
+	}
+
+	//out of bounds
+	if (index >= ohmd_ctx_probe(m_context)) {
+		return false;
+	}
+
+	m_deviceIndex = index;
+	m_device = ohmd_list_open_device(m_context, index);
+	return true;
+}
+
+int GHOST_OpenHMDManager::getNumDevices() const
+{
+	if (!m_available)
+		return -1;
+
+	return ohmd_ctx_probe(m_context);
+}
+
+const char *GHOST_OpenHMDManager::getError() const
+{
+	if (!m_available) {
+		return NULL;
+	}
+
+	return ohmd_ctx_get_error(m_context);
+}
+
+const char *GHOST_OpenHMDManager::getDeviceName() const
+{
+	if (!m_available)
+		return NULL;
+
+	return ohmd_list_gets(m_context, m_deviceIndex, OHMD_PRODUCT);
+}
+
+const char *GHOST_OpenHMDManager::getVendorName() const
+{
+	if (!m_available)
+		return NULL;
+
+	return ohmd_list_gets(m_context, m_deviceIndex, OHMD_VENDOR);
+}
+
+const char *GHOST_OpenHMDManager::getPath() const
+{
+	if (!m_available)
+		return NULL;
+
+	return ohmd_list_gets(m_context, m_deviceIndex, OHMD_PATH);
+}
+
+void GHOST_OpenHMDManager::getRotationQuat(float orientation[4]) const
+{
+	if (!m_available) {
+		return;
+	}
+
+	float tmp[4];
+	ohmd_device_getf(m_device, OHMD_ROTATION_QUAT, tmp);
+
+	orientation[0] = tmp[3];
+	orientation[1] = tmp[0];
+	orientation[2] = tmp[1];
+	orientation[3] = tmp[2];
+}
+
+void GHOST_OpenHMDManager::getLeftEyeGLModelviewMatrix(float mat[16]) const
+{
+	if (!m_available) {
+		return;
+	}
+
+	ohmd_device_getf(m_device, OHMD_LEFT_EYE_GL_MODELVIEW_MATRIX, mat);
+}
+
+void GHOST_OpenHMDManager::getRightEyeGLModelviewMatrix(float mat[16]) const
+{
+	if (!m_available) {
+		return;
+	}
+
+	ohmd_device_getf(m_device, OHMD_RIGHT_EYE_GL_MODELVIEW_MATRIX, mat);
+}
+
+void GHOST_OpenHMDManager::getLeftEyeGLProjectionMatrix(float mat[16]) const
+{
+	if (!m_available) {
+		return;
+	}
+
+	ohmd_device_getf(m_device, OHMD_LEFT_EYE_GL_PROJECTION_MATRIX, mat);
+}
+
+void GHOST_OpenHMDManager::getRightEyeGLProjectionMatrix(float mat[16]) const
+{
+	if (!m_available) {
+		return;
+	}
+
+	ohmd_device_getf(m_device, OHMD_RIGHT_EYE_GL_PROJECTION_MATRIX, mat);
+}
+
+void GHOST_OpenHMDManager::getPositionVector(float position[3]) const
+{
+	if (!m_available) {
+		return;
+	}
+
+	ohmd_device_getf(m_device, OHMD_POSITION_VECTOR, position);
+}
+
+float GHOST_OpenHMDManager::getScreenHorizontalSize() const
+{
+	if (!m_available) {
+		return -1;
+	}
+
+	float val = -1;
+	ohmd_device_getf(m_device, OHMD_SCREEN_HORIZONTAL_SIZE, &val);
+	return val;
+}
+
+float GHOST_OpenHMDManager::getScreenVerticalSize() const
+{
+	if (!m_available) {
+		return -1;
+	}
+
+	float val = -1;
+	ohmd_device_getf(m_device, OHMD_SCREEN_VERTICAL_SIZE, &val);
+	return val;
+}
+
+float GHOST_OpenHMDManager::getLensHorizontalSeparation() const
+{
+	if (!m_available) {
+		return -1;
+	}
+
+	float val = -1;
+	ohmd_device_getf(m_device, OHMD_LENS_HORIZONTAL_SEPARATION, &val);
+	return val;
+
+}
+
+float GHOST_OpenHMDManager::getLensVerticalPosition() const
+{
+	if (!m_available) {
+		return -1;
+	}
+
+	float val = -1;
+	ohmd_device_getf(m_device, OHMD_LENS_VERTICAL_POSITION, &val);
+	return val;
+}
+
+float GHOST_OpenHMDManager::getLeftEyeFOV() const
+{
+	if (!m_available) {
+		return -1;
+	}
+
+	float val = -1;
+	ohmd_device_getf(m_device, OHMD_LEFT_EYE_FOV, &val);
+	return val;
+}
+
+float GHOST_OpenHMDManager::getLeftEyeAspectRatio() const
+{
+	if (!m_available) {
+		return -1;
+	}
+
+	float val = -1;
+	ohmd_device_getf(m_device, OHMD_LEFT_EYE_ASPECT_RATIO, &val);
+	return val;
+}
+
+float GHOST_OpenHMDManager::getRightEyeFOV() const
+{
+	if (!m_available) {
+		return -1;
+	}
+
+	float val = -1;
+	ohmd_device_getf(m_device, OHMD_RIGHT_EYE_FOV, &val);
+	return val;
+}
+
+float GHOST_OpenHMDManager::getRightEyeAspectRatio() const
+{
+	if (!m_available) {
+		return -1;
+	}
+
+	float val = -1;
+	ohmd_device_getf(m_device, OHMD_RIGHT_EYE_ASPECT_RATIO, &val);
+	return val;
+}
+
+float GHOST_OpenHMDManager::getEyeIPD() const
+{
+	if (!m_available) {
+		return -1;
+	}
+
+	float val = -1;
+	ohmd_device_getf(m_device, OHMD_EYE_IPD, &val);
+	return val;
+}
+
+float GHOST_OpenHMDManager::getProjectionZFar() const
+{
+	if (!m_available) {
+		return -1;
+	}
+
+	float val = -1;
+	ohmd_device_getf(m_device, OHMD_PROJECTION_ZFAR, &val);
+	return val;
+}
+
+float GHOST_OpenHMDManager::getProjectionZNear() const
+{
+	if (!m_available) {
+		return -1;
+	}
+
+	float val = -1;
+	ohmd_device_getf(m_device, OHMD_PROJECTION_ZNEAR, &val);
+	return val;
+}
+
+void GHOST_OpenHMDManager::getDistortion(float distortion[6]) const
+{
+	if (!m_available) {
+		return;
+	}
+
+	ohmd_device_getf(m_device, OHMD_DISTORTION_K, distortion);
+}
+
+int GHOST_OpenHMDManager::getScreenHorizontalResolution() const
+{
+	if (!m_available) {
+		return -1;
+	}
+
+	int val = -1;
+	ohmd_device_geti(m_device, OHMD_SCREEN_HORIZONTAL_RESOLUTION, &val);
+	return val;
+}
+
+int GHOST_OpenHMDManager::getScreenVerticalResolution() const
+{
+	if (!m_available) {
+		return -1;
+	}
+
+	int val = -1;
+	ohmd_device_geti(m_device, OHMD_SCREEN_VERTICAL_RESOLUTION, &val);
+	return val;
+}
+
+bool GHOST_OpenHMDManager::setEyeIPD(float val)
+{
+	if (!m_available) {
+		return false;
+	}
+
+	return ohmd_device_setf(m_device, OHMD_EYE_IPD, &val);
+}
+
+bool GHOST_OpenHMDManager::setProjectionZFar(float val)
+{
+	if (!m_available) {
+		return false;
+	}
+
+	return ohmd_device_setf(m_device, OHMD_PROJECTION_ZFAR, &val);
+}
+
+bool GHOST_OpenHMDManager::setProjectionZNear(float val)
+{
+	if (!m_available) {
+		return false;
+	}
+
+	return ohmd_device_setf(m_device, OHMD_PROJECTION_ZNEAR, &val);
+}
+
+ohmd_context *GHOST_OpenHMDManager::getOpenHMDContext()
+{
+	return m_context;
+}
+
+ohmd_device *GHOST_OpenHMDManager::getOpenHMDDevice()
+{
+	return m_device;
+}
+
+const int GHOST_OpenHMDManager::getDeviceIndex()
+{
+	return m_deviceIndex;
 }
diff --git a/intern/ghost/intern/GHOST_OpenHMDManager.h b/intern/ghost/intern/GHOST_OpenHMDManager.h
index 7975342..e87bd85 100644
--- a/intern/ghost/intern/GHOST_OpenHMDManager.h
+++ b/intern/ghost/intern/GHOST_OpenHMDManager.h
@@ -34,21 +34,240 @@ public:
 	// none of the others without platform implementations use it)
 	GHOST_OpenHMDManager(GHOST_System&);
 	virtual ~GHOST_OpenHMDManager();
-	
+
+	/**
+	 *  \return True if there is a device opened and ready for polling, false otherwise.
+	 */
 	bool available() const;
+
+	/**
+	 *  Update the device context and generate an event containing the current orientation of the device.
+	 *  \return A boolean indicating success.
+	 */
 	bool processEvents();
-	
+
+	/**
+	 *  Select the device matching the given vendor and device name.
+	 *  This device will then be the device for which ghost events will be generated.
+	 *  If no device with the correct name and vendor can be found, or an error occurs,
+	 *      the current device is preserved.
+	 *  \param requested_vendor_name    The exact name of the vendor for the requested device
+	 *  \param requested_device_name    The exact name of the requested device.
+	 *  \return A boolean indicating success.
+	 */
 	bool setDevice(const char *requested_vendor_name, const char *requested_device_name);
-	
+
+	/**
+	 *  Select a device by index
+	 *  \param index    The index of the requested device
+	 *  See setDevice(const char*, const char*) for more information.
+	 */
+	bool setDevice(int index);
+
+	/**
+	 *  \return The number of connected devices.
+	 *  -1 is returned if available() is false.
+	 */
+	int getNumDevices() const;
+
+	/**
+	 *  \return A c-style string containing the last error as a human-readable message
+	 *  NULL is returned if available() is false.
+	 */
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list