// File: /workspace/github_cpp_makefile_star2_O2/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 0x109321(%rip), %ebx    # 0x12e9d8
subl %esi, %ebx
movl %edi, %r14d
subl 0x10e2e5(%rip), %r14d   # 0x1339a8
movl %ebx, %r9d
subl 0x10e2df(%rip), %r9d    # 0x1339ac
movl %r14d, %eax
imull %r14d, %eax
movl %r9d, %ecx
imull %r9d, %ecx
addl 0x10e2cf(%rip), %eax    # 0x1339b0
addl %ecx, %eax
movl %eax, 0x10e2c7(%rip)    # 0x1339b0
testb $0x1, 0x10e2c4(%rip)    # 0x1339b4
jne 0x25706
cmpl $0x0, 0x10e2bf(%rip)    # 0x1339b8
je 0x257d6
pushq $0x58
jmp 0x2588b
movq 0x10e1fb(%rip), %r15    # 0x133908
cmpl $0x0, 0x10e2a4(%rip)    # 0x1339b8
cvtsi2sd %r9d, %xmm1
je 0x25770
leaq 0x8(%r15), %rdi
leaq 0x20(%r15), %rsi
movsd 0x9f92d(%rip), %xmm0    # 0xc5058
mulsd %xmm1, %xmm0
movsd %xmm1, (%rsp)
callq 0x3c03e
movsd (%rsp), %xmm1
cmpl $0x0, 0x10e273(%rip)    # 0x1339b8
je 0x25770
cvtsi2sd %r14d, %xmm0
movq 0x10e1b5(%rip), %rdi    # 0x133908
mulsd 0x9f905(%rip), %xmm0    # 0xc5060
addq $0x8, %rdi
leaq 0xa25e2(%rip), %rsi     # 0xc7d48
callq 0x3c03e
jmp 0x258b0
cmpl $0x0, 0x10e245(%rip)    # 0x1339bc
je 0x257ea
movq 0x10e188(%rip), %r12    # 0x133908
cvtsi2sd %r14d, %xmm2
movsd 0x9f893(%rip), %xmm0    # 0xc5020
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 0x6c99a
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movsd (%rsp), %xmm0
callq 0x6c72a
addq $0x8, %r12
movq %r12, %rdi
movq %r15, %rsi
jmp 0x25879
cmpl $0x0, 0x10e1df(%rip)    # 0x1339bc
je 0x25880
pushq $0x50
jmp 0x2588b
cmpl $0x0, 0x10e1cf(%rip)    # 0x1339c0
je 0x258b0
cvtsi2sd %r14d, %xmm0
movq 0x10e105(%rip), %r14    # 0x133908
mulsd 0x9f815(%rip), %xmm0    # 0xc5020
leaq 0x20(%r15), %rsi
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movsd %xmm1, (%rsp)
callq 0x6c72a
movsd (%rsp), %xmm0
mulsd 0x9f7f2(%rip), %xmm0    # 0xc5020
movsd %xmm0, (%rsp)
addq $0x38, %r15
leaq 0x38(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x6c99a
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
movsd (%rsp), %xmm0
callq 0x6c72a
leaq 0x20(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x6c9ba
addq $0x8, %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x3c038
jmp 0x258b0
cmpl $0x0, 0x10e139(%rip)    # 0x1339c0
je 0x258b0
pushq $0x48
popq %rax
movq 0x10e075(%rip), %rdi    # 0x133908
movq (%rdi), %r10
leaq 0x10e03b(%rip), %rsi    # 0x1338d8
movsd 0x9f773(%rip), %xmm0    # 0xc5018
movl %ebp, %edx
movl %ebx, %ecx
movl %r14d, %r8d
callq *(%r10,%rax)
cmpl $0x0, 0x10e101(%rip)    # 0x1339b8
jne 0x258cb
cmpl $0x0, 0x10e0fc(%rip)    # 0x1339bc
jne 0x258cb
cmpl $0x0, 0x10e0f7(%rip)    # 0x1339c0
je 0x258d0
callq 0xb878c
movl %ebp, 0x10e0d2(%rip)    # 0x1339a8
movl %ebx, 0x10e0d0(%rip)    # 0x1339ac
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq