// File: tomfunkhouser[P]gaps/apps/scnview/scnview.cpp
// Function: DrawLights(gaps::R3Scene*)
static void 
DrawLights(R3Scene *scene)
{
  // Draw all lights
  double radius = scene->BBox().DiagonalRadius();
  for (int i = 0; i < scene->NLights(); i++) {
    R3Light *light = scene->Light(i);
    RNLoadRgb(light->Color());
    if (light->ClassID() == R3DirectionalLight::CLASS_ID()) {
      R3DirectionalLight *directional_light = (R3DirectionalLight *) light;
      R3Vector direction = directional_light->Direction();

      // Draw direction vector
      RNGrfxBegin(RN_GRFX_LINES);
      R3Point centroid = scene->BBox().Centroid();
      R3LoadPoint(centroid - radius * direction);
      R3LoadPoint(centroid - 0.1 * radius * direction);
      RNGrfxEnd();
    }
    else if (light->ClassID() == R3PointLight::CLASS_ID()) {
      // Draw sphere at point light position
      R3PointLight *point_light = (R3PointLight *) light;
      R3Point position = point_light->Position();

      // Draw sphere at light position 
      R3Sphere(position, 0.01 * radius).Draw();
    }
    else if (light->ClassID() == R3SpotLight::CLASS_ID()) {
      R3SpotLight *spot_light = (R3SpotLight *) light;
      R3Point position = spot_light->Position();
      R3Vector direction = spot_light->Direction();

      // Draw sphere at light position 
      R3Sphere(position, 0.01 * radius).Draw();
  
      // Draw direction vector
      RNGrfxBegin(RN_GRFX_LINES);
      R3LoadPoint(position);
      R3LoadPoint(position + 0.025 * radius * direction);
      RNGrfxEnd();
    }
    else {
      RNFail("Unrecognized light type: %d\n", light->ClassID());
      return;
    }
  }
}

// Assembly:
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rdi, 0x1d0(%rsp)
movq 0x1d0(%rsp), %rdi
callq 0x2b590
movq %rax, %rdi
callq 0x2b5b0
movsd %xmm0, 0x1c8(%rsp)
movl $0x0, 0x1c4(%rsp)
movl 0x1c4(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0x1d0(%rsp), %rdi
callq 0x2b9f0
movl %eax, %ecx
movl 0x24(%rsp), %eax
cmpl %ecx, %eax
jge 0x27c2c
movq 0x1d0(%rsp), %rdi
movl 0x1c4(%rsp), %esi
callq 0x2ba10
movq %rax, 0x1b8(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x2ba40
movq %rax, %rdi
callq 0x2b540
movq 0x1b8(%rsp), %rdi
movq (%rdi), %rax
callq *0x78(%rax)
movl %eax, 0x20(%rsp)
callq 0x62130
movl %eax, %ecx
movl 0x20(%rsp), %eax
cmpl %ecx, %eax
jne 0x279cb
movq 0x1b8(%rsp), %rax
movq %rax, 0x1b0(%rsp)
movq 0x1b0(%rsp), %rdi
callq 0x2ba50
movq %rax, %rsi
leaq 0x198(%rsp), %rdi
callq 0xcda10
movl $0x1, %edi
callq 0x2b960
movq 0x1d0(%rsp), %rdi
callq 0x2b590
movq %rax, %rsi
movq (%rsi), %rax
leaq 0x180(%rsp), %rdi
callq *0x68(%rax)
movsd 0x1c8(%rsp), %xmm0
leaq 0x150(%rsp), %rdi
leaq 0x198(%rsp), %rsi
callq 0x2b630
leaq 0x168(%rsp), %rdi
leaq 0x180(%rsp), %rsi
leaq 0x150(%rsp), %rdx
callq 0xcd7d0
leaq 0x168(%rsp), %rdi
callq 0x2b610
movsd 0x1666cf(%rip), %xmm0   # 0x18e048
mulsd 0x1c8(%rsp), %xmm0
leaq 0x120(%rsp), %rdi
leaq 0x198(%rsp), %rsi
callq 0x2b630
leaq 0x138(%rsp), %rdi
leaq 0x180(%rsp), %rsi
leaq 0x120(%rsp), %rdx
callq 0xcd7d0
leaq 0x138(%rsp), %rdi
callq 0x2b610
callq 0x2b9d0
jmp 0x27c14
movq 0x1b8(%rsp), %rdi
movq (%rdi), %rax
callq *0x78(%rax)
movl %eax, 0x1c(%rsp)
callq 0x61290
movl %eax, %ecx
movl 0x1c(%rsp), %eax
cmpl %ecx, %eax
jne 0x27aac
movq 0x1b8(%rsp), %rax
movq %rax, 0x118(%rsp)
movq 0x118(%rsp), %rdi
callq 0x2ba60
movq %rax, %rsi
leaq 0x100(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0xcc8b0
movq 0x10(%rsp), %rsi
movsd 0x1c8(%rsp), %xmm0
movsd 0x166600(%rip), %xmm1   # 0x18e038
mulsd %xmm1, %xmm0
leaq 0xd8(%rsp), %rdi
callq 0xb2bd0
leaq 0xd0(%rsp), %rdi
movl $0x772, %esi            # imm = 0x772
callq 0x2b520
jmp 0x27a5d
movq 0xd0(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x68e80
jmp 0x27a74
leaq 0xd8(%rsp), %rdi
callq 0x2ba70
jmp 0x27c12
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x2ba70
jmp 0x27c34
movq 0x1b8(%rsp), %rdi
movq (%rdi), %rax
callq *0x78(%rax)
movl %eax, 0xc(%rsp)
callq 0x60b60
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jne 0x27bf0
movq 0x1b8(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x2ba60
movq %rax, %rsi
leaq 0xa0(%rsp), %rdi
movq %rdi, (%rsp)
callq 0xcc8b0
movq 0xb8(%rsp), %rdi
callq 0x2ba80
movq %rax, %rsi
leaq 0x88(%rsp), %rdi
callq 0xcda10
movq (%rsp), %rsi
movsd 0x1c8(%rsp), %xmm0
movsd 0x166504(%rip), %xmm1   # 0x18e038
mulsd %xmm1, %xmm0
leaq 0x60(%rsp), %rdi
callq 0xb2bd0
leaq 0x58(%rsp), %rdi
movl $0x772, %esi            # imm = 0x772
callq 0x2b520
jmp 0x27b53
movq 0x58(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0x68e80
jmp 0x27b64
leaq 0x60(%rsp), %rdi
callq 0x2ba70
movl $0x1, %edi
callq 0x2b960
leaq 0xa0(%rsp), %rdi
callq 0x2b610
movsd 0x1664b3(%rip), %xmm0   # 0x18e040
mulsd 0x1c8(%rsp), %xmm0
leaq 0x28(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x2b630
leaq 0x40(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0xcce30
leaq 0x40(%rsp), %rdi
callq 0x2b610
callq 0x2b9d0
jmp 0x27c10
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x2ba70
jmp 0x27c34
movq 0x1b8(%rsp), %rdi
movq (%rdi), %rax
callq *0x78(%rax)
movl %eax, %esi
leaq 0x166675(%rip), %rdi    # 0x18e27c
movb $0x0, %al
callq 0xf3b00
jmp 0x27c2c
jmp 0x27c12
jmp 0x27c14
jmp 0x27c16
movl 0x1c4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c4(%rsp)
jmp 0x27858
addq $0x1d8, %rsp            # imm = 0x1D8
retq
movq 0xc8(%rsp), %rdi
callq 0x23290
nopw %cs:(%rax,%rax)