// File: /workspace/github_cpp_makefile_star2_O3/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 0x11756f(%rip), %ebx    # 0x13d9b8
subl %esi, %ebx
movl %edi, %r14d
subl 0x11c533(%rip), %r14d   # 0x142988
movl %ebx, %r9d
subl 0x11c52d(%rip), %r9d    # 0x14298c
movl %r14d, %eax
imull %r14d, %eax
movl %r9d, %ecx
imull %r9d, %ecx
addl 0x11c51d(%rip), %eax    # 0x142990
addl %ecx, %eax
movl %eax, 0x11c515(%rip)    # 0x142990
testb $0x1, 0x11c512(%rip)    # 0x142994
jne 0x264db
movl $0x58, %eax
cmpl $0x0, 0x11c508(%rip)    # 0x142998
jne 0x264b2
movl $0x50, %eax
cmpl $0x0, 0x11c4fe(%rip)    # 0x14299c
jne 0x264b2
movl $0x48, %eax
cmpl $0x0, 0x11c4f4(%rip)    # 0x1429a0
je 0x26645
movq 0x11c42f(%rip), %rdi    # 0x1428e8
movq (%rdi), %r10
leaq 0x11c3f5(%rip), %rsi    # 0x1428b8
movsd 0xb3b4d(%rip), %xmm0    # 0xda018
movl %ebp, %edx
movl %ebx, %ecx
movl %r14d, %r8d
callq *(%r10,%rax)
jmp 0x26645
movq 0x11c406(%rip), %r15    # 0x1428e8
cmpl $0x0, 0x11c4af(%rip)    # 0x142998
cvtsi2sd %r9d, %xmm1
je 0x26548
leaq 0x8(%r15), %rdi
leaq 0x20(%r15), %rsi
movsd 0xb3b58(%rip), %xmm0    # 0xda058
mulsd %xmm1, %xmm0
movsd %xmm1, (%rsp)
callq 0x4042a
movsd (%rsp), %xmm1
cmpl $0x0, 0x11c47e(%rip)    # 0x142998
je 0x26548
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movq 0x11c3bd(%rip), %rdi    # 0x1428e8
mulsd 0xb3b2d(%rip), %xmm0    # 0xda060
addq $0x8, %rdi
leaq 0xb687a(%rip), %rsi     # 0xdcdb8
callq 0x4042a
jmp 0x26645
cmpl $0x0, 0x11c44d(%rip)    # 0x14299c
je 0x265ae
movq 0x11c390(%rip), %r12    # 0x1428e8
cvtsi2sd %r14d, %xmm2
movsd 0xb3ac3(%rip), %xmm0    # 0xda028
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, (%rsp)
addq $0x50, %r15
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x76a98
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movsd (%rsp), %xmm0
callq 0x767fa
addq $0x8, %r12
movq %r12, %rdi
movq %r15, %rsi
jmp 0x26640
cmpl $0x0, 0x11c3eb(%rip)    # 0x1429a0
je 0x26645
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movq 0x11c31e(%rip), %r14    # 0x1428e8
mulsd 0xb3a56(%rip), %xmm0    # 0xda028
leaq 0x20(%r15), %rsi
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movsd %xmm1, (%rsp)
callq 0x767fa
movsd (%rsp), %xmm0
mulsd 0xb3a33(%rip), %xmm0    # 0xda028
movsd %xmm0, (%rsp)
addq $0x38, %r15
leaq 0x38(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x76a98
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
movsd (%rsp), %xmm0
callq 0x767fa
leaq 0x20(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x76ab8
addq $0x8, %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x40424
cmpl $0x0, 0x11c34c(%rip)    # 0x142998
jne 0x26660
cmpl $0x0, 0x11c347(%rip)    # 0x14299c
jne 0x26660
cmpl $0x0, 0x11c342(%rip)    # 0x1429a0
je 0x26665
callq 0xcd590
movl %ebp, 0x11c31d(%rip)    # 0x142988
movl %ebx, 0x11c31b(%rip)    # 0x14298c
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq