// File: tomfunkhouser[P]gaps/apps/grdview/grdview.cpp
// Function: GLUTKeyboard(unsigned char, int, int)
void GLUTKeyboard(unsigned char key, int x, int y)
{
  // Process keyboard button event 
  switch (key) {
  case 'A':
  case 'a':
    show_axes = !show_axes;
    break;

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

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

  case 'I':
  case 'i':
    show_isosurface = !show_isosurface;
    break;

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

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

  case 'W':
  case 'w':
    show_slices[0] = !show_slices[0];
    show_slices[1] = show_slices[0];
    show_slices[2] = show_slices[0];
    break;

  case 'X':
    grid_slice_coords[RN_X]++;
    if (grid_slice_coords[RN_X] >= grid->XResolution()) 
      grid_slice_coords[RN_X] = grid->XResolution() - 1;
    break;

  case 'x':
    grid_slice_coords[RN_X]--;
    if (grid_slice_coords[RN_X] < 0)
      grid_slice_coords[RN_X] = 0;
    break;

  case 'Y':
    grid_slice_coords[RN_Y]++;
    if (grid_slice_coords[RN_Y] >= grid->YResolution()) 
      grid_slice_coords[RN_Y] = grid->YResolution() - 1;
    break;

  case 'y':
    grid_slice_coords[RN_Y]--;
    if (grid_slice_coords[RN_Y] < 0)
      grid_slice_coords[RN_Y] = 0;
    break;

  case 'Z':
    grid_slice_coords[RN_Z]++;
    if (grid_slice_coords[RN_Z] >= grid->ZResolution()) 
      grid_slice_coords[RN_Z] = grid->ZResolution() - 1;
    break;

  case 'z':
    grid_slice_coords[RN_Z]--;
    if (grid_slice_coords[RN_Z] < 0)
      grid_slice_coords[RN_Z] = 0;
    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;
  }

  // Remember mouse position 
  GLUTmouse[0] = x;
  GLUTmouse[1] = GLUTwindow_height - y;

  // Remember modifiers 
  GLUTmodifiers = glutGetModifiers();

  // Redraw
  glutPostRedisplay();  
}

