// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/apps/confview/confview.cpp
// Function: GLUTMouse(int, int, int, int)
void GLUTMouse(int button, int state, int x, int y)
{
  // Invert y coordinate
  y = GLUTwindow_height - y;

  // Mouse is going down
  if (state == GLUT_DOWN) {
    // Reset mouse drag
    GLUTmouse_drag = 0;

    // Process thumbwheel
    if (button == 3) viewer.ScaleWorld(center, 0.9);
    else if (button == 4) viewer.ScaleWorld(center, 1.1);
  }
  else if (button == 0) {
    // Check for double click  
    static RNBoolean double_click = FALSE;
    static RNTime last_mouse_up_time;
    double_click = (!double_click) && (last_mouse_up_time.Elapsed() < 0.4);
    last_mouse_up_time.Read();

    // Check for click (rather than drag)
    if (GLUTmouse_drag < 100) {
      // Reset selected indices
      selected_surface_index = -1;
      selected_image_index = -1;

      // Select image or surface
      selected_position = R3unknown_point;
      RGBDImage *selected_image = NULL;
      RGBDSurface *selected_surface = NULL;
      if (Pick(x, y, &selected_surface, &selected_image, &selected_position)) {
        // Remember selected indices
        if (!selected_image) selected_image = configuration.FindImage(selected_position);
        if (selected_surface) selected_surface_index = selected_surface->ConfigurationIndex();
        if (selected_image) selected_image_index = selected_image->ConfigurationIndex();
        
        // Print message
        if (selected_surface) {
          printf("Selected surface %d at %g %g %g\n", selected_surface->ConfigurationIndex(),
            selected_position.X(), selected_position.Y(), selected_position.Z());
        }
        if (selected_image) {
          printf("Selected image %d %s and %g %g %g\n", selected_image->ConfigurationIndex(), selected_image->Name(),
            selected_position.X(), selected_position.Y(), selected_position.Z());
        }
        
        // Set viewing center of rotation and scale if double-click
        // if (double_click) center = selected_position;
        center = selected_position;
      }
    }
    else {
      // Process rubber box 
      if (rubber_box_active) {
        DrawRubberBox();
        ProcessRubberBox();
        rubber_box_corners[0] = R2zero_point;
        rubber_box_corners[1] = R2zero_point;
        rubber_box_active = FALSE;
      }
    }
  }

  // Remember button state 
  int b = (button == GLUT_LEFT_BUTTON) ? 0 : ((button == GLUT_MIDDLE_BUTTON) ? 1 : 2);
  GLUTbutton[b] = (state == GLUT_DOWN) ? 1 : 0;

  // Remember modifiers 
  GLUTmodifiers = glutGetModifiers();

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

  // Redraw
  glutPostRedisplay();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movl %edx, 0xc(%rsp)
movl %esi, %r14d
movl %edi, %r15d
movl 0x13e4c4(%rip), %ebp    # 0x1669e0
subl %ecx, %ebp
testl %esi, %esi
je 0x286aa
testl %r15d, %r15d
jne 0x287cd
movb 0x1435a3(%rip), %al     # 0x16bad8
testb %al, %al
je 0x28c29
xorl %eax, %eax
cmpl $0x0, 0x14357e(%rip)    # 0x16bac4
jne 0x28565
leaq 0x143579(%rip), %rdi    # 0x16bac8
callq 0xa66b2
movsd 0xd1ae4(%rip), %xmm1    # 0xfa040
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
movl %eax, 0x143559(%rip)    # 0x16bac4
leaq 0x143556(%rip), %rdi    # 0x16bac8
xorl %esi, %esi
callq 0x23ff0
cmpl $0x63, 0x14352c(%rip)   # 0x16baac
jg 0x286de
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x13e453(%rip)    # 0x1669e4
movl %eax, 0x13e451(%rip)    # 0x1669e8
leaq 0x1433aa(%rip), %r15    # 0x16b948
leaq 0x146a4b(%rip), %rsi    # 0x16eff0
movq %r15, %rdi
callq 0x87c7e
xorl %eax, %eax
leaq 0xe0(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x98(%rsp), %rdx
movq %rax, (%rdx)
movl 0xc(%rsp), %edi
movl %ebp, %esi
movq %r15, %r8
callq 0x28cda
testl %eax, %eax
je 0x287ae
movq 0xe0(%rsp), %rax
testq %rax, %rax
jne 0x28603
leaq 0x1432c1(%rip), %rdi    # 0x16b8b0
leaq 0x143352(%rip), %rsi    # 0x16b948
callq 0x2f2dc
movq %rax, 0xe0(%rsp)
movq 0x98(%rsp), %rcx
testq %rcx, %rcx
je 0x28619
movl 0x10(%rcx), %edx
movl %edx, 0x13e3cb(%rip)    # 0x1669e4
testq %rax, %rax
je 0x28627
movl 0x10(%rax), %edx
movl %edx, 0x13e3c1(%rip)    # 0x1669e8
testq %rcx, %rcx
je 0x2865d
movl 0x10(%rcx), %esi
movsd 0x143311(%rip), %xmm0   # 0x16b948
movsd 0x143311(%rip), %xmm1   # 0x16b950
movsd 0x143311(%rip), %xmm2   # 0x16b958
leaq 0xd1bad(%rip), %rdi     # 0xfa1fb
movb $0x3, %al
callq 0x23080
movq 0xe0(%rsp), %rax
testq %rax, %rax
je 0x28692
movl 0x10(%rax), %esi
movq 0x1d0(%rax), %rdx
movsd 0x1432d4(%rip), %xmm0   # 0x16b948
movsd 0x1432d4(%rip), %xmm1   # 0x16b950
movsd 0x1432d4(%rip), %xmm2   # 0x16b958
leaq 0xd1b91(%rip), %rdi     # 0xfa21c
movb $0x3, %al
callq 0x23080
leaq 0x1432ff(%rip), %rdi    # 0x16b998
leaq 0x1432a8(%rip), %rsi    # 0x16b948
callq 0x87c7e
jmp 0x287ae
movl $0x0, 0x1433f8(%rip)    # 0x16baac
testl %r15d, %r15d
je 0x2881d
cmpl $0x3, %r15d
je 0x287b2
cmpl $0x4, %r15d
jne 0x287cd
movsd 0xd197f(%rip), %xmm0    # 0xfa058
jmp 0x287ba
cmpb $0x1, 0x1433cf(%rip)    # 0x16bab4
jne 0x287ae
callq 0x283a3
leaq 0x146da1(%rip), %rsi    # 0x16f498
leaq 0x70(%rsp), %r15
movq %r15, %rdi
callq 0x9e200
leaq 0x143255(%rip), %rsi    # 0x16b960
movq %r15, %rdi
callq 0x9e90e
leaq 0x143256(%rip), %rsi    # 0x16b970
leaq 0x70(%rsp), %rdi
callq 0x9e90e
movsd 0x88(%rsp), %xmm1
subsd 0x78(%rsp), %xmm1
movsd 0xd190d(%rip), %xmm0    # 0xfa048
ucomisd %xmm1, %xmm0
ja 0x2875d
movsd 0x90(%rsp), %xmm1
subsd 0x80(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x28822
leaq 0xd207e(%rip), %rdi     # 0xfa7e2
callq 0x23ee0
movq 0x13d7b0(%rip), %rax    # 0x165f20
movq (%rax), %rdi
callq 0x23ac0
leaq 0x70(%rsp), %rdi
callq 0x9eb9c
leaq 0x1431d7(%rip), %rdi    # 0x16b960
leaq 0x1470b0(%rip), %r15    # 0x16f840
movq %r15, %rsi
callq 0xa116e
leaq 0x1431d1(%rip), %rdi    # 0x16b970
movq %r15, %rsi
callq 0xa116e
movb $0x0, 0x143306(%rip)    # 0x16bab4
xorl %eax, %eax
jmp 0x287d9
movsd 0xd1896(%rip), %xmm0    # 0xfa050
leaq 0x1431ef(%rip), %rdi    # 0x16b9b0
leaq 0x1431d0(%rip), %rsi    # 0x16b998
callq 0x38ec8
xorl %eax, %eax
cmpl $0x1, %r15d
setne %al
incq %rax
xorl %ecx, %ecx
testl %r14d, %r14d
sete %cl
leaq 0x1432d0(%rip), %rdx    # 0x16bab8
movl %ecx, (%rdx,%rax,4)
callq 0xf1aa9
movl %eax, 0x1432ba(%rip)    # 0x16bab0
movl 0xc(%rsp), %eax
movl %eax, 0x1432a4(%rip)    # 0x16baa4
movl %ebp, 0x1432a2(%rip)    # 0x16baa8
callq 0xecbf0
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r15d, %eax
jmp 0x287d9
movl $0x6000, %edi           # imm = 0x6000
callq 0x23040
movq %rax, (%rsp)
xorl %ebx, %ebx
movq (%rsp), %rax
leaq (%rax,%rbx), %rdi
callq 0x87914
addq $0x18, %rbx
cmpq $0x6000, %rbx           # imm = 0x6000
jne 0x28832
movq $0x0, 0x10(%rsp)
movl $0x2800, %ebx           # imm = 0x2800
leaq 0x98(%rsp), %r15
callq 0xa89c8
xorps %xmm1, %xmm1
cvtsi2sdl 0x143052(%rip), %xmm1 # 0x16b8c4
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movq 0x143037(%rip), %rcx    # 0x16b8b8
cltq
movq (%rcx,%rax,8), %r12
callq 0xa89c8
movsd %xmm0, 0x30(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x28(%r12), %xmm0
movsd %xmm0, 0x18(%rsp)
callq 0xa89c8
movsd %xmm0, 0x20(%rsp)
movl 0x2c(%r12), %r13d
leaq 0xe0(%rsp), %rdi
callq 0x87914
movsd 0x30(%rsp), %xmm0
mulsd 0x18(%rsp), %xmm0
xorps %xmm2, %xmm2
cvtsi2sd %r13d, %xmm2
movsd 0x20(%rsp), %xmm1
mulsd %xmm2, %xmm1
movq %r15, %rdi
callq 0xa1036
movq %r15, %rdi
leaq 0xe0(%rsp), %rsi
movq %r12, %rdx
callq 0x2b21f
testl %eax, %eax
je 0x28957
movq %r15, %rdi
leaq 0x1430aa(%rip), %rsi    # 0x16b9b0
leaq 0xe0(%rsp), %rdx
callq 0x39cd8
leaq 0x70(%rsp), %rdi
movq %r15, %rsi
callq 0x8fd78
testl %eax, %eax
je 0x28957
movslq 0x10(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq (%rsp), %rcx
leaq (%rcx,%rax,8), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x87c7e
movq 0x10(%rsp), %rcx
leal 0x1(%rcx), %eax
cmpl $0x3fe, %ecx            # imm = 0x3FE
jg 0x28984
movq %rax, 0x10(%rsp)
decl %ebx
jne 0x28862
movq 0x10(%rsp), %r15
cmpl $0x2, %r15d
jg 0x28987
leaq 0xd1e2f(%rip), %rdi     # 0xfa7a0
callq 0x23ee0
movq (%rsp), %rdi
callq 0x23c50
jmp 0x28769
movl %eax, %r15d
leaq 0x128(%rsp), %rdi
movl %r15d, %esi
movq (%rsp), %rbx
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x62e7d
leaq 0xe0(%rsp), %rdi
leaq 0x128(%rsp), %rsi
movq %r15, %r12
movl %r15d, %edx
movq %rbx, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x62f07
leaq 0x143035(%rip), %rsi    # 0x16ba00
leaq 0x98(%rsp), %rdi
callq 0x88fe4
leaq 0x110(%rsp), %r15
leaq 0x98(%rsp), %rsi
movq %r15, %rdi
callq 0x88636
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movq %r12, %rbx
jbe 0x28a73
leaq 0xf8(%rsp), %r13
leaq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x88fe4
leaq 0x58(%rsp), %rdi
movq %r15, %rsi
callq 0x88fe4
leaq 0x98(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
leaq 0x40(%rsp), %rdx
leaq 0x58(%rsp), %rcx
callq 0x82aec
leaq 0xe0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x88b36
leaq 0xb0(%rsp), %rsi
movq %r13, %rdi
callq 0x88b36
leaq 0xc8(%rsp), %rsi
movq %r15, %rdi
callq 0x88b36
leaq 0x98(%rsp), %rdi
movq %r15, %rsi
callq 0x883ba
leaq 0x98(%rsp), %rdi
callq 0x886c0
leaq 0x142f51(%rip), %rsi    # 0x16b9e8
leaq 0x40(%rsp), %rdi
callq 0x883ba
leaq 0x58(%rsp), %rdi
leaq 0x98(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x88cde
leaq 0x58(%rsp), %rdi
callq 0x886c0
leaq 0x140(%rsp), %rdi
leaq 0x58(%rsp), %rsi
leaq 0x98(%rsp), %rdx
callq 0x88cde
leaq 0x40(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x88b36
leaq 0x40(%rsp), %rdi
callq 0x886c0
movl %ebx, %ebx
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x140(%rsp), %r15
leaq 0x128(%rsp), %r12
movq (%rsp), %r13
movsd %xmm0, 0x18(%rsp)
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x87b72
movq %r15, %rdi
leaq 0x58(%rsp), %rsi
callq 0x88636
movapd %xmm0, 0x30(%rsp)
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x87b72
movq %r15, %rdi
leaq 0x40(%rsp), %rsi
callq 0x88636
movapd %xmm0, %xmm2
movapd 0xd155a(%rip), %xmm0    # 0xfa0c0
movapd 0x30(%rsp), %xmm1
andpd %xmm0, %xmm1
andpd %xmm0, %xmm2
maxsd 0x18(%rsp), %xmm1
maxsd 0x20(%rsp), %xmm2
addq $0x18, %r13
movsd %xmm2, 0x20(%rsp)
movsd %xmm1, 0x18(%rsp)
decq %rbx
jne 0x28b1e
movapd %xmm2, 0x20(%rsp)
movapd %xmm1, 0x30(%rsp)
movq (%rsp), %rdi
callq 0x23c50
movl $0x78, %edi
callq 0x238e0
movq %rax, %r15
leaq 0x128(%rsp), %rsi
leaq 0x58(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq %rax, %rdi
movapd 0x30(%rsp), %xmm0
movapd 0x20(%rsp), %xmm1
callq 0x78ab4
movl $0xa0, %edi
callq 0x238e0
movq %rax, %r12
movsd 0x142f66(%rip), %xmm0   # 0x16bb58
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x2f866
leaq 0x142caa(%rip), %rdi    # 0x16b8b0
movq %r12, %rsi
callq 0x2b6a4
movl 0x142cc0(%rip), %esi    # 0x16b8d4
decl %esi
leaq 0xd1717(%rip), %rdi     # 0xfa334
xorl %eax, %eax
callq 0x23080
jmp 0x28769
leaq 0x142ea8(%rip), %rdi    # 0x16bad8
callq 0x24160
testl %eax, %eax
je 0x2853d
leaq 0x142e84(%rip), %rdi    # 0x16bac8
callq 0xa6650
leaq 0x142e88(%rip), %rdi    # 0x16bad8
callq 0x235c0
jmp 0x2853d
movq %rax, %rbx
leaq 0x142e74(%rip), %rdi    # 0x16bad8
callq 0x235a0
jmp 0x28cd2
jmp 0x28cc5
movq %rax, %rbx
movl $0xa0, %esi
movq %r12, %rdi
jmp 0x28c85
movq %rax, %rbx
movl $0x78, %esi
movq %r15, %rdi
callq 0x23900
jmp 0x28cc8
jmp 0x28cc5
jmp 0x28cc5
jmp 0x28cc5
jmp 0x28cc5
jmp 0x28cc5
jmp 0x28cc5
jmp 0x28cc5
jmp 0x28cc5
jmp 0x28cc5
jmp 0x28cc5
jmp 0x28cc5
jmp 0x28cc5
jmp 0x28cc5
jmp 0x28cc5
jmp 0x28cc5
jmp 0x28cc5
movq %rax, %rbx
movl $0x6000, %esi           # imm = 0x6000
movq (%rsp), %rdi
callq 0x242d0
jmp 0x28cc8
jmp 0x28cc5
jmp 0x28cc5
jmp 0x28cc5
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x9eb9c
movq %rbx, %rdi
callq 0x240f0