// File: /workspace/github_cpp_makefile_star2_O2/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 $0xd0, %rsp
movsd %xmm3, 0x28(%rsp)
movsd %xmm2, 0x18(%rsp)
movaps %xmm1, 0x30(%rsp)
movsd %xmm0, 0x20(%rsp)
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
callq 0x649a2
leaq 0xbf34f(%rip), %rax     # 0x120bd8
movq %rax, (%rbx)
leaq 0x40(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x67374
leaq 0x8(%rbx), %r14
leaq 0x40(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x66f12
leaq 0x68(%rbx), %r13
xorl %r15d, %r15d
leaq (%r15,%r13), %rdi
callq 0x76d36
addq $0x20, %r15
cmpq $0xc0, %r15
jne 0x618b7
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x128(%rbx)
movaps 0x30(%rsp), %xmm0
movsd %xmm0, 0x130(%rbx)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x138(%rbx)
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x140(%rbx)
movq %rsp, %rdi
callq 0x7897a
leaq 0x20(%rbx), %r15
movq %rsp, %rdi
movq %r15, %rsi
callq 0x78eec
leaq 0x38(%rbx), %r12
movq %rsp, %rdi
movq %r12, %rsi
movsd 0x20(%rsp), %xmm0
callq 0x78f0c
leaq 0x40(%rsp), %rdi
movq %rsp, %rdx
movq %r14, %rsi
callq 0x76d54
leaq 0x40(%rsp), %rsi
movq %r13, %rdi
callq 0x2865e
movq %rsp, %rdi
callq 0x7897a
movq %rsp, %rdi
movq %r12, %rsi
callq 0x78eec
movapd 0x66a38(%rip), %xmm0    # 0xc83a0
xorpd 0x30(%rsp), %xmm0
movq %rsp, %rdi
movq %r15, %rsi
callq 0x78f0c
leaq 0x40(%rsp), %rdi
movq %rsp, %rdx
movq %r14, %rsi
callq 0x76d54
leaq 0x88(%rbx), %rdi
leaq 0x40(%rsp), %rsi
callq 0x2865e
movq %rsp, %rdi
callq 0x7897a
leaq 0x50(%rbx), %r13
leaq 0x88(%rsp), %rdi
movq %r13, %rsi
movsd 0x18(%rsp), %xmm0
callq 0x79072
leaq 0xa0(%rsp), %rdi
leaq 0x88(%rsp), %rdx
movq %r14, %rsi
callq 0x7890d
leaq 0xb8(%rsp), %rdi
movq %r13, %rsi
callq 0x792e2
leaq 0x40(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
callq 0x76d54
leaq 0xa8(%rbx), %rdi
leaq 0x40(%rsp), %rsi
callq 0x2865e
movq %rsp, %rdi
callq 0x7897a
movq %rsp, %rdi
movq %r15, %rsi
callq 0x78eec
leaq 0x6fd2f(%rip), %rax     # 0xd1758
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
subsd 0x20(%rsp), %xmm0
movq %rsp, %rdi
movq %r12, %rsi
callq 0x78f0c
leaq 0x40(%rsp), %rdi
movq %rsp, %rdx
movq %r14, %rsi
callq 0x76d54
leaq 0xc8(%rbx), %rdi
leaq 0x40(%rsp), %rsi
callq 0x2865e
movq %rsp, %rdi
callq 0x7897a
movq %rsp, %rdi
movq %r12, %rsi
callq 0x78eec
movapd 0x30(%rsp), %xmm0
subsd 0x18(%rsp), %xmm0
movq %rsp, %rdi
movq %r15, %rsi
callq 0x78f0c
leaq 0x40(%rsp), %rdi
movq %rsp, %rdx
movq %r14, %rsi
callq 0x76d54
leaq 0xe8(%rbx), %rdi
leaq 0x40(%rsp), %rsi
callq 0x2865e
movq %rsp, %rdi
callq 0x7897a
leaq 0x88(%rsp), %rdi
movq %r13, %rsi
movsd 0x28(%rsp), %xmm0
callq 0x79072
leaq 0xa0(%rsp), %rdi
leaq 0x88(%rsp), %rdx
movq %r14, %rsi
callq 0x7890d
leaq 0x40(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
movq %r13, %rdx
callq 0x76d54
leaq 0x108(%rbx), %rdi
leaq 0x40(%rsp), %rsi
callq 0x2865e
addq $0xd0, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0x61b2b
jmp 0x61b2b
jmp 0x61b2b
jmp 0x61b2b
jmp 0x61b2b
jmp 0x61b2b
jmp 0x61b2b
movq %rax, %r14
movq %rbx, %rdi
callq 0x649ae
movq %r14, %rdi
callq 0x138f0