// Assembly:
subq $0xd8, %rsp
movb %dil, %al
movb %al, 0xd7(%rsp)
movl %esi, 0xd0(%rsp)
movl %edx, 0xcc(%rsp)
movzbl 0xd7(%rsp), %eax
addl $-0x1b, %eax
movl %eax, %ecx
movq %rcx, 0x70(%rsp)
subl $0x5f, %eax
ja 0x256ed
movq 0x70(%rsp), %rax
leaq 0x139d7e(%rip), %rcx    # 0x15f0a4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x0, 0x19cf2e(%rip)    # 0x1c2264
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x19cf1e(%rip)    # 0x1c2264
jmp 0x256ed
cmpl $0x0, 0x18e586(%rip)    # 0x1b38d8
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x18e576(%rip)    # 0x1b38d8
jmp 0x256ed
cmpl $0x0, 0x19ceca(%rip)    # 0x1c2238
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x19ceba(%rip)    # 0x1c2238
jmp 0x256ed
cmpl $0x0, 0x18e54a(%rip)    # 0x1b38d4
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x18e53a(%rip)    # 0x1b38d4
jmp 0x256ed
cmpl $0x0, 0x19cec2(%rip)    # 0x1c2268
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x19ceb2(%rip)    # 0x1c2268
jmp 0x256ed
cmpl $0x0, 0x19ce86(%rip)    # 0x1c2248
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x19ce76(%rip)    # 0x1c2248
jmp 0x256ed
cmpl $0x0, 0x19ce6e(%rip)    # 0x1c224c
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x19ce5e(%rip)    # 0x1c224c
movl 0x19ce58(%rip), %eax    # 0x1c224c
movl %eax, 0x19ce56(%rip)    # 0x1c2250
movl 0x19ce4c(%rip), %eax    # 0x1c224c
movl %eax, 0x19ce4e(%rip)    # 0x1c2254
jmp 0x256ed
movl 0x19ce47(%rip), %eax    # 0x1c2258
addl $0x1, %eax
movl %eax, 0x19ce3e(%rip)    # 0x1c2258
movl 0x19ce38(%rip), %eax    # 0x1c2258
movl %eax, 0x6c(%rsp)
movq 0x19ce15(%rip), %rdi    # 0x1c2240
callq 0x269c0
movl %eax, %ecx
movl 0x6c(%rsp), %eax
cmpl %ecx, %eax
jl 0x2544f
movq 0x19cdff(%rip), %rdi    # 0x1c2240
callq 0x269c0
subl $0x1, %eax
movl %eax, 0x19ce09(%rip)    # 0x1c2258
jmp 0x256ed
movl 0x19cdfe(%rip), %eax    # 0x1c2258
addl $-0x1, %eax
movl %eax, 0x19cdf5(%rip)    # 0x1c2258
cmpl $0x0, 0x19cdee(%rip)    # 0x1c2258
jge 0x25476
movl $0x0, 0x19cde2(%rip)    # 0x1c2258
jmp 0x256ed
movl 0x19cddb(%rip), %eax    # 0x1c225c
addl $0x1, %eax
movl %eax, 0x19cdd2(%rip)    # 0x1c225c
movl 0x19cdcc(%rip), %eax    # 0x1c225c
movl %eax, 0x68(%rsp)
movq 0x19cda5(%rip), %rdi    # 0x1c2240
callq 0x269e0
movl %eax, %ecx
movl 0x68(%rsp), %eax
cmpl %ecx, %eax
jl 0x254bf
movq 0x19cd8f(%rip), %rdi    # 0x1c2240
callq 0x269e0
subl $0x1, %eax
movl %eax, 0x19cd9d(%rip)    # 0x1c225c
jmp 0x256ed
movl 0x19cd92(%rip), %eax    # 0x1c225c
addl $-0x1, %eax
movl %eax, 0x19cd89(%rip)    # 0x1c225c
cmpl $0x0, 0x19cd82(%rip)    # 0x1c225c
jge 0x254e6
movl $0x0, 0x19cd76(%rip)    # 0x1c225c
jmp 0x256ed
movl 0x19cd6f(%rip), %eax    # 0x1c2260
addl $0x1, %eax
movl %eax, 0x19cd66(%rip)    # 0x1c2260
movl 0x19cd60(%rip), %eax    # 0x1c2260
movl %eax, 0x64(%rsp)
movq 0x19cd35(%rip), %rdi    # 0x1c2240
callq 0x26a00
movl %eax, %ecx
movl 0x64(%rsp), %eax
cmpl %ecx, %eax
jl 0x2552f
movq 0x19cd1f(%rip), %rdi    # 0x1c2240
callq 0x26a00
subl $0x1, %eax
movl %eax, 0x19cd31(%rip)    # 0x1c2260
jmp 0x256ed
movl 0x19cd26(%rip), %eax    # 0x1c2260
addl $-0x1, %eax
movl %eax, 0x19cd1d(%rip)    # 0x1c2260
cmpl $0x0, 0x19cd16(%rip)    # 0x1c2260
jge 0x25556
movl $0x0, 0x19cd0a(%rip)    # 0x1c2260
jmp 0x256ed
movq 0x19ccce(%rip), %rdi    # 0x1c2230
callq 0x268e0
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x26da0
movq %rax, %rdi
callq 0x26db0
movsd %xmm0, 0x58(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x26da0
movq %rax, %rdi
callq 0x26dc0
movsd %xmm0, 0x18(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x26da0
movq %rax, %rdi
callq 0x26dd0
movsd %xmm0, 0x20(%rsp)
movq 0xc0(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x26de0
leaq 0xa8(%rsp), %rdi
callq 0x26e30
movsd %xmm0, 0x28(%rsp)
movq 0xc0(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x26de0
leaq 0x90(%rsp), %rdi
callq 0x26e40
movsd %xmm0, 0x30(%rsp)
movq 0xc0(%rsp), %rsi
leaq 0x78(%rsp), %rdi
callq 0x26de0
leaq 0x78(%rsp), %rdi
callq 0x26e50
movsd %xmm0, 0x38(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x26e60
movq %rax, %rdi
callq 0x26e30
movsd %xmm0, 0x40(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x26e60
movq %rax, %rdi
callq 0x26e40
movsd %xmm0, 0x48(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x26e60
movq %rax, %rdi
callq 0x26e50
movsd %xmm0, 0x50(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x26e80
movsd 0x18(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
movsd 0x28(%rsp), %xmm3
movsd 0x30(%rsp), %xmm4
movsd 0x38(%rsp), %xmm5
movsd 0x40(%rsp), %xmm6
movsd 0x48(%rsp), %xmm7
movsd 0x50(%rsp), %xmm9
movaps %xmm0, %xmm8
movsd 0x58(%rsp), %xmm0
leaq 0x139b57(%rip), %rdi    # 0x15f229
movsd %xmm9, (%rsp)
movsd %xmm8, 0x8(%rsp)
movb $0x8, %al
callq 0x20070
jmp 0x256ed
callq 0x23df0
movl 0xd0(%rsp), %eax
movl %eax, 0x19cbde(%rip)    # 0x1c22d8
movl 0x18e1e0(%rip), %eax    # 0x1b38e0
subl 0xcc(%rsp), %eax
movl %eax, 0x19cbcf(%rip)    # 0x1c22dc
callq 0xf6230
movl %eax, 0x19cbd4(%rip)    # 0x1c22ec
callq 0xee000
addq $0xd8, %rsp
retq
nopw %cs:(%rax,%rax)