Prechádzať zdrojové kódy

Implemented set_android_properties, introduced OHMD_DRIVER_PROPERTIES in set_data to be able to set the data for drivers which have a general init.
- Fixed up some leftovers

Joey Ferwerda 9 rokov pred
rodič
commit
b56efa8b29
3 zmenil súbory, kde vykonal 68 pridanie a 54 odobranie
  1. 5 5
      include/openhmd.h
  2. 59 49
      src/drv_android/android.c
  3. 4 0
      src/openhmd.c

+ 5 - 5
include/openhmd.h

@@ -125,9 +125,6 @@ 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;
 
@@ -136,8 +133,11 @@ typedef enum {
 typedef enum {
     /** void*, set
         Set void* data for use in the internal drivers. */
-    OHMD_DRIVER_DATA
-
+    OHMD_DRIVER_DATA		= 0,
+    /** ohmd_device_properties*, set
+        Set the device properties based on the ohmd_device_properties struct for use in the internal drivers. 
+        This can be used to fill in information about the device such as Android internally, or for setting profiles.*/  
+	OHMD_DRIVER_PROPERTIES	= 1,
 } ohmd_data_value;
 
 /** An opaque pointer to a context structure. */

+ 59 - 49
src/drv_android/android.c

@@ -30,56 +30,12 @@ typedef struct {
     #endif
 } android_priv;
 
-static void nofusion_update(fusion* me, float dt, const vec3f* accel)
-{
-	//avg raw accel data to smooth jitter, and normalise
-	ofq_add(&me->accel_fq, accel);
-	vec3f accel_mean;
-	ofq_get_mean(&me->accel_fq, &accel_mean);
-	vec3f acc_n = accel_mean;
-	ovec3f_normalize_me(&acc_n);
-
-
-	//reference vectors for axis-angle
-	vec3f xyzv[3] = {
-		{1,0,0},
-		{0,1,0},
-		{0,0,1}
-	};
-	quatf roll, pitch;
-
-	//pitch is rot around x, based on gravity in z and y axes
-	oquatf_init_axis(&pitch, xyzv+0, atan2f(-acc_n.z, -acc_n.y));
-
-	//roll is rot around z, based on gravity in x and y axes
-	//note we need to invert the values when the device is upside down (y < 0) for proper results
-	oquatf_init_axis(&roll, xyzv+2, acc_n.y < 0 ? atan2f(-acc_n.x, -acc_n.y) : atan2f(acc_n.x, acc_n.y));
-
+//Forward decelerations
+static void set_android_properties(ohmd_device* device, ohmd_device_properties* props);
+static void nofusion_init(fusion* me);
+static void nofusion_update(fusion* me, float dt, const vec3f* accel);
 
 
-	quatf or = {0,0,0,1};
-	//order of applying is yaw-pitch-roll
-	//yaw is not possible using only accel
-	oquatf_mult_me(&or, &pitch);
-	oquatf_mult_me(&or, &roll);
-
-	me->orient = or;
-}
-
-//shorter buffers for frame smoothing
-static void nofusion_init(fusion* me)
-{
-	memset(me, 0, sizeof(fusion));
-	me->orient.w = 1.0f;
-
-	ofq_init(&me->mag_fq, 10);
-	ofq_init(&me->accel_fq, 10);
-	ofq_init(&me->ang_vel_fq, 10);
-
-	me->flags = FF_USE_GRAVITY;
-	me->grav_gain = 0.05f;
-}
-
 //Static variable for timeDelta;
 static float timestamp;
 
@@ -197,8 +153,12 @@ static int set_data(ohmd_device* device, ohmd_data_value type, void* in)
 	switch(type){
 		case OHMD_DRIVER_DATA: {
 		    priv->state = (android_app*)in;
+            break;
+		}
+		case OHMD_DRIVER_PROPERTIES: {
+            set_android_properties(device, (ohmd_device_properties*)in);
+            break;
 		}
-		break;
 
 		default:
 			ohmd_set_error(priv->base.ctx, "invalid type given to set_data (%i)", type);
@@ -298,6 +258,56 @@ ohmd_driver* ohmd_create_android_drv(ohmd_context* ctx)
 }
 
 /* Android specific functions */
+static void nofusion_update(fusion* me, float dt, const vec3f* accel)
+{
+	//avg raw accel data to smooth jitter, and normalise
+	ofq_add(&me->accel_fq, accel);
+	vec3f accel_mean;
+	ofq_get_mean(&me->accel_fq, &accel_mean);
+	vec3f acc_n = accel_mean;
+	ovec3f_normalize_me(&acc_n);
+
+
+	//reference vectors for axis-angle
+	vec3f xyzv[3] = {
+		{1,0,0},
+		{0,1,0},
+		{0,0,1}
+	};
+	quatf roll, pitch;
+
+	//pitch is rot around x, based on gravity in z and y axes
+	oquatf_init_axis(&pitch, xyzv+0, atan2f(-acc_n.z, -acc_n.y));
+
+	//roll is rot around z, based on gravity in x and y axes
+	//note we need to invert the values when the device is upside down (y < 0) for proper results
+	oquatf_init_axis(&roll, xyzv+2, acc_n.y < 0 ? atan2f(-acc_n.x, -acc_n.y) : atan2f(acc_n.x, acc_n.y));
+
+
+
+	quatf or = {0,0,0,1};
+	//order of applying is yaw-pitch-roll
+	//yaw is not possible using only accel
+	oquatf_mult_me(&or, &pitch);
+	oquatf_mult_me(&or, &roll);
+
+	me->orient = or;
+}
+
+//shorter buffers for frame smoothing
+static void nofusion_init(fusion* me)
+{
+	memset(me, 0, sizeof(fusion));
+	me->orient.w = 1.0f;
+
+	ofq_init(&me->mag_fq, 10);
+	ofq_init(&me->accel_fq, 10);
+	ofq_init(&me->ang_vel_fq, 10);
+
+	me->flags = FF_USE_GRAVITY;
+	me->grav_gain = 0.05f;
+}
+
 static void set_android_properties(ohmd_device* device, ohmd_device_properties* props)
 {
     android_priv* priv = (android_priv*)device;

+ 4 - 0
src/openhmd.c

@@ -308,6 +308,10 @@ int OHMD_APIENTRY ohmd_device_set_data(ohmd_device* device, ohmd_data_value type
         device->set_data(device, OHMD_DRIVER_DATA, in);
         return OHMD_S_OK;
     }
+    case OHMD_DRIVER_PROPERTIES:{
+        device->set_data(device, OHMD_DRIVER_PROPERTIES, in);
+        return OHMD_S_OK;
+    }
     break;
     default:
         return OHMD_S_INVALID_PARAMETER;