// File: /workspace/github_cpp_makefile_star2_O3/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 0x26db4
leaq 0xb3435(%rip), %rcx     # 0xda0a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %eax, %eax
cmpl $0x0, 0x11bcdf(%rip)    # 0x14295c
sete %al
movl %eax, 0x11bcd6(%rip)    # 0x14295c
jmp 0x26fa5
xorl %eax, %eax
cmpl $0x0, 0x11bc74(%rip)    # 0x142908
sete %al
movl %eax, 0x11bc6b(%rip)    # 0x142908
jmp 0x26fa5
movq 0x11bc4f(%rip), %rax    # 0x1428f8
testq %rax, %rax
je 0x26dd4
movl 0xc(%rax), %ecx
testl %ecx, %ecx
jle 0x26dd4
movl 0x116cf9(%rip), %edx    # 0x13d9bc
cmpb $0x76, %dil
je 0x26edf
movzbl %dil, %esi
cmpl $0x56, %esi
jne 0x26eec
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
jmp 0x26ee4
xorl %eax, %eax
cmpl $0x0, 0x11bc73(%rip)    # 0x142960
sete %al
movl %eax, 0x11bc6a(%rip)    # 0x142960
jmp 0x26fa5
xorl %eax, %eax
cmpl $0x0, 0x11bc00(%rip)    # 0x142904
sete %al
movl %eax, 0x11bbf7(%rip)    # 0x142904
jmp 0x26fa5
xorl %eax, %eax
cmpl $0x0, 0x11bca5(%rip)    # 0x1429c0
sete %al
movl %eax, 0x11bc9c(%rip)    # 0x1429c0
jmp 0x26fa5
xorl %eax, %eax
cmpl $0x0, 0x11bbbe(%rip)    # 0x1428f0
sete %al
movl %eax, 0x11bbb5(%rip)    # 0x1428f0
jmp 0x26fa5
xorl %eax, %eax
cmpl $0x0, 0x11bc0b(%rip)    # 0x142954
sete %al
movl %eax, 0x11bc02(%rip)    # 0x142954
jmp 0x26fa5
xorl %eax, %eax
cmpl $0x0, 0x11bbf8(%rip)    # 0x142958
sete %al
movl %eax, 0x11bbef(%rip)    # 0x142958
jmp 0x26fa5
cmpl $0x0, 0x11bb6b(%rip)    # 0x1428e0
je 0x26deb
movl $0x0, 0x11bb5f(%rip)    # 0x1428e0
jmp 0x26fa5
xorl %eax, %eax
cmpl $0x0, 0x116c21(%rip)    # 0x13d9b0
sete %al
movl %eax, 0x116c18(%rip)    # 0x13d9b0
jmp 0x26fa5
xorl %eax, %eax
cmpl $0x0, 0x11bb5a(%rip)    # 0x142900
sete %al
movl %eax, 0x11bb51(%rip)    # 0x142900
jmp 0x26fa5
cmpl $0x20, %edi
je 0x26dfa
cmpl $0x1b, %edi
jne 0x26fa5
movl 0x11bb08(%rip), %edi    # 0x1428d0
callq 0xd3886
xorl %edi, %edi
callq 0x21b00
movq 0x11bb0d(%rip), %rdi    # 0x1428e8
movq 0x11baf6(%rip), %rsi    # 0x1428d8
addq $0x78, %rsi
jmp 0x26f13
movl $0x1, 0x11baeb(%rip)    # 0x1428e0
jmp 0x26fa5
movq 0x11bae7(%rip), %r12    # 0x1428e8
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 0x76a98
movsd (%r15), %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x76a98
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0x18(%rsp)
leaq 0x58(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x76a98
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 0xb32f6(%rip), %rdi     # 0xda1ab
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 0x26fa5
movl $0x1, %esi
addl %esi, %edx
movl %edx, 0x116ad0(%rip)    # 0x13d9bc
xorl %edi, %edi
testl %edx, %edx
cmovgl %edx, %edi
leal -0x1(%rcx), %esi
cmpl %ecx, %edx
cmovll %edi, %esi
jb 0x26f03
movl %esi, 0x116ab9(%rip)    # 0x13d9bc
movq 0x11b9de(%rip), %rdi    # 0x1428e8
movq (%rax), %rax
movl %esi, %ecx
movq (%rax,%rcx,8), %rsi
callq 0x3e154
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x753c8
movl 0x116a89(%rip), %eax    # 0x13d9b4
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
cvtsi2sd %ecx, %xmm0
movq 0x11b9a9(%rip), %rsi    # 0x1428e8
movl 0x116a73(%rip), %eax    # 0x13d9b8
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
cvtsi2sd %ecx, %xmm1
leaq 0x70(%rsp), %r15
movq %r15, %rdi
callq 0x3ef42
movq 0x11b972(%rip), %rdi    # 0x1428d8
leaq 0x11717b(%rip), %rax    # 0x13e0e8
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 0x29082
testl %eax, %eax
je 0x26fa5
leaq 0x11b91d(%rip), %rdi    # 0x1428b8
leaq 0x40(%rsp), %rsi
callq 0x75732
movl %ebp, 0x11b9dd(%rip)    # 0x142988
movl 0x116a07(%rip), %eax    # 0x13d9b8
subl %ebx, %eax
movl %eax, 0x11b9d3(%rip)    # 0x14298c
callq 0xd2449
movl %eax, 0x11b9d0(%rip)    # 0x142994
callq 0xcd590
addq $0xa0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq