// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/apps/gapsview/gapsview.cpp
// Function: GLUTKeyboard(unsigned char, int, int)
static void
GLUTKeyboard(unsigned char key, int x, int y)
{
  // Initialize redraw
  RNBoolean redraw = TRUE;

  // Determine modifiers
  int modifiers = glutGetModifiers();
  int ctrl = (modifiers & GLUT_ACTIVE_CTRL);
  int alt = (modifiers & GLUT_ACTIVE_ALT);

  // Process keyboard button event
  if (ctrl) {
    // Control which data sources are drawn
    switch(key) {
    case 7: // ctrl-G
      show_grids = !show_grids;
      break;

    case 12: // ctrl-L
      show_gsvs = !show_gsvs;
      break;

    case 13: // ctrl-M
      show_meshes = !show_meshes;
      break;

    case 15: // ctrl-O
      show_scenes = !show_scenes;
      break;

    case 16: // ctrl-P
      show_pointsets = !show_pointsets;
      break;

    case 19: // ctrl-S
      show_sfls = !show_sfls;
      break;

    default:
      redraw = FALSE;
      break;
    }
  }
  else if (alt) {
    // Control how things are drawn
    switch (key) {
    case 'C':
    case 'c':
      color_scheme = RGB_COLOR_SCHEME;
      break;

    case 'E':
    case 'e':
      color_scheme = NULL_COLOR_SCHEME;
      break;

    case 'I':
    case 'i':
      color_scheme = INSTANCE_COLOR_SCHEME;
      break;

    case 'L':
    case 'l':
      color_scheme = CATEGORY_COLOR_SCHEME;
      break;

    case 'S':
    case 's':
      color_scheme = SHADING_COLOR_SCHEME;
      break;

    case 'X':
      if (selected_model_index < grids.NEntries()) {
        grid_slice_coords[RN_X]++;
        if (grid_slice_coords[RN_X] >= grids[selected_model_index]->XResolution()) 
          grid_slice_coords[RN_X] = grids[selected_model_index]->XResolution() - 1;
      }
      break;

    case 'x':
      if (selected_model_index < grids.NEntries()) {
        grid_slice_coords[RN_X]--;
        if (grid_slice_coords[RN_X] < 0)
          grid_slice_coords[RN_X] = 0;
      }
      break;

    case 'Y':
      if (selected_model_index < grids.NEntries()) {
        grid_slice_coords[RN_Y]++;
        if (grid_slice_coords[RN_Y] >= grids[selected_model_index]->YResolution()) 
          grid_slice_coords[RN_Y] = grids[selected_model_index]->YResolution() - 1;
      }
      break;

    case 'y':
      if (selected_model_index < grids.NEntries()) {
        grid_slice_coords[RN_Y]--;
        if (grid_slice_coords[RN_Y] < 0)
          grid_slice_coords[RN_Y] = 0;
      }
      break;

    case 'Z':
      if (selected_model_index < grids.NEntries()) {
        grid_slice_coords[RN_Z]++;
        if (grid_slice_coords[RN_Z] >= grids[selected_model_index]->ZResolution()) 
          grid_slice_coords[RN_Z] = grids[selected_model_index]->ZResolution() - 1;
      }
      break;

    case 'z':
      if (selected_model_index < grids.NEntries()) {
        grid_slice_coords[RN_Z]--;
        if (grid_slice_coords[RN_Z] < 0)
          grid_slice_coords[RN_Z] = 0;
      }
      break;

    default:
      redraw = FALSE;
      break;
    }
  }
  else {
    // Control which data elements are drawn
    switch (key) {
    case '1':
    case '2':
    case '3':
    case '4':
      selected_model_index = key - '1';
      if (selected_model_index > nmodels - 1) {
        selected_model_index = nmodels - 1;
      }
      break;

    case 'A':
    case 'a':
      show_axes = !show_axes;
      break;

    case 'B':
    case 'b':
      show_bbox = !show_bbox;
      break;

    case 'C':
    case 'c':
      show_cameras = !show_cameras;
      break;

    case 'D':
    case 'd':
      show_image_depths = !show_image_depths;
      break;
      
    case 'E':
    case 'e':
      show_edges = !show_edges;
      break;

    case 'F':
    case 'f':
      show_surfaces = !show_surfaces;
      break;

    case 'G':
    case 'g':
      show_slices = !show_slices;
      break;

    case 'I':
      show_image_billboards = !show_image_billboards;
      break;

    case 'i':
      show_image_insets = !show_image_insets;
      break;

    case 'L':
    case 'l':
      show_text_labels = !show_text_labels;
      break;

    case 'N':
    case 'n':
      show_normals = !show_normals;
      break;

    case 'P':
    case 'p':
      show_points = !show_points;
      break;

    case 'R':
    case 'r':
      show_image_rays = !show_image_rays;
      break;

    case 'T':
    case 't':
      show_grid_threshold = !show_grid_threshold;
      break;

    case ' ': {
      // Print camera
      const R3Camera& camera = viewer->Camera();
      printf("#camera  %g %g %g  %g %g %g  %g %g %g  %g \n",
             camera.Origin().X(), camera.Origin().Y(), camera.Origin().Z(),
             camera.Towards().X(), camera.Towards().Y(), camera.Towards().Z(),
             camera.Up().X(), camera.Up().Y(), camera.Up().Z(),
             camera.YFOV());
      break; }
      
    case 27: // ESCAPE
      GLUTStop();
      break;

    default:
      redraw = FALSE;
      break;
    }
  }
  
  // Remember mouse position 
  GLUTmouse[0] = x;
  GLUTmouse[1] = GLUTwindow_height - y;

  // Remember modifiers 
  GLUTmodifiers = modifiers;

  // Redraw
  if (redraw) glutPostRedisplay();  
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x80, %rsp
movl %edx, %ebx
movl %esi, %ebp
movl %edi, %r14d
callq 0xf82b6
testb $0x2, %al
jne 0x2ca11
testb $0x4, %al
jne 0x2ca48
movzbl %r14b, %ecx
leal -0x31(%rcx), %eax
cmpl $0x43, %eax
ja 0x2cdea
leaq 0xfe81d(%rip), %rcx     # 0x12b204
movslq (%rcx,%rax,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movl %eax, 0x1977ae(%rip)    # 0x1c41a4
movl 0x1979e8(%rip), %ecx    # 0x1c43e4
cmpl %ecx, %eax
jl 0x2cf12
decl %ecx
movl %ecx, 0x197798(%rip)    # 0x1c41a4
jmp 0x2cf12
movzbl %r14b, %eax
addl $-0x7, %eax
cmpl $0xc, %eax
ja 0x2cdf8
leaq 0xfe718(%rip), %rcx     # 0x12b140
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %eax, %eax
cmpl $0x0, 0x19207a(%rip)    # 0x1beab4
sete %al
movl %eax, 0x192071(%rip)    # 0x1beab4
jmp 0x2cf12
movzbl %r14b, %eax
leal -0x43(%rax), %ecx
cmpl $0x9, %ecx
jbe 0x2caf3
leal -0x53(%rax), %ecx
cmpl $0x7, %ecx
jbe 0x2cb12
leal -0x63(%rax), %ecx
cmpl $0x9, %ecx
ja 0x2cb69
leaq 0xfe745(%rip), %rax     # 0x12b1bc
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
xorl %eax, %eax
cmpl $0x0, 0x192027(%rip)    # 0x1beab0
sete %al
movl %eax, 0x19201e(%rip)    # 0x1beab0
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x192018(%rip)    # 0x1beab8
sete %al
movl %eax, 0x19200f(%rip)    # 0x1beab8
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x192009(%rip)    # 0x1beac0
sete %al
movl %eax, 0x192000(%rip)    # 0x1beac0
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x191fde(%rip)    # 0x1beaac
sete %al
movl %eax, 0x191fd5(%rip)    # 0x1beaac
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x191fbf(%rip)    # 0x1beaa4
sete %al
movl %eax, 0x191fb6(%rip)    # 0x1beaa4
jmp 0x2cf12
leaq 0xfe67a(%rip), %rax     # 0x12b174
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl $0x1, 0x191f93(%rip)    # 0x1beaa0
jmp 0x2cf12
leaq 0xfe683(%rip), %rax     # 0x12b19c
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movslq 0x19767b(%rip), %rax    # 0x1c41a4
cmpl 0x1971c5(%rip), %eax    # 0x1c3cf4
jge 0x2cf12
movl 0x197645(%rip), %ecx    # 0x1c4180
incl %ecx
movl %ecx, 0x19763d(%rip)    # 0x1c4180
movq 0x19719e(%rip), %rdx    # 0x1c3ce8
movq (%rdx,%rax,8), %rax
movl 0x238(%rax), %eax
cmpl %eax, %ecx
jl 0x2cf12
decl %eax
movl %eax, 0x19761c(%rip)    # 0x1c4180
jmp 0x2cf12
addl $-0x73, %eax
cmpl $0x7, %eax
ja 0x2cdf8
leaq 0xfe668(%rip), %rcx     # 0x12b1e4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x2, 0x191f11(%rip)    # 0x1beaa0
jmp 0x2cf12
andl $0x0, 0x191f05(%rip)    # 0x1beaa0
jmp 0x2cf12
movl $0x4, 0x191ef6(%rip)    # 0x1beaa0
jmp 0x2cf12
movl $0x3, 0x191ee7(%rip)    # 0x1beaa0
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x197811(%rip)    # 0x1c43d8
sete %al
movl %eax, 0x197808(%rip)    # 0x1c43d8
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x1975ce(%rip)    # 0x1c41ac
sete %al
movl %eax, 0x1975c5(%rip)    # 0x1c41ac
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x1975b3(%rip)    # 0x1c41a8
sete %al
movl %eax, 0x1975aa(%rip)    # 0x1c41a8
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x1977d4(%rip)    # 0x1c43e0
sete %al
movl %eax, 0x1977cb(%rip)    # 0x1c43e0
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x1977b1(%rip)    # 0x1c43d4
sete %al
movl %eax, 0x1977a8(%rip)    # 0x1c43d4
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x197786(%rip)    # 0x1c43c0
sete %al
movl %eax, 0x19777d(%rip)    # 0x1c43c0
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x191e6b(%rip)    # 0x1beabc
sete %al
movl %eax, 0x191e62(%rip)    # 0x1beabc
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x197774(%rip)    # 0x1c43dc
sete %al
movl %eax, 0x19776b(%rip)    # 0x1c43dc
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x197531(%rip)    # 0x1c41b0
sete %al
movl %eax, 0x197528(%rip)    # 0x1c41b0
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x197732(%rip)    # 0x1c43c8
sete %al
movl %eax, 0x197729(%rip)    # 0x1c43c8
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x191dfb(%rip)    # 0x1beaa8
sete %al
movl %eax, 0x191df2(%rip)    # 0x1beaa8
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x197700(%rip)    # 0x1c43c4
sete %al
movl %eax, 0x1976f7(%rip)    # 0x1c43c4
jmp 0x2cf12
movslq 0x1974cb(%rip), %rax    # 0x1c41a4
cmpl 0x197015(%rip), %eax    # 0x1c3cf4
jge 0x2cf12
movl 0x197499(%rip), %ecx    # 0x1c4184
incl %ecx
movl %ecx, 0x197491(%rip)    # 0x1c4184
movq 0x196fee(%rip), %rdx    # 0x1c3ce8
movq (%rdx,%rax,8), %rax
movl 0x23c(%rax), %eax
cmpl %eax, %ecx
jl 0x2cf12
decl %eax
movl %eax, 0x197470(%rip)    # 0x1c4184
jmp 0x2cf12
movslq 0x197484(%rip), %rax    # 0x1c41a4
cmpl 0x196fce(%rip), %eax    # 0x1c3cf4
jge 0x2cf12
movl 0x197456(%rip), %ecx    # 0x1c4188
incl %ecx
movl %ecx, 0x19744e(%rip)    # 0x1c4188
movq 0x196fa7(%rip), %rdx    # 0x1c3ce8
movq (%rdx,%rax,8), %rax
movl 0x240(%rax), %eax
cmpl %eax, %ecx
jl 0x2cf12
decl %eax
movl %eax, 0x19742d(%rip)    # 0x1c4188
jmp 0x2cf12
movl 0x19743e(%rip), %eax    # 0x1c41a4
cmpl 0x196f88(%rip), %eax    # 0x1c3cf4
jge 0x2cf12
movl 0x197408(%rip), %eax    # 0x1c4180
cmpl $0x2, %eax
pushq $0x1
popq %rcx
cmovgel %eax, %ecx
decl %ecx
movl %ecx, 0x1973f7(%rip)    # 0x1c4180
jmp 0x2cf12
movl 0x197410(%rip), %eax    # 0x1c41a4
cmpl 0x196f5a(%rip), %eax    # 0x1c3cf4
jge 0x2cf12
movl 0x1973de(%rip), %eax    # 0x1c4184
cmpl $0x2, %eax
pushq $0x1
popq %rcx
cmovgel %eax, %ecx
decl %ecx
movl %ecx, 0x1973cd(%rip)    # 0x1c4184
jmp 0x2cf12
movl 0x1973e2(%rip), %eax    # 0x1c41a4
cmpl 0x196f2c(%rip), %eax    # 0x1c3cf4
jge 0x2cf12
movl 0x1973b4(%rip), %eax    # 0x1c4188
cmpl $0x2, %eax
pushq $0x1
popq %rcx
cmovgel %eax, %ecx
decl %ecx
movl %ecx, 0x1973a3(%rip)    # 0x1c4188
jmp 0x2cf12
cmpl $0x20, %ecx
je 0x2ce3f
cmpl $0x1b, %ecx
je 0x2cf3b
movl %ebp, 0x1975ea(%rip)    # 0x1c43e8
movl 0x191c10(%rip), %eax    # 0x1bea14
subl %ebx, %eax
movl %eax, 0x1975e0(%rip)    # 0x1c43ec
jmp 0x2cf2b
xorl %eax, %eax
cmpl $0x0, 0x1975b6(%rip)    # 0x1c43d0
sete %al
movl %eax, 0x1975ad(%rip)    # 0x1c43d0
jmp 0x2cf12
xorl %eax, %eax
cmpl $0x0, 0x19759b(%rip)    # 0x1c43cc
sete %al
movl %eax, 0x197592(%rip)    # 0x1c43cc
jmp 0x2cf12
movq 0x19734a(%rip), %r12    # 0x1c4190
movsd 0x8(%r12), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x10(%r12), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x18(%r12), %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x50(%r12), %r14
leaq 0x68(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xc1f22
movsd (%r15), %xmm0
movsd %xmm0, 0x18(%rsp)
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xc1f22
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x38(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xc1f22
movsd 0x10(%r15), %xmm5
movsd 0x38(%r12), %xmm6
movsd 0x40(%r12), %xmm7
movsd 0x48(%r12), %xmm0
movsd 0x70(%r12), %xmm1
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, (%rsp)
leaq 0xfe52f(%rip), %rdi     # 0x12b41c
movsd 0x30(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
movsd 0x18(%rsp), %xmm3
movsd 0x10(%rsp), %xmm4
movb $0x8, %al
callq 0x27080
movl %ebp, 0x1974d0(%rip)    # 0x1c43e8
movl 0x191af6(%rip), %eax    # 0x1bea14
subl %ebx, %eax
movl %eax, 0x1974c6(%rip)    # 0x1c43ec
callq 0xf3818
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl 0x196dc3(%rip), %eax    # 0x1c3d04
xorl %r14d, %r14d
movslq %eax, %rcx
cmpq %rcx, %r14
jge 0x2cf81
movq 0x196da5(%rip), %rcx    # 0x1c3cf8
movq (%rcx,%r14,8), %rbx
testq %rbx, %rbx
je 0x2cf7c
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x168(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0xf8(%rax)
movl 0x196d88(%rip), %eax    # 0x1c3d04
incq %r14
jmp 0x2cf44
movl 0x197219(%rip), %edi    # 0x1c41a0
callq 0xf959d
xorl %edi, %edi
callq 0x27b70