Ver código fonte

- Added smarter way to use the acceleration only fallback
- Introduced seti and geti in android driver and in the c++ bindings

Joey Ferwerda 10 anos atrás
pai
commit
f2f63fa48c
4 arquivos alterados com 61 adições e 3 exclusões
  1. 13 0
      include/openhmd.h
  2. 28 3
      src/drv_android/android.c
  3. 16 0
      src/openhmd.c
  4. 4 0
      src/openhmdi.h

+ 13 - 0
include/openhmd.h

@@ -125,6 +125,9 @@ typedef enum {
 	/** int[1], get
 	      Physical vertical resolution of the device screen. */
 	OHMD_SCREEN_VERTICAL_RESOLUTION       =  1,
+	/** int[1], get
+		  Acceleration only fallback non-fusion (Android driver) */
+	OHMD_ACCELERATION_ONLY_FALLBACK		  =	 2,
 
 } ohmd_int_value;
 
@@ -258,6 +261,16 @@ OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_setf(ohmd_device* device, ohmd_fl
  */
 OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_geti(ohmd_device* device, ohmd_int_value type, int* out);
 
+/**
+ * Set an integer value from a device.
+ *
+ * @param device An open device to retreive the value from.
+ * @param type What type of value to retreive, ohmd_int_value section for more information.
+ * @param[out] out A pointer to an integer, or integer array where the retreived value should be written.
+ * @return 0 on success, <0 on failure.
+ */
+OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_seti(ohmd_device* device, ohmd_int_value type, int* in);
+
 #ifdef __cplusplus
 }
 #endif

+ 28 - 3
src/drv_android/android.c

@@ -104,8 +104,10 @@ static int setf(ohmd_device* device, ohmd_float_value type, float* in)
 
 	switch(type){
 		case OHMD_EXTERNAL_SENSOR_FUSION: {
-				//ofusion_update(&priv->sensor_fusion, *in, (vec3f*)(in + 1), (vec3f*)(in + 4), (vec3f*)(in + 7));
-				nofusion_update(&priv->sensor_fusion, *in, (vec3f*)(in + 4));
+				if (priv->base.properties.accel_only == 1)
+					nofusion_update(&priv->sensor_fusion, *in, (vec3f*)(in + 4));
+				else
+					ofusion_update(&priv->sensor_fusion, *in, (vec3f*)(in + 1), (vec3f*)(in + 4), (vec3f*)(in + 7));
 			}
 			break;
 
@@ -118,6 +120,28 @@ static int setf(ohmd_device* device, ohmd_float_value type, float* in)
 	return 0;
 }
 
+static int seti(ohmd_device* device, ohmd_int_value type, int* in)
+{
+	android_priv* priv = (android_priv*)device;
+
+	switch(type){
+		case OHMD_ACCELERATION_ONLY_FALLBACK: {
+			priv->base.properties.accel_only = &in;
+			
+			if(priv->base.properties.accel_only = 1)
+				nofusion_init(&priv->sensor_fusion); //re-init with different smoothing
+		}
+		break;
+		
+		default:
+			ohmd_set_error(priv->base.ctx, "invalid type given to seti (%i)", type);
+			return -1;
+			break;
+		}
+		
+		return 0;		
+}
+
 static void close_device(ohmd_device* device)
 {
 	LOGD("closing Android device");
@@ -153,8 +177,9 @@ static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
 	priv->base.close = close_device;
 	priv->base.getf = getf;
 	priv->base.setf = setf;
+	priv->base.seti = seti;
 	
-	nofusion_init(&priv->sensor_fusion);
+	ofusion_init(&priv->sensor_fusion);
 
 	return (ohmd_device*)priv;
 }

+ 16 - 0
src/openhmd.c

@@ -288,6 +288,22 @@ int OHMD_APIENTRY ohmd_device_geti(ohmd_device* device, ohmd_int_value type, int
 	case OHMD_SCREEN_VERTICAL_RESOLUTION:
 		*out = device->properties.vres;
 		return OHMD_S_OK;
+	case OHMD_ACCELERATION_ONLY_FALLBACK:
+		*out = device->properties.accel_only;
+		return OHMD_S_OK;
+	default:
+		return OHMD_S_INVALID_PARAMETER;
+	}
+}
+
+int OHMD_APIENTRY ohmd_device_seti(ohmd_device* device, ohmd_int_value type, int* in)
+{
+	switch(type){
+	case OHMD_ACCELERATION_ONLY_FALLBACK: {
+		device->properties.accel_only = *in;
+		return OHMD_S_OK;
+	}
+	break;
 	default:
 		return OHMD_S_INVALID_PARAMETER;
 	}

+ 4 - 0
src/openhmdi.h

@@ -65,6 +65,8 @@ typedef struct {
 		float zfar;
 		float znear;
 
+		int accel_only; //bool-like for setting acceleration only fallback (android driver)
+		
 		mat4x4f proj_left; // adjusted projection matrix for left screen
 		mat4x4f proj_right; // adjusted projection matrix for right screen
 } ohmd_device_properties;
@@ -77,6 +79,8 @@ struct ohmd_device {
 
 	int (*getf)(ohmd_device* device, ohmd_float_value type, float* out);
 	int (*setf)(ohmd_device* device, ohmd_float_value type, float* in);
+	
+	int (*seti)(ohmd_device* device, ohmd_int_value type, int in);
 
 	void (*update)(ohmd_device* device);
 	void (*close)(ohmd_device* device);