// File: /workspace/github_cpp_makefile_star2_O3/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe0, %rsp
movsd %xmm3, 0x30(%rsp)
movsd %xmm2, 0x20(%rsp)
movaps %xmm1, 0x80(%rsp)
movsd %xmm0, 0x28(%rsp)
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
callq 0x6e168
leaq 0xc4f96(%rip), %rax     # 0x12fbc8
movq %rax, (%rbx)
leaq 0x38(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x70ca6
leaq 0x8(%rbx), %r14
leaq 0x38(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x707a8
leaq 0x68(%rbx), %r13
xorl %r15d, %r15d
leaq (%r15,%r13), %rdi
callq 0x82858
addq $0x20, %r15
cmpq $0xc0, %r15
jne 0x6ac60
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x128(%rbx)
movaps 0x80(%rsp), %xmm0
movsd %xmm0, 0x130(%rbx)
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x138(%rbx)
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x140(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x84854
leaq 0x20(%rbx), %r15
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x84fe2
leaq 0x38(%rbx), %r12
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
movsd 0x28(%rsp), %xmm0
callq 0x85002
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rdx
movq %r14, %rsi
callq 0x82876
leaq 0x38(%rsp), %rsi
movq %r13, %rdi
callq 0x84fe2
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x80(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x84854
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x84fe2
movapd 0x72672(%rip), %xmm0    # 0xdd3a0
xorpd 0x80(%rsp), %xmm0
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x85002
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rdx
movq %r14, %rsi
callq 0x82876
leaq 0x88(%rbx), %rdi
leaq 0x38(%rsp), %rsi
callq 0x84fe2
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0xa0(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x84854
leaq 0x50(%rbx), %r13
leaq 0x98(%rsp), %rdi
movq %r13, %rsi
movsd 0x20(%rsp), %xmm0
callq 0x851f2
leaq 0xb0(%rsp), %rdi
leaq 0x98(%rsp), %rdx
movq %r14, %rsi
callq 0x847e3
leaq 0xc8(%rsp), %rdi
movq %r13, %rsi
callq 0x85490
leaq 0x38(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
callq 0x82876
leaq 0xa8(%rbx), %rdi
leaq 0x38(%rsp), %rsi
callq 0x84fe2
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0xc0(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x84854
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x84fe2
leaq 0x7b9c0(%rip), %rax     # 0xe67d8
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
subsd 0x28(%rsp), %xmm0
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x85002
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rdx
movq %r14, %rsi
callq 0x82876
leaq 0xc8(%rbx), %rdi
leaq 0x38(%rsp), %rsi
callq 0x84fe2
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0xe0(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x84854
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x84fe2
movapd 0x80(%rsp), %xmm0
subsd 0x20(%rsp), %xmm0
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x85002
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rdx
movq %r14, %rsi
callq 0x82876
leaq 0xe8(%rbx), %rdi
leaq 0x38(%rsp), %rsi
callq 0x84fe2
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x100(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x84854
leaq 0x98(%rsp), %rdi
movq %r13, %rsi
movsd 0x30(%rsp), %xmm0
callq 0x851f2
leaq 0xb0(%rsp), %rdi
leaq 0x98(%rsp), %rdx
movq %r14, %rsi
callq 0x847e3
leaq 0x38(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
movq %r13, %rdx
callq 0x82876
leaq 0x108(%rbx), %rdi
leaq 0x38(%rsp), %rsi
callq 0x84fe2
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x120(%rbx)
addq $0xe0, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0x6af55
jmp 0x6af55
jmp 0x6af55
jmp 0x6af55
jmp 0x6af55
jmp 0x6af55
jmp 0x6af55
movq %rax, %r14
movq %rbx, %rdi
callq 0x6e174
movq %r14, %rdi
callq 0x138b0