// File: tomfunkhouser[P]gaps/pkgs/R3Graphics/R3SceneNode.cpp
// Function: gaps::R3SceneNode::UpdateBBox()
void R3SceneNode::
UpdateBBox(void)
{
  // Initialize bounding box
  bbox = R3null_box;

  // Add bounding box of elements
  for (int i = 0; i < elements.NEntries(); i++) {
    R3SceneElement *element = elements.Kth(i);
    R3Box element_bbox = element->BBox();
    element_bbox.Transform(transformation);
    bbox.Union(element_bbox);
  }
    
  // Add bounding box of references
  for (int i = 0; i < references.NEntries(); i++) {
    R3SceneReference *reference = references.Kth(i);
    R3Scene *referenced_scene = reference->ReferencedScene();
    if (!referenced_scene) continue;
    R3Box reference_bbox = referenced_scene->BBox();
    reference_bbox.Transform(transformation);
    bbox.Union(reference_bbox);
  }
    
  // Add bounding box of children nodes
  for (int i = 0; i < children.NEntries(); i++) {
    R3SceneNode *child = children.Kth(i);
    R3Box child_bbox = child->BBox();
    child_bbox.Transform(transformation);
    bbox.Union(child_bbox);
  }
}

// Assembly:
subq $0x128, %rsp            # imm = 0x128
movq %rdi, 0x120(%rsp)
movq 0x120(%rsp), %rdi
movq %rdi, 0x30(%rsp)
addq $0x168, %rdi            # imm = 0x168
leaq 0x1a7dfe(%rip), %rsi    # 0x1fe868
callq 0x585e0
movl $0x0, 0x11c(%rsp)
movq 0x30(%rsp), %rdi
movl 0x11c(%rsp), %eax
movl %eax, 0x2c(%rsp)
addq $0x30, %rdi
callq 0x2b8b0
movl %eax, %ecx
movl 0x2c(%rsp), %eax
cmpl %ecx, %eax
jge 0x56b59
movq 0x30(%rsp), %rdi
addq $0x30, %rdi
movl 0x11c(%rsp), %esi
callq 0x2bd50
movq %rax, 0x110(%rsp)
movq 0x110(%rsp), %rdi
callq 0x58430
movq %rax, %rsi
leaq 0xd8(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0xb72c0
movq 0x30(%rsp), %rsi
movq 0x20(%rsp), %rdi
addq $0x58, %rsi
callq 0xb9650
jmp 0x56af5
movq 0x30(%rsp), %rdi
addq $0x168, %rdi            # imm = 0x168
leaq 0xd8(%rsp), %rsi
callq 0xb9110
jmp 0x56b10
leaq 0xd8(%rsp), %rdi
callq 0x2c1a0
movl 0x11c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x11c(%rsp)
jmp 0x56a7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd0(%rsp)
movl %eax, 0xcc(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x2c1a0
jmp 0x56d31
movl $0x0, 0xc8(%rsp)
movq 0x30(%rsp), %rdi
movl 0xc8(%rsp), %eax
movl %eax, 0x1c(%rsp)
addq $0x40, %rdi
callq 0x2b8b0
movl %eax, %ecx
movl 0x1c(%rsp), %eax
cmpl %ecx, %eax
jge 0x56c65
movq 0x30(%rsp), %rdi
addq $0x40, %rdi
movl 0xc8(%rsp), %esi
callq 0x2bd30
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x2bb90
movq %rax, 0xb8(%rsp)
cmpq $0x0, 0xb8(%rsp)
jne 0x56bca
jmp 0x56c29
movq 0xb8(%rsp), %rdi
callq 0x2b590
movq %rax, %rsi
leaq 0x80(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0xb72c0
movq 0x30(%rsp), %rsi
movq 0x10(%rsp), %rdi
addq $0x58, %rsi
callq 0xb9650
jmp 0x56c01
movq 0x30(%rsp), %rdi
addq $0x168, %rdi            # imm = 0x168
leaq 0x80(%rsp), %rsi
callq 0xb9110
jmp 0x56c1c
leaq 0x80(%rsp), %rdi
callq 0x2c1a0
movl 0xc8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc8(%rsp)
jmp 0x56b64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd0(%rsp)
movl %eax, 0xcc(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x2c1a0
jmp 0x56d31
movl $0x0, 0x7c(%rsp)
movq 0x30(%rsp), %rdi
movl 0x7c(%rsp), %eax
movl %eax, 0xc(%rsp)
addq $0x20, %rdi
callq 0x2b8b0
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jge 0x56d29
movq 0x30(%rsp), %rdi
addq $0x20, %rdi
movl 0x7c(%rsp), %esi
callq 0x2bd10
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rdi
callq 0x56d40
movq %rax, %rsi
leaq 0x38(%rsp), %rdi
movq %rdi, (%rsp)
callq 0xb72c0
movq 0x30(%rsp), %rsi
movq (%rsp), %rdi
addq $0x58, %rsi
callq 0xb9650
jmp 0x56cd7
movq 0x30(%rsp), %rdi
addq $0x168, %rdi            # imm = 0x168
leaq 0x38(%rsp), %rsi
callq 0xb9110
jmp 0x56cef
leaq 0x38(%rsp), %rdi
callq 0x2c1a0
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x56c6d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd0(%rsp)
movl %eax, 0xcc(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x2c1a0
jmp 0x56d31
addq $0x128, %rsp            # imm = 0x128
retq
movq 0xd0(%rsp), %rdi
callq 0x23290
nop