Selaa lähdekoodia

Added analog axes support for controllers in the API.

Fredrik Hultin 8 vuotta sitten
vanhempi
commit
2eda395c28
5 muutettua tiedostoa jossa 41 lisäystä ja 4 poistoa
  1. 19 1
      examples/simple/simple.c
  2. 6 0
      include/openhmd.h
  3. 10 2
      src/drv_dummy/dummy.c
  4. 5 1
      src/openhmd.c
  5. 1 0
      src/openhmdi.h

+ 19 - 1
examples/simple/simple.c

@@ -93,9 +93,13 @@ int main(int argc, char** argv)
 	print_infof(hmd, "distortion k:",     6, OHMD_DISTORTION_K);
 	
 	print_infoi(hmd, "digital button count:", 1, OHMD_BUTTON_COUNT);
+	print_infoi(hmd, "analog axis count:   ", 1, OHMD_ANALOG_AXIS_COUNT);
 
 	printf("\n");
 
+	int analog_axis_count;
+	ohmd_device_geti(hmd, OHMD_ANALOG_AXIS_COUNT, &analog_axis_count);
+
 	// Ask for n rotation quaternions and position vectors
 	for(int i = 0; i < 10000; i++){
 		ohmd_ctx_update(ctx);
@@ -106,8 +110,22 @@ int main(int argc, char** argv)
 		//ohmd_device_setf(hmd, OHMD_ROTATION_QUAT, zero);
 		//ohmd_device_setf(hmd, OHMD_POSITION_VECTOR, zero);
 
+		// get rotation and postition
 		print_infof(hmd, "rotation quat:", 4, OHMD_ROTATION_QUAT);
 		print_infof(hmd, "position vec: ", 3, OHMD_POSITION_VECTOR);
+
+		// read analog axes
+		float axes[256];
+		ohmd_device_getf(hmd, OHMD_ANALOG_AXES_STATE, axes);
+
+		printf("%-25s", "axes:");
+		for(int i = 0; i < analog_axis_count; i++)
+		{
+			printf("%f ", axes[i]);
+		}
+		puts("");
+
+		// handle digital button events
 		print_infoi(hmd, "button event count:", 1, OHMD_BUTTON_EVENT_COUNT);
 		
 		int event_count = 0;
@@ -119,7 +137,7 @@ int main(int argc, char** argv)
 			ohmd_device_geti(hmd, OHMD_BUTTON_POP_EVENT, event);
 			printf("button %d: %s", event[0], event[1] == OHMD_BUTTON_DOWN ? "down" : "up");
 		}
-
+			
 		ohmd_sleep(.01);
 	}
 

+ 6 - 0
include/openhmd.h

@@ -129,6 +129,9 @@ typedef enum {
 	/** float[3] (get): Universal shader aberration coefficients (post warp scaling <r,g,b>. */
 	OHMD_UNIVERSAL_ABERRATION_K           = 21,
 
+	/** float[OHMD_ANALOG_AXIS_COUNT] (get): Get the state of the analog axes on the device. */
+	OHMD_ANALOG_AXES_STATE                = 22,
+
 } ohmd_float_value;
 
 /** A collection of int value information types used for getting information with ohmd_device_geti(). */
@@ -151,6 +154,9 @@ typedef enum {
 	OHMD_DEVICE_CLASS                     =  6,
 	/** int[1] (get, ohmd_geti()/ohmd_list_geti()): Gets the flags of the device. See: ohmd_device_flags. */
 	OHMD_DEVICE_FLAGS                     =  7,
+
+	/** int[1] (get, ohmd_geti()): Get the number of analog axes on the device. */
+	OHMD_ANALOG_AXIS_COUNT                =  8,
 } ohmd_int_value;
 
 /** A collection of data information types used for setting information with ohmd_set_data(). */

+ 10 - 2
src/drv_dummy/dummy.c

@@ -52,14 +52,19 @@ static int getf(ohmd_device* device, ohmd_float_value type, float* out)
 		// TODO this should be set to the equivalent of no distortion
 		memset(out, 0, sizeof(float) * 6);
 		break;
+	
+	case OHMD_ANALOG_AXES_STATE:
+		out[0] = .1f;
+		out[1] = .2f;
+		break;
 
 	default:
 		ohmd_set_error(priv->base.ctx, "invalid type given to getf (%ud)", type);
-		return -1;
+		return OHMD_S_INVALID_PARAMETER;
 		break;
 	}
 
-	return 0;
+	return OHMD_S_OK;
 }
 
 static void close_device(ohmd_device* device)
@@ -88,7 +93,10 @@ static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
 	priv->base.properties.lens_vpos = 0.046800f;
 	priv->base.properties.fov = DEG_TO_RAD(125.5144f);
 	priv->base.properties.ratio = (1280.0f / 800.0f) / 2.0f;
+	
+	// Some buttons and axes
 	priv->base.properties.digital_button_count = 4;
+	priv->base.properties.analog_axis_count = 2;
 
 	// calculate projection eye projection matrices from the device properties
 	ohmd_calc_default_proj_matrices(&priv->base.properties);

+ 5 - 1
src/openhmd.c

@@ -455,7 +455,7 @@ int OHMD_APIENTRY ohmd_device_geti(ohmd_device* device, ohmd_int_value type, int
 		case OHMD_BUTTON_COUNT:
 			*out = device->properties.digital_button_count;
 			return OHMD_S_OK;
-
+		
 		case OHMD_BUTTON_POP_EVENT: {
 				ohmd_digital_input_event event;
 
@@ -468,6 +468,10 @@ int OHMD_APIENTRY ohmd_device_geti(ohmd_device* device, ohmd_int_value type, int
 
 				return OHMD_S_OK;
 			}
+		
+		case OHMD_ANALOG_AXIS_COUNT:
+			*out = device->properties.analog_axis_count;
+			return OHMD_S_OK;
 
 		default:
 				return OHMD_S_INVALID_PARAMETER;

+ 1 - 0
src/openhmdi.h

@@ -62,6 +62,7 @@ typedef struct {
 		int hres;
 		int vres;
 		int digital_button_count;
+		int analog_axis_count;
 
 		float hsize;
 		float vsize;