// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/apps/scnview/scnview.cpp
// Function: DrawNormals(gaps::R3Scene*, gaps::R3SceneNode*)
static void 
DrawNormals(R3Scene *scene, R3SceneNode *node)
{
  // Push transformation
  node->Transformation().Push();

  // Draw children normals
  for (int i = 0; i < node->NChildren(); i++) {
    R3SceneNode *child = node->Child(i);
    DrawNormals(scene, child);
  }

  // Draw reference normals
  for (int i = 0; i < node->NReferences(); i++) {
    R3SceneReference *reference = node->Reference(i);
    R3Scene *referenced_scene = reference->ReferencedScene();
    DrawNormals(referenced_scene, referenced_scene->Root());
  }

  // Draw element normals
  RNGrfxBegin(RN_GRFX_LINES);
  double r = 0.01 * scene->BBox().DiagonalRadius();
  for (int i = 0; i < node->NElements(); i++) {
    R3SceneElement *element = node->Element(i);
    for (int j = 0; j < element->NShapes(); j++) {
      R3Shape *shape = element->Shape(j);
      if (shape->ClassID() == R3TriangleArray::CLASS_ID()) {
        R3TriangleArray *triangles = (R3TriangleArray *) shape;
        for (int k = 0; k < triangles->NTriangles(); k++) {
          R3Triangle *triangle = triangles->Triangle(k);
          // R3LoadPoint(triangle->Centroid());
          // R3LoadPoint(triangle->Centroid() + r * triangle->Normal());
          for (int v = 0; v < 3; v++) {
            R3TriangleVertex *vertex = triangle->Vertex(v);
            if (!vertex->HasNormal()) continue;
            R3LoadPoint(vertex->Position());
            R3LoadPoint(vertex->Position() + r * vertex->Normal());
          }
        }
      }
    }
  }
  RNGrfxEnd();
  
  // Pop transformation
  node->Transformation().Pop();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r14
movq %rdi, %r15
leaq 0x58(%rsi), %rdi
movq 0x58(%rsi), %rax
movq %rdi, (%rsp)
callq *0xb0(%rax)
cmpl $0x0, 0x2c(%r14)
jle 0x2620a
xorl %ebx, %ebx
movq 0x20(%r14), %rax
movq (%rax,%rbx,8), %rsi
movq %r15, %rdi
callq 0x261bf
incq %rbx
movslq 0x2c(%r14), %rax
cmpq %rax, %rbx
jl 0x261ee
cmpl $0x0, 0x4c(%r14)
jle 0x26232
xorl %ebx, %ebx
movq 0x40(%r14), %rax
movq (%rax,%rbx,8), %rax
movq (%rax), %rdi
movq (%rdi), %rsi
callq 0x261bf
incq %rbx
movslq 0x4c(%r14), %rax
cmpq %rax, %rbx
jl 0x26213
movl $0x1, %edi
callq 0x21190
movq (%r15), %rdi
callq 0x3c988
movq %rax, %rdi
callq 0x6e16c
cmpl $0x0, 0x3c(%r14)
jle 0x26364
mulsd 0xb5dc1(%rip), %xmm0    # 0xdc020
mulsd 0xb5dc1(%rip), %xmm0    # 0xdc028
movsd %xmm0, 0x30(%rsp)
xorl %ecx, %ecx
leaq 0x38(%rsp), %r15
leaq 0x50(%rsp), %r12
movq %r14, 0x8(%rsp)
movq 0x30(%r14), %rax
movq %rcx, 0x10(%rsp)
movq (%rax,%rcx,8), %rcx
cmpl $0x0, 0x1c(%rcx)
jle 0x2634a
xorl %edx, %edx
movq %rcx, 0x18(%rsp)
movq 0x10(%rcx), %rax
movq %rdx, 0x20(%rsp)
movq (%rax,%rdx,8), %rbx
movq (%rbx), %rax
movq %rbx, %rdi
callq *0xb8(%rax)
movl %eax, %ebp
callq 0x6867c
cmpl %eax, %ebp
jne 0x26330
cmpl $0x0, 0x24(%rbx)
jle 0x26330
xorl %r14d, %r14d
movq %rbx, 0x28(%rsp)
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rbx
movl $0x1, %r13d
movq (%rbx,%r13,8), %rbp
testb $0x1, 0x59(%rbp)
je 0x26316
movq %rbp, %rdi
callq 0x211b0
leaq 0x18(%rbp), %rsi
movq %r15, %rdi
movsd 0x30(%rsp), %xmm0
callq 0x77722
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x76605
movq %r12, %rdi
callq 0x211b0
incq %r13
cmpq $0x4, %r13
jne 0x262dc
incq %r14
movq 0x28(%rsp), %rbx
movslq 0x24(%rbx), %rax
cmpq %rax, %r14
jl 0x262ce
movq 0x20(%rsp), %rdx
incq %rdx
movq 0x18(%rsp), %rcx
movslq 0x1c(%rcx), %rax
cmpq %rax, %rdx
jl 0x2629c
movq 0x10(%rsp), %rcx
incq %rcx
movq 0x8(%rsp), %r14
movslq 0x3c(%r14), %rax
cmpq %rax, %rcx
jl 0x2627e
callq 0x21c60
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0xb8(%rax)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq