// File: 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:
subq $0xd8, %rsp
movl %edi, 0xd4(%rsp)
movl %esi, 0xd0(%rsp)
movl 0x1cd51d(%rip), %eax    # 0x1f5ac8
subl 0xd0(%rsp), %eax
movl %eax, 0xd0(%rsp)
movl 0xd4(%rsp), %eax
subl 0x1d3702(%rip), %eax    # 0x1fbcc8
movl %eax, 0xcc(%rsp)
movl 0xd0(%rsp), %eax
subl 0x1d36f2(%rip), %eax    # 0x1fbccc
movl %eax, 0xc8(%rsp)
movl 0xcc(%rsp), %eax
imull 0xcc(%rsp), %eax
movl 0xc8(%rsp), %ecx
imull 0xc8(%rsp), %ecx
addl %ecx, %eax
addl 0x1d36c9(%rip), %eax    # 0x1fbcd0
movl %eax, 0x1d36c3(%rip)    # 0x1fbcd0
movl 0x1d36c1(%rip), %eax    # 0x1fbcd4
andl $0x1, %eax
cmpl $0x0, %eax
je 0x28821
movq 0x1d3602(%rip), %rdi    # 0x1fbc28
callq 0x2b4d0
movq %rax, 0xc0(%rsp)
cmpl $0x0, 0x1d369e(%rip)    # 0x1fbcd8
je 0x28677
movq 0x1d35e5(%rip), %rax    # 0x1fbc28
movq %rax, 0x28(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x2b720
movq 0x28(%rsp), %rdi
movq %rax, %rsi
cvtsi2sdl 0xc8(%rsp), %xmm1
movsd 0x1659ea(%rip), %xmm0   # 0x18e058
mulsd %xmm1, %xmm0
callq 0x2b6f0
cmpl $0x0, 0x1d365a(%rip)    # 0x1fbcd8
je 0x286ad
movq 0x1d35a1(%rip), %rdi    # 0x1fbc28
cvtsi2sdl 0xcc(%rsp), %xmm1
movsd 0x1659c8(%rip), %xmm0   # 0x18e060
mulsd %xmm1, %xmm0
leaq 0x1d6c75(%rip), %rsi    # 0x1ff318
callq 0x2b6f0
jmp 0x287fc
cmpl $0x0, 0x1d3628(%rip)    # 0x1fbcdc
je 0x28741
movq 0x1d3567(%rip), %rax    # 0x1fbc28
movq %rax, 0x20(%rsp)
cvtsi2sdl 0xcc(%rsp), %xmm0
cvtsi2sdl 0xc8(%rsp), %xmm2
movsd 0x165958(%rip), %xmm1   # 0x18e038
mulsd %xmm2, %xmm1
movsd 0x16594c(%rip), %xmm2   # 0x18e038
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0xc0(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x2b770
movsd 0x18(%rsp), %xmm0
leaq 0xa8(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x2b630
movq 0x20(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x2b740
jmp 0x287fa
cmpl $0x0, 0x1d3598(%rip)    # 0x1fbce0
je 0x287f8
movq 0x1d34d3(%rip), %rax    # 0x1fbc28
movq %rax, 0x10(%rsp)
cvtsi2sdl 0xcc(%rsp), %xmm1
movsd 0x1658cd(%rip), %xmm0   # 0x18e038
mulsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movq 0xc0(%rsp), %rdi
callq 0x2b720
movsd (%rsp), %xmm0
movq %rax, %rsi
leaq 0x60(%rsp), %rdi
callq 0x2b630
cvtsi2sdl 0xc8(%rsp), %xmm1
movsd 0x165894(%rip), %xmm0   # 0x18e038
mulsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0xc0(%rsp), %rsi
leaq 0x30(%rsp), %rdi
callq 0x2b7c0
movsd 0x8(%rsp), %xmm0
leaq 0x48(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2b630
leaq 0x78(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0xced50
movq 0x10(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x2b740
jmp 0x287fa
jmp 0x287fc
cmpl $0x0, 0x1d34d5(%rip)    # 0x1fbcd8
jne 0x28817
cmpl $0x0, 0x1d34d0(%rip)    # 0x1fbcdc
jne 0x28817
cmpl $0x0, 0x1d34cb(%rip)    # 0x1fbce0
je 0x2881c
callq 0x179f80
jmp 0x28917
cmpl $0x0, 0x1d34b0(%rip)    # 0x1fbcd8
je 0x28869
movq 0x1d33f7(%rip), %rdi    # 0x1fbc28
movl 0xd4(%rsp), %edx
movl 0xd0(%rsp), %ecx
movl 0xcc(%rsp), %r8d
movl 0xc8(%rsp), %r9d
movq (%rdi), %rax
movsd 0x1657b6(%rip), %xmm0   # 0x18e010
leaq 0x1d3397(%rip), %rsi    # 0x1fbbf8
callq *0x58(%rax)
jmp 0x288f5
cmpl $0x0, 0x1d346c(%rip)    # 0x1fbcdc
je 0x288ae
movq 0x1d33af(%rip), %rdi    # 0x1fbc28
movl 0xd4(%rsp), %edx
movl 0xd0(%rsp), %ecx
movl 0xcc(%rsp), %r8d
movl 0xc8(%rsp), %r9d
movq (%rdi), %rax
movsd 0x16576e(%rip), %xmm0   # 0x18e010
leaq 0x1d334f(%rip), %rsi    # 0x1fbbf8
callq *0x50(%rax)
jmp 0x288f3
cmpl $0x0, 0x1d342b(%rip)    # 0x1fbce0
je 0x288f1
movq 0x1d336a(%rip), %rdi    # 0x1fbc28
movl 0xd4(%rsp), %edx
movl 0xd0(%rsp), %ecx
movl 0xcc(%rsp), %r8d
movl 0xc8(%rsp), %r9d
movq (%rdi), %rax
movsd 0x165729(%rip), %xmm0   # 0x18e010
leaq 0x1d330a(%rip), %rsi    # 0x1fbbf8
callq *0x48(%rax)
jmp 0x288f3
jmp 0x288f5
cmpl $0x0, 0x1d33dc(%rip)    # 0x1fbcd8
jne 0x28910
cmpl $0x0, 0x1d33d7(%rip)    # 0x1fbcdc
jne 0x28910
cmpl $0x0, 0x1d33d2(%rip)    # 0x1fbce0
je 0x28915
callq 0x179f80
jmp 0x28917
movl 0xd4(%rsp), %eax
movl %eax, 0x1d33a4(%rip)    # 0x1fbcc8
movl 0xd0(%rsp), %eax
movl %eax, 0x1d339b(%rip)    # 0x1fbccc
addq $0xd8, %rsp
retq
nopl (%rax)