// File: /workspace/github_cpp_makefile_star2_O3/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 0xc3d42
leaq 0x80(%rbx), %r12
leaq 0xc8(%rbx), %r13
leaq 0x38(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0xc5400
leaq 0x68(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xc28b2
movq %rbp, %rdi
leaq 0x18(%rsp), %rsi
callq 0x8bd3b
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x303ac
addsd 0x107cc5(%rip), %xmm0   # 0x138038
movsd %xmm0, 0x30(%rsp)
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0xc5400
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movsd 0x30(%rsp), %xmm0
callq 0xc5162
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0xc469a
leaq 0x78(%rbx), %rdi
cmpl $0x0, 0x4bc(%rbx)
sete %cl
movl 0x49c(%rbx), %eax
testl %eax, %eax
sete %dl
orb %cl, %dl
je 0x30419
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 0x3046e
testl %eax, %eax
je 0x30447
movq (%rbx), %rax
movsd 0x107c0b(%rip), %xmm0   # 0x138008
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
movl %r12d, %edx
movl %r15d, %ecx
movl %ebp, %r8d
movl %r14d, %r9d
callq *0x358(%rax)
jmp 0x3048c
movsd 0x107fef(%rip), %xmm0   # 0x138410
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 0x7899a
jmp 0x3048c
cmpl $0x0, 0x4a0(%rbx)
je 0x30465
movsd 0x107fb8(%rip), %xmm0   # 0x138410
leaq 0x18(%rsp), %rsi
movl %r12d, %edx
movl %r15d, %ecx
jmp 0x3043a
cmpl $0x0, 0x4a4(%rbx)
je 0x3048c
movsd 0x107f9a(%rip), %xmm0   # 0x138410
leaq 0x18(%rsp), %rsi
movl %r12d, %edx
movl %r15d, %ecx
movl %ebp, %r8d
movl %r14d, %r9d
callq 0x788a8
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