// File: tomfunkhouser[P]gaps/apps/prpview/prpview.cpp
// Function: GLUTMouse(int, int, int, int)
void GLUTMouse(int button, int state, int x, int y)
{
  // Invert y coordinate
  y = GLUTwindow_height - y;
  
  // Process mouse button event
  // Process mouse button event
  if ((button == GLUT_LEFT) && (state == GLUT_UP)) {
    // Check for double click  
    static RNBoolean double_click = FALSE;
    static RNTime last_mouse_down_time;
    double_click = (!double_click) && (last_mouse_down_time.Elapsed() < 0.4);
    last_mouse_down_time.Read();

    // Set world origin
    if (double_click) {
      R3Ray ray = viewer->WorldRay(x, y);
      R3MeshIntersection intersection;
      if (mesh->Intersection(ray, &intersection)) {
        world_origin = intersection.point;
      }
    }
  }

  // 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:
subq $0xa8, %rsp
movl %edi, 0xa4(%rsp)
movl %esi, 0xa0(%rsp)
movl %edx, 0x9c(%rsp)
movl %ecx, 0x98(%rsp)
movl 0x1d60c7(%rip), %eax    # 0x1feac0
subl 0x98(%rsp), %eax
movl %eax, 0x98(%rsp)
cmpl $0x0, 0xa4(%rsp)
jne 0x28b3c
cmpl $0x1, 0xa0(%rsp)
jne 0x28b3c
cmpb $0x0, 0x1dc2d6(%rip)    # 0x204d00
jne 0x28a57
leaq 0x1dc2cd(%rip), %rdi    # 0x204d00
callq 0x232f0
cmpl $0x0, %eax
je 0x28a57
leaq 0x1dc2ac(%rip), %rdi    # 0x204cf0
callq 0xf6cb0
jmp 0x28a4b
leaq 0x1dc2ae(%rip), %rdi    # 0x204d00
callq 0x22660
xorl %eax, %eax
cmpl $0x0, 0x1dc28c(%rip)    # 0x204cec
movb %al, 0x13(%rsp)
jne 0x28a88
leaq 0x1dc283(%rip), %rdi    # 0x204cf0
callq 0xf6d70
movaps %xmm0, %xmm1
movsd 0x16d60b(%rip), %xmm0   # 0x196088
ucomisd %xmm1, %xmm0
seta %al
movb %al, 0x13(%rsp)
movb 0x13(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x1dc255(%rip)    # 0x204cec
leaq 0x1dc252(%rip), %rdi    # 0x204cf0
callq 0x2ae50
cmpl $0x0, 0x1dc242(%rip)    # 0x204cec
je 0x28b3a
movq 0x1dc1b9(%rip), %rsi    # 0x204c70
cvtsi2sdl 0x9c(%rsp), %xmm0
cvtsi2sdl 0x98(%rsp), %xmm1
leaq 0x58(%rsp), %rdi
callq 0x2cf70
leaq 0x18(%rsp), %rdi
callq 0x2ae70
movq 0x1dc19c(%rip), %rdi    # 0x204c80
movq (%rdi), %rax
leaq 0x58(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq *0x170(%rax)
cmpl $0x0, %eax
je 0x28b38
leaq 0x18(%rsp), %rsi
addq $0x20, %rsi
leaq 0x1dc14c(%rip), %rdi    # 0x204c58
callq 0xd5030
jmp 0x28b38
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0x1dc1d2(%rip), %rdi    # 0x204d00
callq 0x22640
jmp 0x28bc6
jmp 0x28b3a
jmp 0x28b3c
cmpl $0x0, 0xa4(%rsp)
jne 0x28b4e
xorl %eax, %eax
movl %eax, 0xc(%rsp)
jmp 0x28b69
movl 0xa4(%rsp), %edx
movl $0x2, %eax
movl $0x1, %ecx
cmpl $0x1, %edx
cmovel %ecx, %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0xa0(%rsp), %ecx
xorl %edx, %edx
movl $0x1, %eax
cmpl $0x0, %ecx
cmovel %eax, %edx
movslq 0x14(%rsp), %rcx
leaq 0x1dc14f(%rip), %rax    # 0x204ce0
movl %edx, (%rax,%rcx,4)
callq 0x18a2e0
movl %eax, 0x1dc169(%rip)    # 0x204d08
movl 0x9c(%rsp), %eax
movl %eax, 0x1dc12c(%rip)    # 0x204cd8
movl 0x98(%rsp), %eax
movl %eax, 0x1dc123(%rip)    # 0x204cdc
callq 0x1820b0
addq $0xa8, %rsp
retq
movq 0x90(%rsp), %rdi
callq 0x23270
nopw %cs:(%rax,%rax)