// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/apps/scnview/scnview.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':
    if (show_backfacing == 0) show_backfacing = 1;
    else show_backfacing = 0;
    break;

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

  case 'E':
  case 'e':
    show_edges = !show_edges;
    break;

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

  case 'H':
  case 'h':
    show_bboxes = !show_bboxes;
    break;

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

  case 'M':
  case 'm':
    show_materials = !show_materials;
    break;

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

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

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

  case 'V':
  case 'v':
    // Set camera
    if (cameras && (cameras->NEntries() > 0)) {
      if (key == 'v') selected_camera_index++;
      else if (key == 'V') selected_camera_index--;
      if (selected_camera_index < 0) selected_camera_index = 0;
      if (selected_camera_index >= cameras->NEntries()) selected_camera_index = cameras->NEntries()-1;
      viewer->SetCamera(*(cameras->Kth(selected_camera_index)));
    }
    else {
      viewer->SetCamera(scene->Camera());
    }

    // Set center
    if (1) {
      R3Point hit_point;
      R3Ray ray = viewer->WorldRay(GLUTwindow_width/2, GLUTwindow_height/2);
      if (scene->Intersects(ray, NULL, NULL, NULL, &hit_point)) center = hit_point;
    }
    break;

  case ' ': {
    // Print camera
    const R3Camera& camera = viewer->Camera();
    printf("%g %g %g  %g %g %g  %g %g %g  %g %g  1\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.XFOV(), 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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xa0, %rsp
movl %edx, %ebx
movl %esi, %ebp
leal -0x41(%rdi), %eax
cmpl $0x35, %eax
ja 0x25ff4
leaq 0x9f1ef(%rip), %rcx     # 0xc50a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %eax, %eax
cmpl $0x0, 0x10dab9(%rip)    # 0x13397c
sete %al
movl %eax, 0x10dab0(%rip)    # 0x13397c
jmp 0x261cd
xorl %eax, %eax
cmpl $0x0, 0x10da4e(%rip)    # 0x133928
sete %al
movl %eax, 0x10da45(%rip)    # 0x133928
jmp 0x261cd
movq 0x10da29(%rip), %rax    # 0x133918
testq %rax, %rax
je 0x26007
movl 0xc(%rax), %ecx
testl %ecx, %ecx
jle 0x26007
movl 0x108ad3(%rip), %edx    # 0x12e9dc
cmpb $0x76, %dil
je 0x26112
movzbl %dil, %esi
cmpl $0x56, %esi
jne 0x2611d
pushq $-0x1
jmp 0x26114
xorl %eax, %eax
cmpl $0x0, 0x10da50(%rip)    # 0x133980
sete %al
movl %eax, 0x10da47(%rip)    # 0x133980
jmp 0x261cd
xorl %eax, %eax
cmpl $0x0, 0x10d9dd(%rip)    # 0x133924
sete %al
movl %eax, 0x10d9d4(%rip)    # 0x133924
jmp 0x261cd
xorl %eax, %eax
cmpl $0x0, 0x10da82(%rip)    # 0x1339e0
sete %al
movl %eax, 0x10da79(%rip)    # 0x1339e0
jmp 0x261cd
xorl %eax, %eax
cmpl $0x0, 0x10d99b(%rip)    # 0x133910
sete %al
movl %eax, 0x10d992(%rip)    # 0x133910
jmp 0x261cd
xorl %eax, %eax
cmpl $0x0, 0x10d9e8(%rip)    # 0x133974
sete %al
movl %eax, 0x10d9df(%rip)    # 0x133974
jmp 0x261cd
xorl %eax, %eax
cmpl $0x0, 0x10d9d5(%rip)    # 0x133978
sete %al
movl %eax, 0x10d9cc(%rip)    # 0x133978
jmp 0x261cd
cmpl $0x0, 0x10d948(%rip)    # 0x133900
je 0x2601e
andl $0x0, 0x10d93f(%rip)    # 0x133900
jmp 0x261cd
xorl %eax, %eax
cmpl $0x0, 0x108a01(%rip)    # 0x12e9d0
sete %al
movl %eax, 0x1089f8(%rip)    # 0x12e9d0
jmp 0x261cd
xorl %eax, %eax
cmpl $0x0, 0x10d93a(%rip)    # 0x133920
sete %al
movl %eax, 0x10d931(%rip)    # 0x133920
jmp 0x261cd
cmpl $0x20, %edi
je 0x2602d
cmpl $0x1b, %edi
jne 0x261cd
callq 0x247dc
movq 0x10d8fa(%rip), %rdi    # 0x133908
movq 0x10d8e3(%rip), %rsi    # 0x1338f8
addq $0x78, %rsi
jmp 0x26144
movl $0x1, 0x10d8d8(%rip)    # 0x133900
jmp 0x261cd
movq 0x10d8d4(%rip), %r12    # 0x133908
movsd 0x8(%r12), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x10(%r12), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x18(%r12), %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0x50(%r12), %r14
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x6c99a
movsd (%r15), %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x6c99a
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0x18(%rsp)
leaq 0x58(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x6c99a
movsd 0x10(%r15), %xmm5
movsd 0x38(%r12), %xmm6
movsd 0x40(%r12), %xmm7
movsd 0x48(%r12), %xmm0
movsd 0x68(%r12), %xmm1
movsd 0x70(%r12), %xmm2
movsd %xmm2, 0x10(%rsp)
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, (%rsp)
leaq 0x9f0c3(%rip), %rdi     # 0xc51ab
movsd 0x38(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x28(%rsp), %xmm2
movsd 0x20(%rsp), %xmm3
movsd 0x18(%rsp), %xmm4
movb $0x8, %al
callq 0x21080
jmp 0x261cd
pushq $0x1
popq %rsi
addl %esi, %edx
movl %edx, 0x1088bf(%rip)    # 0x12e9dc
xorl %edi, %edi
testl %edx, %edx
cmovgl %edx, %edi
leal -0x1(%rcx), %esi
cmpl %ecx, %edx
cmovll %edi, %esi
jb 0x26134
movl %esi, 0x1088a8(%rip)    # 0x12e9dc
movq 0x10d7cd(%rip), %rdi    # 0x133908
movq (%rax), %rax
movl %esi, %ecx
movq (%rax,%rcx,8), %rsi
callq 0x39f3a
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x6b872
movq 0x10d7ab(%rip), %rsi    # 0x133908
movl 0x108871(%rip), %eax    # 0x12e9d4
pushq $0x2
popq %rcx
cltd
idivl %ecx
cvtsi2sd %eax, %xmm0
movl 0x108865(%rip), %eax    # 0x12e9d8
cltd
idivl %ecx
cvtsi2sd %eax, %xmm1
leaq 0x70(%rsp), %r15
movq %r15, %rdi
callq 0x3abf0
movq 0x10d76a(%rip), %rdi    # 0x1338f8
leaq 0x108f73(%rip), %rax    # 0x12f108
movsd (%rax), %xmm1
xorpd %xmm0, %xmm0
movupd %xmm0, (%rsp)
xorpd %xmm0, %xmm0
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r14, %r9
callq 0x27fd2
testl %eax, %eax
je 0x261cd
leaq 0x10d715(%rip), %rdi    # 0x1338d8
leaq 0x40(%rsp), %rsi
callq 0x6bb5e
movl %ebp, 0x10d7d5(%rip)    # 0x1339a8
movl 0x1087ff(%rip), %eax    # 0x12e9d8
subl %ebx, %eax
movl %eax, 0x10d7cb(%rip)    # 0x1339ac
callq 0xbd22a
movl %eax, 0x10d7c8(%rip)    # 0x1339b4
callq 0xb878c
addq $0xa0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq