// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Frustum.cpp
// Function: gaps::R3Frustum::R3Frustum(gaps::R3Point const&, gaps::R3Vector const&, gaps::R3Vector const&, double, double, double, double)
R3Frustum::
R3Frustum(const R3Point& viewpoint, const R3Vector& towards, const R3Vector& up, 
  RNAngle xfov, RNAngle yfov, RNLength neardist, RNLength fardist)
  : cs(viewpoint, R3Triad(towards, up)),
    xfov(xfov),
    yfov(yfov),
    neardist(neardist),
    fardist(fardist)
{
  // Compute halfspaces
  for (int dir = 0; dir < 2; dir++) {
    for (int dim = 0; dim < 3; dim++) {
      R3Vector normal;
      switch (dim) {
      case RN_X:
        normal = cs.Axes().Axis(RN_X); 
        if (dir == RN_LO) normal.Rotate(cs.Axes().Axis(RN_Y), xfov);
        else normal.Rotate(cs.Axes().Axis(RN_Y), RN_PI - xfov);
        halfspaces[dir][dim] = R3Halfspace(cs.Origin(), normal);
        break;

      case RN_Y:
        normal = cs.Axes().Axis(RN_Y); 
        if (dir == RN_LO) normal.Rotate(cs.Axes().Axis(RN_X), -yfov);
        else normal.Rotate(cs.Axes().Axis(RN_X), yfov - RN_PI);
        halfspaces[dir][dim] = R3Halfspace(cs.Origin(), normal);
        break;

      case RN_Z:
        if (dir == RN_LO) {
          halfspaces[dir][dim] = R3Halfspace(cs.Origin() - cs.Axes().Axis(RN_Z) * neardist, -cs.Axes().Axis(RN_Z));
        }
        else {
          halfspaces[dir][dim] = R3Halfspace(cs.Origin() - cs.Axes().Axis(RN_Z) * fardist, cs.Axes().Axis(RN_Z));
        }
        break;

      default:
        RNAbort("Should never get here");
        break;
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movsd %xmm3, 0x30(%rsp)
movsd %xmm2, 0x28(%rsp)
movapd %xmm1, 0x60(%rsp)
movsd %xmm0, 0x20(%rsp)
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r12
callq 0x6edd4
leaq 0xc536f(%rip), %rax     # 0x130bc8
movq %rax, (%r12)
leaq 0xc0(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r12, 0x8(%rsp)
callq 0x71906
leaq 0x8(%r12), %rdi
leaq 0xc0(%rsp), %rdx
movq %rdi, 0x18(%rsp)
movq %rbx, %rsi
callq 0x71408
leaq 0x68(%r12), %rbx
xorl %r15d, %r15d
leaq (%rbx,%r15), %rdi
callq 0x83814
addq $0x20, %r15
cmpq $0xc0, %r15
jne 0x6b897
movq 0x8(%rsp), %r15
movsd 0x20(%rsp), %xmm2
movsd %xmm2, 0x128(%r15)
movapd 0x60(%rsp), %xmm1
movsd %xmm1, 0x130(%r15)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x138(%r15)
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x140(%r15)
leaq 0x50(%r15), %rax
movq %rax, 0x10(%rsp)
leaq 0x20(%r15), %rax
movq %rax, 0x58(%rsp)
leaq 0x38(%r15), %rax
movq %rax, 0x50(%rsp)
leaq 0x7bed8(%rip), %rax     # 0xe77e8
movsd (%rax), %xmm0
movapd %xmm1, %xmm3
subsd %xmm0, %xmm3
movapd %xmm3, 0x90(%rsp)
xorpd 0x72a73(%rip), %xmm1    # 0xde3a0
movapd %xmm1, 0x60(%rsp)
subsd %xmm2, %xmm0
movsd %xmm0, 0x70(%rsp)
leaq 0x120(%rsp), %rbp
leaq 0xc0(%rsp), %rbx
xorl %eax, %eax
movaps 0x60(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x6b98a
movaps 0x90(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %rbp, %rdi
callq 0x85814
testl %r13d, %r13d
je 0x6ba79
cmpl $0x1, %r13d
je 0x6ba37
cmpl $0x2, %r13d
jne 0x6bad1
cmpq $0x0, 0x48(%rsp)
je 0x6bae4
leaq 0xa8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movsd 0x30(%rsp), %xmm0
callq 0x861e6
leaq 0x78(%rsp), %rdi
movq 0x18(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
callq 0x857a5
movq %rbx, %rdi
leaq 0x78(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x83832
movq 0x8(%rsp), %rax
leaq (%rax,%r12), %rdi
addq $0xc8, %rdi
movq %rbx, %rsi
callq 0x85fc2
movsd 0xd8(%rsp), %xmm0
movq 0x8(%rsp), %rax
movsd %xmm0, 0xe0(%rax,%r12)
jmp 0x6bb65
movq %rbp, %rdi
movq 0x50(%rsp), %rsi
callq 0x85fc2
movq %rbp, %rdi
movq 0x58(%rsp), %rsi
movsd 0x40(%rsp), %xmm0
callq 0x85fe2
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movq %rbp, %rdx
callq 0x83832
leaq (%r15,%r12), %rdi
addq $0x68, %rdi
movq %rbx, %rsi
callq 0x85fc2
jmp 0x6bab9
movq %rbp, %rdi
movq 0x58(%rsp), %rsi
callq 0x85fc2
movq %rbp, %rdi
movq 0x50(%rsp), %rsi
movsd 0x38(%rsp), %xmm0
callq 0x85fe2
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movq %rbp, %rdx
callq 0x83832
leaq (%r15,%r12), %rdi
addq $0x68, %rdi
movq %rbx, %rsi
callq 0x85fc2
movsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0x80(%r15,%r12)
jmp 0x6bb65
leaq 0x74199(%rip), %rdi     # 0xdfc71
xorl %eax, %eax
callq 0xadcd6
jmp 0x6bb65
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movsd 0x28(%rsp), %xmm0
callq 0x861e6
leaq 0x78(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
callq 0x857a5
leaq 0x108(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x864ac
movq %rbx, %rdi
leaq 0x78(%rsp), %rsi
leaq 0x108(%rsp), %rdx
callq 0x83832
movq 0x8(%rsp), %rax
leaq (%rax,%r12), %rdi
addq $0x68, %rdi
movq %rbx, %rsi
callq 0x85fc2
movsd 0xd8(%rsp), %xmm0
movq 0x8(%rsp), %rax
movsd %xmm0, 0x80(%rax,%r12)
incl %r13d
addq $0x20, %r12
cmpq $0x60, %r12
jne 0x6b990
movq 0x48(%rsp), %rcx
leaq 0x1(%rcx), %rax
addq $0x60, %r15
testq %rcx, %rcx
je 0x6b94f
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6bbac
jmp 0x6bbac
jmp 0x6bbac
jmp 0x6bbac
jmp 0x6bbac
jmp 0x6bbac
jmp 0x6bbac
movq %rax, %rbx
movq 0x8(%rsp), %rdi
callq 0x6ede0
movq %rbx, %rdi
callq 0x138b0
nop