// File: /workspace/github_cpp_makefile_star2_O2/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 0xb2330
leaq 0x80(%rbx), %r12
leaq 0xc8(%rbx), %r13
leaq 0x38(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0xb3446
leaq 0x68(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xb0f80
movq %rbp, %rdi
leaq 0x18(%rsp), %rsi
callq 0x7fda0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x2f0c6
addsd 0xeafab(%rip), %xmm0    # 0x11a038
movsd %xmm0, 0x30(%rsp)
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0xb3446
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movsd 0x30(%rsp), %xmm0
callq 0xb31d6
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0xb29b8
leaq 0x78(%rbx), %rdi
cmpl $0x0, 0x4bc(%rbx)
sete %cl
movl 0x49c(%rbx), %eax
testl %eax, %eax
sete %dl
orb %cl, %dl
je 0x2f133
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 0x2f188
testl %eax, %eax
je 0x2f161
movq (%rbx), %rax
movsd 0xeaef1(%rip), %xmm0    # 0x11a008
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
movl %r12d, %edx
movl %r15d, %ecx
movl %ebp, %r8d
movl %r14d, %r9d
callq *0x358(%rax)
jmp 0x2f1a6
movsd 0xeb2d5(%rip), %xmm0    # 0x11a410
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 0x6ec68
jmp 0x2f1a6
cmpl $0x0, 0x4a0(%rbx)
je 0x2f17f
movsd 0xeb29e(%rip), %xmm0    # 0x11a410
leaq 0x18(%rsp), %rsi
movl %r12d, %edx
movl %r15d, %ecx
jmp 0x2f154
cmpl $0x0, 0x4a4(%rbx)
je 0x2f1a6
movsd 0xeb280(%rip), %xmm0    # 0x11a410
leaq 0x18(%rsp), %rsi
movl %r12d, %edx
movl %r15d, %ecx
movl %ebp, %r8d
movl %r14d, %r9d
callq 0x6eb96
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