// File: /workspace/github_cpp_makefile_star2_O2/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, %r13d
movl %esi, %r14d
movl %edi, %r15d
movl 0x12e18d(%rip), %ebp    # 0x155a00
subl %ecx, %ebp
testl %esi, %esi
je 0x27a00
testl %r15d, %r15d
jne 0x27b20
movb 0x13326c(%rip), %al     # 0x15aaf8
testb %al, %al
movl %r13d, 0x14(%rsp)
je 0x27f5c
xorl %eax, %eax
cmpl $0x0, 0x133242(%rip)    # 0x15aae4
jne 0x278c1
leaq 0x13323d(%rip), %rdi    # 0x15aae8
callq 0x98b78
movsd 0xba788(%rip), %xmm1    # 0xe2040
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
movl %eax, 0x13321d(%rip)    # 0x15aae4
leaq 0x13321a(%rip), %rdi    # 0x15aae8
callq 0x29e36
cmpl $0x63, 0x1331f2(%rip)   # 0x15aacc
jg 0x27a31
orl $-0x1, 0x12e11d(%rip)   # 0x155a04
orl $-0x1, 0x12e11a(%rip)   # 0x155a08
leaq 0x133073(%rip), %r15    # 0x15a968
leaq 0x136714(%rip), %rsi    # 0x15e010
movq %r15, %rdi
callq 0x7cb9e
leaq 0x98(%rsp), %rcx
andq $0x0, (%rcx)
leaq 0xf8(%rsp), %rdx
andq $0x0, (%rdx)
movl %r13d, %edi
movl %ebp, %esi
movq %r15, %r8
callq 0x28011
testl %eax, %eax
je 0x27b01
movq 0x98(%rsp), %rax
testq %rax, %rax
jne 0x27959
leaq 0x132f8b(%rip), %rdi    # 0x15a8d0
leaq 0x13301c(%rip), %rsi    # 0x15a968
callq 0x2dd12
movq %rax, 0x98(%rsp)
movq 0xf8(%rsp), %rcx
testq %rcx, %rcx
je 0x2796f
movl 0x10(%rcx), %edx
movl %edx, 0x12e095(%rip)    # 0x155a04
testq %rax, %rax
je 0x2797d
movl 0x10(%rax), %edx
movl %edx, 0x12e08b(%rip)    # 0x155a08
testq %rcx, %rcx
je 0x279b3
movl 0x10(%rcx), %esi
movsd 0x132fdb(%rip), %xmm0   # 0x15a968
movsd 0x132fdb(%rip), %xmm1   # 0x15a970
movsd 0x132fdb(%rip), %xmm2   # 0x15a978
leaq 0xba857(%rip), %rdi     # 0xe21fb
movb $0x3, %al
callq 0x23080
movq 0x98(%rsp), %rax
testq %rax, %rax
je 0x279e8
movl 0x10(%rax), %esi
movq 0x1d0(%rax), %rdx
movsd 0x132f9e(%rip), %xmm0   # 0x15a968
movsd 0x132f9e(%rip), %xmm1   # 0x15a970
movsd 0x132f9e(%rip), %xmm2   # 0x15a978
leaq 0xba83b(%rip), %rdi     # 0xe221c
movb $0x3, %al
callq 0x23080
leaq 0x132fc9(%rip), %rdi    # 0x15a9b8
leaq 0x132f72(%rip), %rsi    # 0x15a968
callq 0x7cb9e
jmp 0x27b01
andl $0x0, 0x1330c5(%rip)    # 0x15aacc
testl %r15d, %r15d
je 0x27b6d
cmpl $0x3, %r15d
je 0x27b05
cmpl $0x4, %r15d
jne 0x27b20
movsd 0xba62c(%rip), %xmm0    # 0xe2058
jmp 0x27b0d
cmpb $0x1, 0x13309c(%rip)    # 0x15aad4
jne 0x27b01
callq 0x27700
leaq 0x136a6e(%rip), %rsi    # 0x15e4b8
leaq 0x70(%rsp), %r15
movq %r15, %rdi
callq 0x9118e
leaq 0x132f22(%rip), %rsi    # 0x15a980
movq %r15, %rdi
callq 0x917c0
leaq 0x132f23(%rip), %rsi    # 0x15a990
leaq 0x70(%rsp), %rdi
callq 0x917c0
movsd 0x88(%rsp), %xmm1
subsd 0x78(%rsp), %xmm1
movsd 0xba5ba(%rip), %xmm0    # 0xe2048
ucomisd %xmm1, %xmm0
ja 0x27ab0
movsd 0x90(%rsp), %xmm1
subsd 0x80(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x27b72
leaq 0xbad2b(%rip), %rdi     # 0xe27e2
callq 0x23f00
movq 0x12d47d(%rip), %rax    # 0x154f40
movq (%rax), %rdi
callq 0x23ac0
leaq 0x70(%rsp), %rdi
callq 0x91a26
leaq 0x132ea4(%rip), %rdi    # 0x15a980
leaq 0x136d7d(%rip), %r15    # 0x15e860
movq %r15, %rsi
callq 0x93df0
leaq 0x132e9e(%rip), %rdi    # 0x15a990
movq %r15, %rsi
callq 0x93df0
movb $0x0, 0x132fd3(%rip)    # 0x15aad4
xorl %eax, %eax
jmp 0x27b2c
movsd 0xba543(%rip), %xmm0    # 0xe2050
leaq 0x132ebc(%rip), %rdi    # 0x15a9d0
leaq 0x132e9d(%rip), %rsi    # 0x15a9b8
callq 0x36ed6
xorl %eax, %eax
cmpl $0x1, %r15d
setne %al
incq %rax
xorl %ecx, %ecx
testl %r14d, %r14d
sete %cl
leaq 0x132f9d(%rip), %rdx    # 0x15aad8
movl %ecx, (%rdx,%rax,4)
callq 0xda0ca
movl %eax, 0x132f87(%rip)    # 0x15aad0
movl %r13d, 0x132f74(%rip)   # 0x15aac4
movl %ebp, 0x132f72(%rip)    # 0x15aac8
callq 0xd562c
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r15d, %eax
jmp 0x27b2c
movl $0x6000, %edi           # imm = 0x6000
callq 0x23040
movq %rax, 0x8(%rsp)
xorl %ebx, %ebx
movq 0x8(%rsp), %rax
leaq (%rax,%rbx), %rdi
callq 0x7c8b2
addq $0x18, %rbx
cmpq $0x6000, %rbx           # imm = 0x6000
jne 0x27b83
movq $0x0, 0x18(%rsp)
movl $0x2800, %ebx           # imm = 0x2800
leaq 0xf8(%rsp), %r12
subl $0x1, %ebx
jb 0x27cb6
callq 0x9ab92
cvtsi2sdl 0x132d1a(%rip), %xmm1 # 0x15a8e4
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movq 0x132cff(%rip), %rcx    # 0x15a8d8
cltq
movq (%rcx,%rax,8), %r15
callq 0x9ab92
movsd %xmm0, 0x28(%rsp)
cvtsi2sdl 0x28(%r15), %xmm0
movsd %xmm0, 0x60(%rsp)
callq 0x9ab92
movsd %xmm0, 0x20(%rsp)
movl 0x2c(%r15), %r13d
leaq 0x98(%rsp), %rdi
callq 0x7c8b2
movsd 0x28(%rsp), %xmm0
mulsd 0x60(%rsp), %xmm0
cvtsi2sd %r13d, %xmm2
movsd 0x20(%rsp), %xmm1
mulsd %xmm2, %xmm1
movq %r12, %rdi
callq 0x93cb8
movq %r12, %rdi
leaq 0x98(%rsp), %rsi
movq %r15, %rdx
callq 0x2a4f3
testl %eax, %eax
movl 0x14(%rsp), %r13d
je 0x27bb4
movq %r12, %rdi
leaq 0x132d71(%rip), %rsi    # 0x15a9d0
leaq 0x98(%rsp), %rdx
callq 0x37b9e
leaq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0x83e38
testl %eax, %eax
je 0x27bb4
movslq 0x18(%rsp), %rax
imulq $0x18, %rax, %rdi
addq 0x8(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x7cb9e
movq 0x18(%rsp), %rcx
leal 0x1(%rcx), %eax
cmpl $0x3fe, %ecx            # imm = 0x3FE
jg 0x27cdc
movq %rax, 0x18(%rsp)
jmp 0x27bb4
movq 0x18(%rsp), %r15
cmpl $0x2, %r15d
jg 0x27cdf
leaq 0xbaad8(%rip), %rdi     # 0xe27a0
callq 0x23f00
movq 0x8(%rsp), %rdi
callq 0x23c50
jmp 0x27abc
movl %eax, %r15d
leaq 0xe0(%rsp), %rdi
movl %r15d, %esi
movq 0x8(%rsp), %rbx
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x5b4b4
leaq 0x98(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
movl %r15d, %edx
movq %rbx, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x5b53d
leaq 0x132cff(%rip), %rsi    # 0x15aa20
leaq 0xf8(%rsp), %rdi
callq 0x7d9da
leaq 0xc8(%rsp), %r12
leaq 0xf8(%rsp), %rsi
movq %r12, %rdi
callq 0x7d2ee
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x27da3
leaq 0xb0(%rsp), %rsi
leaq 0x30(%rsp), %rdi
callq 0x7d9da
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
callq 0x7d9da
leaq 0xf8(%rsp), %rdi
leaq 0x98(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x48(%rsp), %rcx
callq 0x78326
leaq 0x98(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x29f22
leaq 0xf8(%rsp), %rdi
movq %r12, %rsi
callq 0x7d084
leaq 0xf8(%rsp), %rdi
callq 0x7d376
leaq 0x132c41(%rip), %rsi    # 0x15aa08
leaq 0x30(%rsp), %rdi
callq 0x7d084
leaq 0x48(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x7d726
leaq 0x48(%rsp), %rdi
callq 0x7d376
leaq 0x140(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0xf8(%rsp), %rdx
callq 0x7d726
leaq 0x30(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x7d5e4
leaq 0x30(%rsp), %rdi
callq 0x7d376
movl %r15d, %eax
imulq $0x18, %rax, %rax
movq %rax, 0x18(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
xorl %ebx, %ebx
leaq 0x140(%rsp), %r12
leaq 0xe0(%rsp), %r13
movsd %xmm0, 0x20(%rsp)
cmpq %rbx, 0x18(%rsp)
je 0x27ed0
movq 0x8(%rsp), %rax
leaq (%rax,%rbx), %r15
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x7ca91
movq %r12, %rdi
leaq 0x48(%rsp), %rsi
callq 0x7d2ee
movapd %xmm0, 0x60(%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x7ca91
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
callq 0x7d2ee
movapd 0xba216(%rip), %xmm1    # 0xe20c0
movapd 0x60(%rsp), %xmm2
andpd %xmm1, %xmm2
andpd %xmm1, %xmm0
maxsd 0x28(%rsp), %xmm2
maxsd 0x20(%rsp), %xmm0
addq $0x18, %rbx
movsd %xmm2, 0x28(%rsp)
jmp 0x27e50
movq 0x8(%rsp), %rdi
callq 0x23c50
pushq $0x78
popq %rdi
callq 0x238f0
movq %rax, %r15
leaq 0xe0(%rsp), %rsi
leaq 0x48(%rsp), %rdx
leaq 0x30(%rsp), %rcx
movq %rax, %rdi
movsd 0x28(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
callq 0x6eeaa
movl 0x14(%rsp), %r13d
movl $0xa0, %edi
callq 0x238f0
movq %rax, %r12
movsd 0x132c53(%rip), %xmm0   # 0x15ab78
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x2e3aa
leaq 0x132997(%rip), %rdi    # 0x15a8d0
movq %r12, %rsi
callq 0x2a8c8
movl 0x1329ad(%rip), %esi    # 0x15a8f4
decl %esi
leaq 0xba3e4(%rip), %rdi     # 0xe2334
xorl %eax, %eax
callq 0x23080
jmp 0x27abc
leaq 0x132b95(%rip), %rdi    # 0x15aaf8
callq 0x24180
testl %eax, %eax
je 0x27899
leaq 0x132b71(%rip), %rdi    # 0x15aae8
callq 0x98b3e
leaq 0x132b75(%rip), %rdi    # 0x15aaf8
callq 0x235c0
movl 0x14(%rsp), %r13d
jmp 0x27899
movq %rax, %rbx
leaq 0x132b5c(%rip), %rdi    # 0x15aaf8
callq 0x235a0
jmp 0x28009
jmp 0x27ffc
movq %rax, %rbx
movl $0xa0, %esi
movq %r12, %rdi
jmp 0x27fbb
movq %rax, %rbx
pushq $0x78
popq %rsi
movq %r15, %rdi
callq 0x23910
jmp 0x27fff
jmp 0x27ffc
jmp 0x27ffc
jmp 0x27ffc
jmp 0x27ffc
jmp 0x27ffc
jmp 0x27ffc
jmp 0x27ffc
jmp 0x27ffc
jmp 0x27ffc
jmp 0x27ffc
jmp 0x27ffc
jmp 0x27ffc
jmp 0x27ffc
jmp 0x27ffc
jmp 0x27ffc
jmp 0x27ffc
movq %rax, %rbx
movl $0x6000, %esi           # imm = 0x6000
movq 0x8(%rsp), %rdi
callq 0x24300
jmp 0x27fff
jmp 0x27ffc
jmp 0x27ffc
jmp 0x27ffc
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x91a26
movq %rbx, %rdi
callq 0x24110