// File: tomfunkhouser[P]gaps/apps/gapsview/gapsview.cpp
// Function: DrawImageRay(ImageData*, gaps::R2Point const&)
static void
DrawImageRay(ImageData *data,
  const R2Point& image_position)
{               
  // Check image position
  R2Box b = data->ray_origin_images[0].GridBox();
  if (!R2Contains(b, image_position)) return;

  // Get ray parameter from images
  RNScalar ox = data->ray_origin_images[0].GridValue(image_position);
  RNScalar oy = data->ray_origin_images[1].GridValue(image_position);
  RNScalar oz = data->ray_origin_images[2].GridValue(image_position);
  RNScalar dx = data->ray_direction_images[0].GridValue(image_position);
  RNScalar dy = data->ray_direction_images[1].GridValue(image_position);
  RNScalar dz = data->ray_direction_images[2].GridValue(image_position);

  // Create ray
  R3Point ray_origin(ox, oy, oz);
  R3Vector ray_direction(dx, dy, dz);
  R3Ray ray(ray_origin, ray_direction);

  // Find projection of selected position onto ray
  RNScalar t = ray.T(selected_position);
  if (t <= 0) return;
  R3Point p = ray.Point(t);

  // Draw ray
  glDisable(GL_LIGHTING);
  RNLoadRgb(0, 1, 1);
  R3Span(ray_origin, p).Draw();
}

// Assembly:
subq $0x198, %rsp            # imm = 0x198
movq %rdi, 0x190(%rsp)
movq %rsi, 0x188(%rsp)
movq 0x190(%rsp), %rsi
addq $0x288, %rsi            # imm = 0x288
leaq 0x160(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x39eb0
movq 0x40(%rsp), %rdi
movq 0x188(%rsp), %rsi
callq 0x1933d0
movl %eax, 0x4c(%rsp)
jmp 0x360a0
movl 0x4c(%rsp), %eax
cmpl $0x0, %eax
jne 0x360df
movl $0x1, 0x150(%rsp)
jmp 0x3633b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x39f60
jmp 0x36350
movq 0x190(%rsp), %rdi
addq $0x288, %rdi            # imm = 0x288
movq 0x188(%rsp), %rsi
callq 0x39f00
movsd %xmm0, 0x38(%rsp)
jmp 0x36103
movsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x148(%rsp)
movq 0x190(%rsp), %rdi
addq $0x358, %rdi            # imm = 0x358
movq 0x188(%rsp), %rsi
callq 0x39f00
movsd %xmm0, 0x30(%rsp)
jmp 0x36136
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x140(%rsp)
movq 0x190(%rsp), %rdi
addq $0x428, %rdi            # imm = 0x428
movq 0x188(%rsp), %rsi
callq 0x39f00
movsd %xmm0, 0x28(%rsp)
jmp 0x36169
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x138(%rsp)
movq 0x190(%rsp), %rdi
addq $0x4f8, %rdi            # imm = 0x4F8
movq 0x188(%rsp), %rsi
callq 0x39f00
movsd %xmm0, 0x20(%rsp)
jmp 0x3619c
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x130(%rsp)
movq 0x190(%rsp), %rdi
addq $0x5c8, %rdi            # imm = 0x5C8
movq 0x188(%rsp), %rsi
callq 0x39f00
movsd %xmm0, 0x18(%rsp)
jmp 0x361cf
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x128(%rsp)
movq 0x190(%rsp), %rdi
addq $0x698, %rdi            # imm = 0x698
movq 0x188(%rsp), %rsi
callq 0x39f00
movsd %xmm0, 0x10(%rsp)
jmp 0x36202
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x120(%rsp)
movsd 0x148(%rsp), %xmm0
movsd 0x140(%rsp), %xmm1
movsd 0x138(%rsp), %xmm2
leaq 0x108(%rsp), %rdi
callq 0x17fd90
jmp 0x3623b
movsd 0x130(%rsp), %xmm0
movsd 0x128(%rsp), %xmm1
movsd 0x120(%rsp), %xmm2
leaq 0xf0(%rsp), %rdi
callq 0x180ef0
jmp 0x36265
leaq 0xc0(%rsp), %rdi
leaq 0x108(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
xorl %ecx, %ecx
callq 0x17f680
jmp 0x36286
leaq 0x2c85fb(%rip), %rsi    # 0x2fe888
leaq 0xc0(%rsp), %rdi
callq 0x17f7c0
movsd %xmm0, 0x8(%rsp)
jmp 0x362a2
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0xb8(%rsp)
xorps %xmm0, %xmm0
ucomisd 0xb8(%rsp), %xmm0
jb 0x362cc
movl $0x1, 0x150(%rsp)
jmp 0x3633b
movsd 0xb8(%rsp), %xmm0
leaq 0xa0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x17f750
jmp 0x362ec
movl $0xb50, %edi            # imm = 0xB50
callq 0x2a130
jmp 0x362f8
xorl %edi, %edi
movl $0x1, %edx
movl %edx, %esi
callq 0x39820
jmp 0x36308
leaq 0x50(%rsp), %rdi
leaq 0x108(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
callq 0x17e7c0
jmp 0x36324
leaq 0x50(%rsp), %rdi
callq 0xf6860
jmp 0x36330
movl $0x0, 0x150(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x39f60
addq $0x198, %rsp            # imm = 0x198
retq
movq 0x158(%rsp), %rdi
callq 0x29c10
nopl (%rax)