// File: /workspace/github_cpp_makefile_star2_O1/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 0x26dc9
leaq 0xb541a(%rip), %rcx     # 0xdc0a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %eax, %eax
cmpl $0x0, 0x11dcc4(%rip)    # 0x14495c
sete %al
movl %eax, 0x11dcbb(%rip)    # 0x14495c
jmp 0x26fc9
xorl %eax, %eax
cmpl $0x0, 0x11dc59(%rip)    # 0x144908
sete %al
movl %eax, 0x11dc50(%rip)    # 0x144908
jmp 0x26fc9
movq 0x11dc34(%rip), %rax    # 0x1448f8
testq %rax, %rax
je 0x26de9
movl 0xc(%rax), %ecx
testl %ecx, %ecx
jle 0x26de9
cmpb $0x76, %dil
je 0x26ef4
movzbl %dil, %edx
cmpl $0x56, %edx
jne 0x26eff
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
jmp 0x26ef9
xorl %eax, %eax
cmpl $0x0, 0x11dc5e(%rip)    # 0x144960
sete %al
movl %eax, 0x11dc55(%rip)    # 0x144960
jmp 0x26fc9
xorl %eax, %eax
cmpl $0x0, 0x11dbeb(%rip)    # 0x144904
sete %al
movl %eax, 0x11dbe2(%rip)    # 0x144904
jmp 0x26fc9
xorl %eax, %eax
cmpl $0x0, 0x11dc90(%rip)    # 0x1449c0
sete %al
movl %eax, 0x11dc87(%rip)    # 0x1449c0
jmp 0x26fc9
xorl %eax, %eax
cmpl $0x0, 0x11dba9(%rip)    # 0x1448f0
sete %al
movl %eax, 0x11dba0(%rip)    # 0x1448f0
jmp 0x26fc9
xorl %eax, %eax
cmpl $0x0, 0x11dbf6(%rip)    # 0x144954
sete %al
movl %eax, 0x11dbed(%rip)    # 0x144954
jmp 0x26fc9
xorl %eax, %eax
cmpl $0x0, 0x11dbe3(%rip)    # 0x144958
sete %al
movl %eax, 0x11dbda(%rip)    # 0x144958
jmp 0x26fc9
cmpl $0x0, 0x11db56(%rip)    # 0x1448e0
je 0x26e00
movl $0x0, 0x11db4a(%rip)    # 0x1448e0
jmp 0x26fc9
xorl %eax, %eax
cmpl $0x0, 0x118c0c(%rip)    # 0x13f9b0
sete %al
movl %eax, 0x118c03(%rip)    # 0x13f9b0
jmp 0x26fc9
xorl %eax, %eax
cmpl $0x0, 0x11db45(%rip)    # 0x144900
sete %al
movl %eax, 0x11db3c(%rip)    # 0x144900
jmp 0x26fc9
cmpl $0x20, %edi
je 0x26e0f
cmpl $0x1b, %edi
jne 0x26fc9
movl 0x11daf3(%rip), %edi    # 0x1448d0
callq 0xd5754
xorl %edi, %edi
callq 0x21b10
movq 0x11daf8(%rip), %rdi    # 0x1448e8
movq 0x11dae1(%rip), %rsi    # 0x1448d8
addq $0x78, %rsi
jmp 0x26f37
movl $0x1, 0x11dad6(%rip)    # 0x1448e0
jmp 0x26fc9
movq 0x11dad2(%rip), %r12    # 0x1448e8
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 0x779e8
movsd (%r15), %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x779e8
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0x18(%rsp)
leaq 0x58(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x779e8
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 0xb52e1(%rip), %rdi     # 0xdc1ab
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 0x26fc9
movl $0x1, %edx
addl %edx, 0x118abd(%rip)    # 0x13f9bc
cmpl $0x0, 0x118ab6(%rip)    # 0x13f9bc
jns 0x26f12
movl $0x0, 0x118aaa(%rip)    # 0x13f9bc
cmpl %ecx, 0x118aa4(%rip)    # 0x13f9bc
jl 0x26f22
decl %ecx
movl %ecx, 0x118a9a(%rip)    # 0x13f9bc
movq 0x11d9bf(%rip), %rdi    # 0x1448e8
movslq 0x118a8c(%rip), %rcx    # 0x13f9bc
movq (%rax), %rax
movq (%rax,%rcx,8), %rsi
callq 0x3e614
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x762b8
movl 0x118a65(%rip), %eax    # 0x13f9b4
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
cvtsi2sd %ecx, %xmm0
movq 0x11d985(%rip), %rsi    # 0x1448e8
movl 0x118a4f(%rip), %eax    # 0x13f9b8
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
cvtsi2sd %ecx, %xmm1
leaq 0x70(%rsp), %r15
movq %r15, %rdi
callq 0x3f3f2
movq 0x11d94e(%rip), %rdi    # 0x1448d8
leaq 0x119157(%rip), %rax    # 0x1400e8
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 0x29142
testl %eax, %eax
je 0x26fc9
leaq 0x11d8f9(%rip), %rdi    # 0x1448b8
leaq 0x40(%rsp), %rsi
callq 0x76628
movl %ebp, 0x11d9b9(%rip)    # 0x144988
movl 0x1189e3(%rip), %eax    # 0x13f9b8
subl %ebx, %eax
movl %eax, 0x11d9af(%rip)    # 0x14498c
callq 0xd435c
movl %eax, 0x11d9ac(%rip)    # 0x144994
callq 0xcf414
addq $0xa0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq