// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/apps/scnview/scnview.cpp
// Function: GLUTMotion(int, int)
void GLUTMotion(int x, int y)
{
  // Invert y coordinate
  y = GLUTwindow_height - y;

  // Compute mouse movement
  int dx = x - GLUTmouse[0];
  int dy = y - GLUTmouse[1];
  
  // Update mouse drag
  GLUTmouse_drag += dx*dx + dy*dy;

  if (GLUTmodifiers & GLUT_ACTIVE_SHIFT) {
    // Camera in hand navigation
    const R3Camera& camera = viewer->Camera();
    if (GLUTbutton[0]) viewer->RotateCamera(camera.Right(), -0.001*dy);
    if (GLUTbutton[0]) viewer->RotateCamera(R3posy_vector, 0.001*dx);
    else if (GLUTbutton[1]) viewer->TranslateCamera((0.01*dx + 0.01*dy)*camera.Towards());
    else if (GLUTbutton[2]) viewer->TranslateCamera((0.01*dx)*camera.Right() + (0.01*dy)*camera.Down());
    if (GLUTbutton[0] || GLUTbutton[1] || GLUTbutton[2]) glutPostRedisplay();
  }
  else {
    // World in hand navigation
    if (GLUTbutton[0]) viewer->RotateWorld(1.0, center, x, y, dx, dy);
    else if (GLUTbutton[1]) viewer->ScaleWorld(1.0, center, x, y, dx, dy);
    else if (GLUTbutton[2]) viewer->TranslateWorld(1.0, center, x, y, dx, dy);
    if (GLUTbutton[0] || GLUTbutton[1] || GLUTbutton[2]) glutPostRedisplay();
  }

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edi, %ebp
movl 0x119563(%rip), %ebx    # 0x13f9b8
subl %esi, %ebx
movl %edi, %r15d
subl 0x11e527(%rip), %r15d   # 0x144988
movl %ebx, %r14d
subl 0x11e521(%rip), %r14d   # 0x14498c
movl %r15d, %eax
imull %r15d, %eax
movl %r14d, %ecx
imull %r14d, %ecx
addl 0x11e511(%rip), %eax    # 0x144990
addl %ecx, %eax
movl %eax, 0x11e509(%rip)    # 0x144990
testb $0x1, 0x11e506(%rip)    # 0x144994
jne 0x264ea
movl $0x58, %eax
cmpl $0x0, 0x11e4fc(%rip)    # 0x144998
jne 0x264be
movl $0x50, %eax
cmpl $0x0, 0x11e4f2(%rip)    # 0x14499c
jne 0x264be
movl $0x48, %eax
cmpl $0x0, 0x11e4e8(%rip)    # 0x1449a0
je 0x2664f
movq 0x11e423(%rip), %rdi    # 0x1448e8
movq (%rdi), %r10
leaq 0x11e3e9(%rip), %rsi    # 0x1448b8
movsd 0xb5b41(%rip), %xmm0    # 0xdc018
movl %ebp, %edx
movl %ebx, %ecx
movl %r15d, %r8d
movl %r14d, %r9d
callq *(%r10,%rax)
jmp 0x2664f
movq 0x11e3f7(%rip), %r12    # 0x1448e8
cmpl $0x0, 0x11e4a0(%rip)    # 0x144998
je 0x26516
leaq 0x8(%r12), %rdi
leaq 0x20(%r12), %rsi
cvtsi2sd %r14d, %xmm0
mulsd 0xb5b47(%rip), %xmm0    # 0xdc058
callq 0x408a6
cmpl $0x0, 0x11e47b(%rip)    # 0x144998
je 0x2654b
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movq 0x11e3ba(%rip), %rdi    # 0x1448e8
mulsd 0xb5b2a(%rip), %xmm0    # 0xdc060
addq $0x8, %rdi
leaq 0xb8877(%rip), %rsi     # 0xdedb8
callq 0x408a6
jmp 0x2664f
cmpl $0x0, 0x11e44a(%rip)    # 0x14499c
je 0x265b9
cvtsi2sd %r15d, %xmm2
movq 0x11e388(%rip), %r15    # 0x1448e8
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd 0xb5ab8(%rip), %xmm1    # 0xdc028
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, (%rsp)
addq $0x50, %r12
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x779e8
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movsd (%rsp), %xmm0
callq 0x77722
addq $0x8, %r15
movq %r15, %rdi
movq %r12, %rsi
jmp 0x2664a
cmpl $0x0, 0x11e3e0(%rip)    # 0x1449a0
je 0x2664f
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movq 0x11e313(%rip), %r15    # 0x1448e8
mulsd 0xb5a4b(%rip), %xmm0    # 0xdc028
leaq 0x20(%r12), %rsi
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x77722
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd 0xb5a29(%rip), %xmm0    # 0xdc028
movsd %xmm0, (%rsp)
addq $0x38, %r12
leaq 0x38(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x779e8
leaq 0x50(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movsd (%rsp), %xmm0
callq 0x77722
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x77a08
addq $0x8, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x408a0
cmpl $0x0, 0x11e342(%rip)    # 0x144998
jne 0x2666a
cmpl $0x0, 0x11e33d(%rip)    # 0x14499c
jne 0x2666a
cmpl $0x0, 0x11e338(%rip)    # 0x1449a0
je 0x2666f
callq 0xcf414
movl %ebp, 0x11e313(%rip)    # 0x144988
movl %ebx, 0x11e311(%rip)    # 0x14498c
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq