OVR: Use hand directon and stick direction to walk where actually the stick is pushed to
[mercenary-reloaded.git] / src / libovr / keyboard.c
1 /* VR Keyboard
2  *
3  * (C) 2018 by Andreas Eversberg <jolly@eversberg.eu>
4  * All Rights Reserved
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdint.h>
23 #include <errno.h>
24 #include <math.h>
25 #include "../../include/keycodes.h"
26 #include "../libsdl/print.h"
27 #include "keyboard.h"
28 #define GL3_PROTOTYPES 1
29 #include <GL/glew.h>
30
31 #define MAX_KEYBOARDS   2       /* maximum number of keyboards to we have */
32 #define MAX_KEYS        64      /* maximum number of keys per keyboard */
33 #define MAX_KEY_LINES   16      /* maximum number of lines on each key */
34 #define TILT_KEYBOARD           /* keyboard is tilted up from horzontal x-z-plane to vertical x-y-plane */
35
36 /*
37  * The keys are defined by coordinates that are described by the following
38  * digits:
39  *
40  * a  b  c  d  e
41  *
42  * f  g  h  i  j
43  *
44  * k  l  m  n  o
45  *
46  * p  q  r  s  t
47  *
48  * u  v  w  x  y
49  *
50  * The lines are defined from digit to digit to digit.... To start with a
51  * new line (not connected to the previous one, add ' ' (space).
52  *
53  */
54
55 static struct key_font {
56         char key;
57         const char *font;
58 } key_font[] = {
59         { '0', "bdjtxvpfb qi" },
60         { '1', "gcw vx" },
61         { '2', "fbdjnlpuy" },
62         { '3', "fbdjntxvp ln" },
63         { '4', "ako hw" },
64         { '5', "eakntxu" },
65         { '6', "jdbfpvxtnk" },
66         { '7', "aemw" },
67         { '8', "lfbdjntxvpln" },
68         { '9', "jnlfbdjtxvp" },
69         { 'A', "ukoy kco" },
70         { 'B', "knjdauxtn" },
71         { 'C', "jdbfpvxt" },
72         { 'D', "adjtxua" },
73         { 'E', "eauy km" },
74         { 'F', "eau km" },
75         { 'G', "jdbfpvxt yom" },
76         { 'H', "au ey ko" },
77         { 'I', "bd vx cw" },
78         { 'J', "aetxvpk" },
79         { 'K', "au emy km" },
80         { 'L', "auy" },
81         { 'M', "uamey" },
82         { 'N', "uaye" },
83         { 'O', "bdjtxvpfb" },
84         { 'P', "uadjnk" },
85         { 'Q', "bdjtxvpfb ys" },
86         { 'R', "uadjnk my" },
87         { 'S', "jdbflntxvp" },
88         { 'T', "ae cw" },
89         { 'U', "apvxte" },
90         { 'V', "akwoe" },
91         { 'W', "aumye" },
92         { 'X', "ay ue" },
93         { 'Y', "ame mw" },
94         { 'Z', "aeuy" },
95         { 'u', "cw kco" },
96         { 'd', "cw kwo" },
97         { 'l', "ko ckw" },
98         { 'r', "ko cow" },
99         { '.', "rr" },
100         { ',', "rv" },
101         { '+', "cw ko" },
102         { '-', "ko" },
103         { '*', "ko ay ue" },
104         { 's', "" }, /* space */
105         { 'b', "beyvkb gs qi" },
106         { 'e', "dsp pl pv" },
107         { ' ', "" },
108         { 0, NULL }
109 };
110
111 /*
112  * f-keys are 25 percent larger, so 4 f-keys are as wide as 5 regular keys.
113  * This is why f-keys use 5 steps instead of four (regular keys).
114  */
115
116 static const char *keyboard_layout[] = {
117         "1   2   3   4   5   6   7   8   9   0   G",
118         "         fh       e                      ",
119         "    f1    f2    f0     7   8   9   *     ",
120         "                       4   5   6   -     ",
121         "           u           1   2   3   +     ",
122         "       l   d   r       02      e2        ",
123         NULL, /* end of keyboard */
124         "1   2   3   4   5   6   7   8   9   0   b",
125         "  Q   W   E   R   T   Y   U   I   O   P  ",
126         "   A   S   D   F   G   H   J   K   L   e ",
127         "     Z   X   C   V   B   N   M   ,   .   ",
128         "          s6                             ",
129         NULL, /* end of keyboard */
130         NULL, /* end of all keyboards */
131 };
132
133 static enum keycode keyboard_codes_1[] = {
134         KEYCODE_1, KEYCODE_2, KEYCODE_3, KEYCODE_4, KEYCODE_5, KEYCODE_6, KEYCODE_7, KEYCODE_8, KEYCODE_9, KEYCODE_0, KEYCODE_g,
135         KEYCODE_HELP, KEYCODE_RETURN,
136         KEYCODE_F1, KEYCODE_F2, KEYCODE_F10, KEYCODE_KP_7, KEYCODE_KP_8, KEYCODE_KP_9, KEYCODE_KP_MULTIPLY,
137         KEYCODE_KP_4, KEYCODE_KP_5, KEYCODE_KP_6, KEYCODE_KP_MINUS,
138         KEYCODE_UP, KEYCODE_KP_1, KEYCODE_KP_2, KEYCODE_KP_3, KEYCODE_KP_PLUS,
139         KEYCODE_LEFT, KEYCODE_DOWN, KEYCODE_RIGHT, KEYCODE_KP_0, KEYCODE_KP_ENTER,
140 };
141
142 static enum keycode keyboard_codes_2[] = {
143         KEYCODE_1, KEYCODE_2, KEYCODE_3, KEYCODE_4, KEYCODE_5, KEYCODE_6, KEYCODE_7, KEYCODE_8, KEYCODE_9, KEYCODE_0, KEYCODE_BACKSPACE,
144         KEYCODE_q, KEYCODE_w, KEYCODE_e, KEYCODE_r, KEYCODE_t, KEYCODE_y, KEYCODE_u, KEYCODE_i, KEYCODE_o, KEYCODE_p,
145         KEYCODE_a, KEYCODE_s, KEYCODE_d, KEYCODE_f, KEYCODE_g, KEYCODE_h, KEYCODE_j, KEYCODE_k, KEYCODE_l, KEYCODE_RETURN,
146         KEYCODE_z, KEYCODE_x, KEYCODE_c, KEYCODE_v, KEYCODE_b, KEYCODE_n, KEYCODE_m, KEYCODE_COMMA, KEYCODE_PERIOD,
147         KEYCODE_SPACE,
148 };
149
150 static enum keycode *keyboard_codes[] = {
151         keyboard_codes_1, keyboard_codes_2,
152 };
153
154 /* definition of keys with coordinates for rendering */
155
156 struct key_def {
157         char key;
158         int fkey;
159         double left_top_x, right_top_x;
160         double top_y;
161         double front_top_z, back_top_z;
162         double left_bottom_x, right_bottom_x;
163         double bottom_y;
164         double front_bottom_z, back_bottom_z;
165         double x1[MAX_KEY_LINES], y1[MAX_KEY_LINES], z1[MAX_KEY_LINES];
166         double x2[MAX_KEY_LINES], y2[MAX_KEY_LINES], z2[MAX_KEY_LINES];
167         int lines;
168 };
169
170 /* definition for each keyboard */
171 static struct keyboard_def {
172         struct key_def key[MAX_KEYS];
173         int keys;
174 } keyboard_def[MAX_KEYBOARDS];
175
176 static int keyboards = 0;
177
178 /*
179  * add key to keyboard_def[].key structure
180  *
181  *-4  -2     0     2 3 4
182  * +-------------------+ 4
183  * | +---------------+ | 3
184  * | | a  b  c  d  e | | 2
185  * | | f  g  h  i  j | | 1
186  * | | k  l  m  n  o | | 0
187  * | | p  q  r  s  t | | -1
188  * | | u  v  w  x  y | | -2
189  * | +---------------+ | -3
190  * +-------------------+ -4
191  *        (front)
192  */
193
194 static int add_key(char key, int fkey, double width, struct key_def *key_def)
195 {
196         int d, l, f, i;
197         double font_scale = 1.0, font_offset = 0.0;
198
199         memset(key_def, 0, sizeof(*key_def));
200
201         key_def->key = key;
202         key_def->fkey = fkey;
203
204         /* key case (see layout in the description above) */
205         key_def->left_top_x = -3.0;
206         key_def->right_top_x = 3.0 + (width - 1.0) * 9.0;
207         key_def->top_y = 0;
208         key_def->front_top_z = 3.0;
209         key_def->back_top_z = -3.0;
210         key_def->left_bottom_x = -4.0;
211         key_def->right_bottom_x = 4.0 + (width - 1.0) * 9.0;
212         key_def->bottom_y = -4.0;
213         key_def->front_bottom_z = 4.0;
214         key_def->back_bottom_z = -4.0;
215
216         /* lines to be drawn ontop of the key (see layout in the description above) */
217         l = 0;
218         /* up to 4 letters/digits are displayed on key */
219         for (d = 0; d < 4; d++) {
220                 if (!key_def->fkey) {
221                         /* render regular key */
222                         if (d == 0)
223                                 key = key_def->key;
224                         else
225                                 break;
226                 } else {
227                         /* render F-key */
228                         if (d == 0) {
229                                 font_scale = 0.5;
230                                 font_offset = -0.25;
231                                 if (key_def->key == 'h')
232                                         key = 'H';
233                                 else
234                                         key = 'F';
235                         }
236                         else if (d == 1) {
237                                 font_offset += 2.5;
238                                 if (key_def->key == 'h')
239                                         key = 'E';
240                                 else if (key_def->key != '0')
241                                         key = key_def->key;
242                                 else
243                                         key = '1';
244                         }
245                         else if (d == 2) {
246                                 font_offset += 2.5;
247                                 if (key_def->key == 'h')
248                                         key = 'L';
249                                 else if (key_def->key != '0')
250                                         break;
251                                 else
252                                         key = '0';
253                         }
254                         else if (d == 3) {
255                                 font_offset += 2.5;
256                                 if (key_def->key == 'h')
257                                         key = 'P';
258                                 else
259                                         break;
260                         }
261                 }
262                 /* search for key font */
263                 for (f = 0; key_font[f].key; f++) {
264                         if (key_font[f].key == key)
265                                 break;
266                 }
267                 if (!key_font[f].key) {
268                         print_error("Failed to find keyboard character '%c' in key_font, please fix\n", key);
269                         return -EINVAL;
270                 }
271                 /* generate lines */
272                 i = 0;
273                 while (key_font[f].font[i] && key_font[f].font[i + 1]) {
274                         /* skip spaces, but this should not happen */
275                         if (key_font[f].font[i] == ' ') {
276                                 i++;
277                                 continue;
278                         }
279                         /* the second character is space, so we start over with a new line sequence */
280                         if (key_font[f].font[i + 1] == ' ') {
281                                 i += 2;
282                                 continue;
283                         }
284                         /* add line */
285                         if (l == MAX_KEY_LINES) {
286                                 print_error("Failed to add key definition, maximum number of lines exeeded, please fix\n");
287                                 return -EINVAL;
288                         }
289                         key_def->x1[l] = (double)(((key_font[f].font[i] - 'a') % 5) - 2) * font_scale + font_offset;
290                         key_def->y1[l] = 0;
291                         key_def->z1[l] = (double)((key_font[f].font[i] - 'a') / 5) - 2;
292                         key_def->x2[l] = (double)(((key_font[f].font[i + 1] - 'a') % 5) - 2) * font_scale + font_offset;
293                         key_def->y2[l] = 0;
294                         key_def->z2[l] = (double)((key_font[f].font[i + 1] - 'a') / 5) - 2;
295                         l++;
296                         i++;
297                 }
298         }
299         key_def->lines = l;
300
301         return 0;
302 }
303
304 static void scale_key(double px, double py, double pz, double scale, struct key_def *key_def)
305 {
306         int l;
307
308         /* scale and translate key case */
309         key_def->left_top_x = key_def->left_top_x * scale + px;
310         key_def->right_top_x = key_def->right_top_x * scale + px;
311         key_def->top_y = key_def->top_y * scale + py;
312         key_def->front_top_z = key_def->front_top_z * scale + pz;
313         key_def->back_top_z = key_def->back_top_z * scale + pz;
314         key_def->left_bottom_x = key_def->left_bottom_x * scale + px;
315         key_def->right_bottom_x = key_def->right_bottom_x * scale + px;
316         key_def->bottom_y = key_def->bottom_y * scale + py;
317         key_def->front_bottom_z = key_def->front_bottom_z * scale + pz;
318         key_def->back_bottom_z = key_def->back_bottom_z * scale + pz;
319
320         /* scale and translate line ontop of keys */
321         for (l = 0; l < key_def->lines; l++) {
322                 key_def->x1[l] = key_def->x1[l] * scale + px;
323                 key_def->y1[l] = key_def->y1[l] * scale + py;
324                 key_def->z1[l] = key_def->z1[l] * scale + pz;
325                 key_def->x2[l] = key_def->x2[l] * scale + px;
326                 key_def->y2[l] = key_def->y2[l] * scale + py;
327                 key_def->z2[l] = key_def->z2[l] * scale + pz;
328         }
329 }
330
331 #define KEY_SIZE_INCH   3.0
332
333 int init_vr_keyboard(double keyboard_height, double keyboard_distance)
334 {
335         double width;
336         int l, k, y, x;
337         int rc;
338         int key, fkey;
339
340         l = 0;
341         /* count all keyboards */
342         while (keyboard_layout[l]) {
343                 k = 0;
344                 /* for each row in keyboard */
345                 for (y = 0; keyboard_layout[l]; y++, l++) {
346                         /* for each key in row */
347                         for (x = 0; keyboard_layout[l][x]; x++) {
348                                 /* skip spaces, because this is no key */
349                                 if (keyboard_layout[l][x] == ' ')
350                                         continue;
351                                 width = 1;
352                                 key = keyboard_layout[l][x];
353                                 fkey = 0;
354                                 /* if we have an F-key, this means size * 1.5 */
355                                 if (keyboard_layout[l][x] == 'f') {
356                                         if (keyboard_layout[l][x + 1] == 'h')
357                                                 width = 2.0; /* help key */
358                                         else
359                                                 width = 1.5; /* f-key */
360                                         key = keyboard_layout[l][x + 1];
361                                         fkey = 1;
362                                 } else
363                                 /* if we have a digit after the key, this means different size */
364                                 if (keyboard_layout[l][x + 1] > '0')
365                                         width = (double)(keyboard_layout[l][x + 1] - '0');
366                                 rc = add_key(key, fkey, width, &keyboard_def[keyboards].key[k]);
367                                 if (rc < 0)
368                                         return -EINVAL;
369 #ifdef TILT_KEYBOARD
370                                 scale_key(((double)x / 4.0 - 5.0) * KEY_SIZE_INCH, -keyboard_distance, (double)y * KEY_SIZE_INCH - keyboard_height, KEY_SIZE_INCH / 9, &keyboard_def[keyboards].key[k]);
371 #else
372                                 scale_key(((double)x / 4.0 - 5.0) * KEY_SIZE_INCH, keyboard_height, (double)y * KEY_SIZE_INCH - keyboard_distance, KEY_SIZE_INCH / 9, &keyboard_def[keyboards].key[k]);
373 #endif
374                                 k++;
375                                 /* skip size information, if any */
376                                 if (keyboard_layout[l][x + 1] > ' ')
377                                         x++;
378                         }
379                 }
380                 keyboard_def[keyboards].keys = k;
381                 keyboards++;
382                 l++;
383         }
384
385         return 0;
386 }
387
388 static int highlight_k;
389 static double from_x, from_y, from_z;
390 static double to_x, to_y, to_z;
391
392 /* calculate pointer and to what key it points to */
393 void handle_vr_keyboard(int keyboard, double pointer_x, double pointer_y, double pointer_z, double pointer_yaw, double pointer_pitch, enum keycode *key)
394 {
395         int k;
396         struct key_def *key_def;
397 #ifdef TILT_KEYBOARD
398         double keyboard_dist = keyboard_def[keyboard].key[0].y1[0]; /* just get the dist from first line of first key */
399 #else
400         double keyboard_height = keyboard_def[keyboard].key[0].y1[0]; /* just get the height from first line of first key */
401 #endif
402
403         /* generate poiting vector */
404         from_x = pointer_x;
405         from_y = pointer_y;
406         from_z = pointer_z;
407         to_x = from_x - sin(pointer_yaw) * cos(pointer_pitch) * 20;
408         to_y = from_y + sin(pointer_pitch) * 20;
409         to_z = from_z - cos(pointer_yaw) * cos(pointer_pitch) * 20;
410
411         /* if pointer points down, intersect with keyboard */
412         highlight_k = -1;
413 #ifdef TILT_KEYBOARD
414         if (from_z - 1.0 > keyboard_dist && to_z < from_z - 1.0) {
415                 to_x = (to_x - from_x) / (from_z - to_z) * (from_z - keyboard_dist) + from_x;
416                 to_y = (to_y - from_y) / (from_z - to_z) * (from_z - keyboard_dist) + from_y;
417                 to_z = keyboard_dist;
418
419                 /* find key that we intersect with */
420                 for (k = 0; k < keyboard_def[keyboard].keys; k++) {
421                         key_def = &keyboard_def[keyboard].key[k];
422                         if (to_x < key_def->left_top_x)
423                                 continue;
424                         if (to_x > key_def->right_top_x)
425                                 continue;
426                         if (-to_y < key_def->back_top_z)
427                                 continue;
428                         if (-to_y > key_def->front_top_z)
429                                 continue;
430                         highlight_k = k;
431                         *key = keyboard_codes[keyboard][k];
432                         break;
433                 }
434         }
435 #else
436         if (from_y - 1.0 > keyboard_height && to_y < from_y - 1.0) {
437                 to_x = (to_x - from_x) / (from_y - to_y) * (from_y - keyboard_height) + from_x;
438                 to_z = (to_z - from_z) / (from_y - to_y) * (from_y - keyboard_height) + from_z;
439                 to_y = keyboard_height;
440
441                 /* find key that we intersect with */
442                 for (k = 0; k < keyboard_def[keyboard].keys; k++) {
443                         key_def = &keyboard_def[keyboard].key[k];
444                         if (to_x < key_def->left_top_x)
445                                 continue;
446                         if (to_x > key_def->right_top_x)
447                                 continue;
448                         if (to_z < key_def->back_top_z)
449                                 continue;
450                         if (to_z > key_def->front_top_z)
451                                 continue;
452                         highlight_k = k;
453                         *key = keyboard_codes[keyboard][k];
454                         break;
455                 }
456         }
457 #endif
458 }
459
460 #ifdef TILT_KEYBOARD
461 #define FLIP_YZ(y, z) -z, y
462 #else
463 #define FLIP_YZ(y, z) y, z
464 #endif
465
466 /* render keyboard per eye */
467 void render_vr_keyboard(int keyboard, double camera_x, double camera_y)
468 {
469         int k, l, distant_k;
470         int rendered[MAX_KEYS];
471         double dists[MAX_KEYS], dist_x, dist_y, dist;
472         struct key_def *key_def;
473
474         glEnable(GL_CULL_FACE);
475         glFrontFace(GL_CW);
476         glCullFace(GL_FRONT);
477
478         memset(rendered, 0, sizeof(rendered));
479
480         /* calculate distances to keys */
481         for (k = 0; k < keyboard_def[keyboard].keys; k++) {
482                 key_def = &keyboard_def[keyboard].key[k];
483 #ifdef TILT_KEYBOARD
484                 dist_x = (key_def->left_top_x + key_def->right_top_x) / 2.0 - camera_x;
485                 dist_y = (key_def->front_top_z + key_def->back_top_z) / 2.0 + camera_y;
486 #else
487                 dist_x = (key_def->left_top_x + key_def->right_top_x) / 2.0 - camera_x;
488                 dist_y = (key_def->front_top_z + key_def->back_top_z) / 2.0;
489 #endif
490                 dists[k] = sqrt(dist_x * dist_x + dist_y * dist_y);
491         }
492
493         while (1) {
494                 key_def = NULL;
495                 /* search for most distant key */
496                 for (k = 0; k < keyboard_def[keyboard].keys; k++) {
497                         /* skip keys that have been already rendered */
498                         if (rendered[k])
499                                 continue;
500                         if (!key_def || dists[k] > dist) {
501                                 dist = dists[k];
502                                 key_def = &keyboard_def[keyboard].key[k];
503                                 distant_k = k;
504                         }
505                 }
506                 /* no unrendered key, we are done */
507                 if (!key_def)
508                         break;
509                 rendered[distant_k] = 1;
510
511                 /* render case of key */
512                 glBegin(GL_QUADS);
513                 /* top plane */
514                 if (distant_k == highlight_k)
515                         glColor4f(0.0, 0.7, 0.7, 1.0);
516                 else
517                         glColor4f(0.5, 0.5, 0.5, 1.0);
518                 glVertex3f(key_def->left_top_x, FLIP_YZ(key_def->top_y, key_def->back_top_z));
519                 glVertex3f(key_def->right_top_x, FLIP_YZ(key_def->top_y, key_def->back_top_z));
520                 glVertex3f(key_def->right_top_x, FLIP_YZ(key_def->top_y, key_def->front_top_z));
521                 glVertex3f(key_def->left_top_x, FLIP_YZ(key_def->top_y, key_def->front_top_z));
522                 /* front plane (in front of player) */
523                 glColor4f(0.1, 0.1, 0.1, 1.0);
524                 glVertex3f(key_def->left_top_x, FLIP_YZ(key_def->top_y, key_def->front_top_z));
525                 glVertex3f(key_def->right_top_x, FLIP_YZ(key_def->top_y, key_def->front_top_z));
526                 glVertex3f(key_def->right_bottom_x, FLIP_YZ(key_def->bottom_y, key_def->front_bottom_z));
527                 glVertex3f(key_def->left_bottom_x, FLIP_YZ(key_def->bottom_y, key_def->front_bottom_z));
528                 /* back plane (away from player) */
529                 glColor4f(0.3, 0.3, 0.3, 1.0);
530                 glVertex3f(key_def->right_top_x, FLIP_YZ(key_def->top_y, key_def->back_top_z));
531                 glVertex3f(key_def->left_top_x, FLIP_YZ(key_def->top_y, key_def->back_top_z));
532                 glVertex3f(key_def->left_bottom_x, FLIP_YZ(key_def->bottom_y, key_def->back_bottom_z));
533                 glVertex3f(key_def->right_bottom_x, FLIP_YZ(key_def->bottom_y, key_def->back_bottom_z));
534                 /* left plane */
535                 glColor4f(0.2, 0.2, 0.2, 1.0);
536                 glVertex3f(key_def->left_top_x, FLIP_YZ(key_def->top_y, key_def->back_top_z));
537                 glVertex3f(key_def->left_top_x, FLIP_YZ(key_def->top_y, key_def->front_top_z));
538                 glVertex3f(key_def->left_bottom_x, FLIP_YZ(key_def->bottom_y, key_def->front_bottom_z));
539                 glVertex3f(key_def->left_bottom_x, FLIP_YZ(key_def->bottom_y, key_def->back_bottom_z));
540                 /* right plane */
541                 glVertex3f(key_def->right_top_x, FLIP_YZ(key_def->top_y, key_def->front_top_z));
542                 glVertex3f(key_def->right_top_x, FLIP_YZ(key_def->top_y, key_def->back_top_z));
543                 glVertex3f(key_def->right_bottom_x, FLIP_YZ(key_def->bottom_y, key_def->back_bottom_z));
544                 glVertex3f(key_def->right_bottom_x, FLIP_YZ(key_def->bottom_y, key_def->front_bottom_z));
545                 /* no bottom plane, because it is unlikely visible */
546                 glEnd();
547
548                 /* render lines of key */
549                 glColor4f(1.0, 1.0, 1.0, 1.0);
550                 for (l = 0; l < key_def->lines; l++) {
551                         if (key_def->x1[l] == key_def->x2[l] && key_def->z1[l] == key_def->z2[l]) {
552                                 /* just a point */
553                                 glBegin(GL_POINTS);
554                                 glVertex3f(key_def->x1[l], FLIP_YZ(key_def->y1[l], key_def->z1[l]));
555                                 glEnd();
556                         } else {
557                                 glBegin(GL_LINES);
558                                 glVertex3f(key_def->x1[l], FLIP_YZ(key_def->y1[l], key_def->z1[l]));
559                                 glVertex3f(key_def->x2[l], FLIP_YZ(key_def->y2[l], key_def->z2[l]));
560                                 glEnd();
561                         }
562                 }
563         }
564
565         glDisable(GL_CULL_FACE);
566
567         /* render pointer */
568         glColor4f(1.0, 0.0, 0.0, 1.0);
569         glBegin(GL_LINES);
570         glVertex3f(from_x, from_y, from_z);
571         glVertex3f(to_x, to_y, to_z);
572         glEnd();
573 }
574