From 4f47791dab553d6776b47ab4b0a2acb4ef2732b7 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sat, 28 Apr 2018 15:12:15 +0200 Subject: [PATCH] OVR: Improved keyboard, so it can be used with touch and xbox controller --- src/libovr/keyboard.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 4 deletions(-) diff --git a/src/libovr/keyboard.c b/src/libovr/keyboard.c index 7784e55..82831ee 100644 --- a/src/libovr/keyboard.c +++ b/src/libovr/keyboard.c @@ -30,7 +30,7 @@ #define MAX_KEYBOARDS 2 /* maximum number of keyboards to we have */ #define MAX_KEYS 64 /* maximum number of keys per keyboard */ -#define MAX_KEY_LINES 16 /* maximum number of lines on each key */ +#define MAX_KEY_LINES 32 /* maximum number of lines on each key */ #define TILT_KEYBOARD /* keyboard is tilted up from horzontal x-z-plane to vertical x-y-plane */ /* @@ -115,7 +115,7 @@ static struct key_font { static const char *keyboard_layout[] = { "1 2 3 4 5 6 7 8 9 0 G", - " fh e ", + " fh fr ", " f1 f2 f0 7 8 9 * ", " 4 5 6 - ", " u 1 2 3 + ", @@ -216,7 +216,7 @@ static int add_key(char key, int fkey, double width, struct key_def *key_def) /* lines to be drawn ontop of the key (see layout in the description above) */ l = 0; /* up to 4 letters/digits are displayed on key */ - for (d = 0; d < 4; d++) { + for (d = 0; d < 6; d++) { if (!key_def->fkey) { /* render regular key */ if (d == 0) @@ -230,6 +230,8 @@ static int add_key(char key, int fkey, double width, struct key_def *key_def) font_offset = -0.25; if (key_def->key == 'h') key = 'H'; + else if (key_def->key == 'r') + key = 'R'; else key = 'F'; } @@ -237,6 +239,8 @@ static int add_key(char key, int fkey, double width, struct key_def *key_def) font_offset += 2.5; if (key_def->key == 'h') key = 'E'; + else if (key_def->key == 'r') + key = 'E'; else if (key_def->key != '0') key = key_def->key; else @@ -246,6 +250,8 @@ static int add_key(char key, int fkey, double width, struct key_def *key_def) font_offset += 2.5; if (key_def->key == 'h') key = 'L'; + else if (key_def->key == 'r') + key = 'T'; else if (key_def->key != '0') break; else @@ -255,6 +261,22 @@ static int add_key(char key, int fkey, double width, struct key_def *key_def) font_offset += 2.5; if (key_def->key == 'h') key = 'P'; + else if (key_def->key == 'r') + key = 'U'; + else + break; + } + else if (d == 4) { + font_offset += 2.5; + if (key_def->key == 'r') + key = 'R'; + else + break; + } + else if (d == 5) { + font_offset += 2.5; + if (key_def->key == 'r') + key = 'N'; else break; } @@ -356,6 +378,9 @@ int init_vr_keyboard(double keyboard_height, double keyboard_distance) if (keyboard_layout[l][x + 1] == 'h') width = 2.0; /* help key */ else + if (keyboard_layout[l][x + 1] == 'r') + width = 2.5; /* return key */ + else width = 1.5; /* f-key */ key = keyboard_layout[l][x + 1]; fkey = 1; @@ -388,6 +413,7 @@ int init_vr_keyboard(double keyboard_height, double keyboard_distance) static int highlight_k; static double from_x, from_y, from_z; static double to_x, to_y, to_z; +static int pointer_valid; /* calculate pointer and to what key it points to */ void handle_vr_keyboard(int keyboard, double pointer_x, double pointer_y, double pointer_z, double pointer_yaw, double pointer_pitch, enum keycode *key) @@ -407,11 +433,13 @@ void handle_vr_keyboard(int keyboard, double pointer_x, double pointer_y, double to_x = from_x - sin(pointer_yaw) * cos(pointer_pitch) * 20; to_y = from_y + sin(pointer_pitch) * 20; to_z = from_z - cos(pointer_yaw) * cos(pointer_pitch) * 20; + pointer_valid = 0; /* if pointer points down, intersect with keyboard */ highlight_k = -1; #ifdef TILT_KEYBOARD if (from_z - 1.0 > keyboard_dist && to_z < from_z - 1.0) { + pointer_valid = 1; to_x = (to_x - from_x) / (from_z - to_z) * (from_z - keyboard_dist) + from_x; to_y = (to_y - from_y) / (from_z - to_z) * (from_z - keyboard_dist) + from_y; to_z = keyboard_dist; @@ -434,6 +462,7 @@ void handle_vr_keyboard(int keyboard, double pointer_x, double pointer_y, double } #else if (from_y - 1.0 > keyboard_height && to_y < from_y - 1.0) { + pointer_valid = 1; to_x = (to_x - from_x) / (from_y - to_y) * (from_y - keyboard_height) + from_x; to_z = (to_z - from_z) / (from_y - to_y) * (from_y - keyboard_height) + from_z; to_y = keyboard_height; @@ -564,11 +593,70 @@ void render_vr_keyboard(int keyboard, double camera_x, double camera_y) glDisable(GL_CULL_FACE); - /* render pointer */ + if (!pointer_valid) + return; + if (to_x > 25 || to_x < -25 || to_y > 20 || to_y < -20) + return; +#if 0 + /* render pointer as a line from pose to keyboard */ glColor4f(1.0, 0.0, 0.0, 1.0); glBegin(GL_LINES); glVertex3f(from_x, from_y, from_z); glVertex3f(to_x, to_y, to_z); glEnd(); +#endif + +#if 0 + /* render dot where pose points to */ + double delta = 0.20; + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBegin(GL_POLYGON); + glColor4f(1.0, 0.0, 0.0, 0.7); + glVertex3f(to_x - delta / 2, to_y + delta, to_z); + glVertex3f(to_x + delta / 2, to_y + delta, to_z); + glVertex3f(to_x + delta, to_y + delta / 2, to_z); + glVertex3f(to_x + delta, to_y - delta / 2, to_z); + glVertex3f(to_x + delta / 2, to_y - delta, to_z); + glVertex3f(to_x - delta / 2, to_y - delta, to_z); + glVertex3f(to_x - delta, to_y - delta / 2, to_z); + glVertex3f(to_x - delta, to_y + delta / 2, to_z); + glEnd(); + glDisable(GL_BLEND); +#endif + +#if 1 + /* render a 'shot' */ + double delta = 0.50; + glBegin(GL_LINES); + glColor4f(1.0, 1.0, 1.0, 1.0); + glVertex3f(to_x - delta / 2, to_y + delta, to_z - delta / 2 + delta); + glVertex3f(to_x + delta / 2, to_y - delta, to_z + delta / 2 + delta); + glVertex3f(to_x + delta / 2, to_y + delta, to_z - delta / 2 + delta); + glVertex3f(to_x - delta / 2, to_y - delta, to_z + delta / 2 + delta); + glVertex3f(to_x - delta / 2, to_y + delta, to_z + delta / 2 + delta); + glVertex3f(to_x + delta / 2, to_y - delta, to_z - delta / 2 + delta); + glVertex3f(to_x + delta / 2, to_y + delta, to_z + delta / 2 + delta); + glVertex3f(to_x - delta / 2, to_y - delta, to_z - delta / 2 + delta); + + glVertex3f(to_x - delta, to_y + delta / 2, to_z - delta / 2 + delta); + glVertex3f(to_x + delta, to_y - delta / 2, to_z + delta / 2 + delta); + glVertex3f(to_x - delta, to_y - delta / 2, to_z - delta / 2 + delta); + glVertex3f(to_x + delta, to_y + delta / 2, to_z + delta / 2 + delta); + glVertex3f(to_x - delta, to_y + delta / 2, to_z + delta / 2 + delta); + glVertex3f(to_x + delta, to_y - delta / 2, to_z - delta / 2 + delta); + glVertex3f(to_x - delta, to_y - delta / 2, to_z + delta / 2 + delta); + glVertex3f(to_x + delta, to_y + delta / 2, to_z - delta / 2 + delta); + + glVertex3f(to_x - delta / 2, to_y + delta / 2, to_z + delta + delta); + glVertex3f(to_x + delta / 2, to_y - delta / 2, to_z - delta + delta); + glVertex3f(to_x + delta / 2, to_y + delta / 2, to_z + delta + delta); + glVertex3f(to_x - delta / 2, to_y - delta / 2, to_z - delta + delta); + glVertex3f(to_x - delta / 2, to_y - delta / 2, to_z + delta + delta); + glVertex3f(to_x + delta / 2, to_y + delta / 2, to_z - delta + delta); + glVertex3f(to_x + delta / 2, to_y - delta / 2, to_z + delta + delta); + glVertex3f(to_x - delta / 2, to_y + delta / 2, to_z - delta + delta); + glEnd(); +#endif } -- 2.13.6