// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Utils/R3SurfelViewer.cpp
// Function: gaps::R3SurfelViewer::MouseMotion(int, int)
int R3SurfelViewer::
MouseMotion(int x, int y)
{
  // Initialize
  int redraw = 0;

  // Compute mouse movement
  int dx = x - mouse_position[0];
  int dy = y - mouse_position[1];

  // Set viewing center point
  R3Point viewing_center_point = center_point;
  const R3Camera& camera = viewer.Camera();
  R3Plane camera_plane(camera.Origin(), camera.Towards());
  RNScalar signed_distance = R3SignedDistance(camera_plane, viewing_center_point);
  if (signed_distance < 0) viewing_center_point -= (signed_distance - 1) * camera.Towards();
  
  // World in hand navigation 
  if (shift_down && mouse_button[0]) viewer.ScaleWorld(2.0, viewing_center_point, x, y, dx, dy);
  else if (ctrl_down && mouse_button[0]) viewer.TranslateWorld(2.0, viewing_center_point, x, y, dx, dy);
  else if (mouse_button[0]) RotateWorld(1.0, viewing_center_point, x, y, dx, dy);
  else if (mouse_button[1]) viewer.ScaleWorld(2.0, viewing_center_point, x, y, dx, dy);
  else if (mouse_button[2]) viewer.TranslateWorld(2.0, viewing_center_point, x, y, dx, dy);
  if (mouse_button[0] || mouse_button[1] || mouse_button[2]) redraw = 1;

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

  // Update mouse drag movement
  mouse_drag_distance_squared += dx*dx + dy*dy;

  // Return whether need redraw
  return redraw;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %edx, %r14d
movq %rdi, %rbx
movl %esi, 0xc(%rsp)
movl %esi, %eax
subl 0x4a8(%rdi), %eax
movl %eax, 0x14(%rsp)
movl %edx, 0x10(%rsp)
subl 0x4ac(%rdi), %r14d
leaq 0x2b0(%rdi), %rsi
leaq 0x18(%rsp), %rdi
callq 0xc532e
leaq 0x80(%rbx), %r12
leaq 0xc8(%rbx), %r13
leaq 0x38(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0xc6a4c
leaq 0x68(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xc3e9e
movq %rbp, %rdi
leaq 0x18(%rsp), %rsi
callq 0x8cc8b
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x30508
addsd 0x10ab69(%rip), %xmm0   # 0x13b038
movsd %xmm0, 0x30(%rsp)
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0xc6a4c
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movsd 0x30(%rsp), %xmm0
callq 0xc6786
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0xc5c8c
leaq 0x78(%rbx), %rdi
cmpl $0x0, 0x4bc(%rbx)
sete %cl
movl 0x49c(%rbx), %eax
testl %eax, %eax
sete %dl
orb %cl, %dl
je 0x30575
testl %eax, %eax
sete %cl
cmpl $0x0, 0x4c0(%rbx)
sete %dl
orb %cl, %dl
movl 0x14(%rsp), %ebp
movl 0x10(%rsp), %r15d
movl 0xc(%rsp), %r12d
je 0x305ca
testl %eax, %eax
je 0x305a3
movq (%rbx), %rax
movsd 0x10aaaf(%rip), %xmm0   # 0x13b008
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
movl %r12d, %edx
movl %r15d, %ecx
movl %ebp, %r8d
movl %r14d, %r9d
callq *0x358(%rax)
jmp 0x305e8
movsd 0x10ae93(%rip), %xmm0   # 0x13b410
leaq 0x18(%rsp), %rsi
movl 0xc(%rsp), %r12d
movl %r12d, %edx
movl 0x10(%rsp), %r15d
movl %r15d, %ecx
movl 0x14(%rsp), %ebp
movl %ebp, %r8d
movl %r14d, %r9d
callq 0x791ae
jmp 0x305e8
cmpl $0x0, 0x4a0(%rbx)
je 0x305c1
movsd 0x10ae5c(%rip), %xmm0   # 0x13b410
leaq 0x18(%rsp), %rsi
movl %r12d, %edx
movl %r15d, %ecx
jmp 0x30596
cmpl $0x0, 0x4a4(%rbx)
je 0x305e8
movsd 0x10ae3e(%rip), %xmm0   # 0x13b410
leaq 0x18(%rsp), %rsi
movl %r12d, %edx
movl %r15d, %ecx
movl %ebp, %r8d
movl %r14d, %r9d
callq 0x790bc
movl 0x4a0(%rbx), %ecx
orl 0x49c(%rbx), %ecx
xorl %eax, %eax
orl 0x4a4(%rbx), %ecx
setne %al
movl %r12d, 0x4a8(%rbx)
movl %r15d, 0x4ac(%rbx)
imull %ebp, %ebp
imull %r14d, %r14d
addl %ebp, %r14d
addl %r14d, 0x4b8(%rbx)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq