// File: tomfunkhouser[P]gaps/pkgs/R3Graphics/R3Camera.cpp
// Function: gaps::R3Camera::Halfspace(int, int) const
const R3Halfspace R3Camera::
Halfspace(RNDirection dir, RNDimension dim) const
{
    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);
	return R3Halfspace(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);
	return R3Halfspace(Origin(), normal);
        break;

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

    // Should never get here
    RNAbort("Invalid dim in camera halfspace query");
    return R3null_halfspace;
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0x10(%rsp)
movq %rdi, %rax
movq %rax, 0x18(%rsp)
movq %rdi, 0xd0(%rsp)
movq %rsi, 0xc8(%rsp)
movl %edx, 0xc4(%rsp)
movl %ecx, 0xc0(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0xcd9c0
movl 0xc0(%rsp), %eax
movl %eax, 0x2c(%rsp)
testl %eax, %eax
je 0x5deae
jmp 0x5de8d
movl 0x2c(%rsp), %eax
subl $0x1, %eax
je 0x5df6f
jmp 0x5de9c
movl 0x2c(%rsp), %eax
subl $0x2, %eax
je 0x5e044
jmp 0x5e160
movq 0x20(%rsp), %rdi
callq 0x2bf20
movq %rax, %rdi
xorl %esi, %esi
callq 0x2bf30
movq %rax, %rsi
leaq 0xa8(%rsp), %rdi
callq 0xce690
cmpl $0x0, 0xc4(%rsp)
jne 0x5df0f
movq 0x20(%rsp), %rdi
callq 0x2bf20
movq %rax, %rdi
movl $0x1, %esi
callq 0x2bf30
movq %rax, %rsi
movq 0x20(%rsp), %rax
movsd 0x60(%rax), %xmm0
leaq 0xa8(%rsp), %rdi
callq 0xce6d0
jmp 0x5df4b
movq 0x20(%rsp), %rdi
callq 0x2bf20
movq %rax, %rdi
movl $0x1, %esi
callq 0x2bf30
movq %rax, %rsi
movq 0x20(%rsp), %rax
leaq 0x133ccb(%rip), %rcx    # 0x191c00
movsd (%rcx), %xmm0
subsd 0x60(%rax), %xmm0
leaq 0xa8(%rsp), %rdi
callq 0xce6d0
movq 0x20(%rsp), %rdi
callq 0x2b900
movq 0x10(%rsp), %rdi
movq %rax, %rsi
leaq 0xa8(%rsp), %rdx
callq 0xc9cc0
jmp 0x5e17f
movq 0x20(%rsp), %rdi
callq 0x2bf20
movq %rax, %rdi
movl $0x1, %esi
callq 0x2bf30
movq %rax, %rsi
leaq 0xa8(%rsp), %rdi
callq 0xce690
cmpl $0x0, 0xc4(%rsp)
jne 0x5dfe7
movq 0x20(%rsp), %rdi
callq 0x2bf20
movq %rax, %rdi
xorl %esi, %esi
callq 0x2bf30
movq %rax, %rsi
movq 0x20(%rsp), %rax
movsd 0x68(%rax), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
leaq 0xa8(%rsp), %rdi
callq 0xce6d0
jmp 0x5e020
movq 0x20(%rsp), %rdi
callq 0x2bf20
movq %rax, %rdi
xorl %esi, %esi
callq 0x2bf30
movq %rax, %rsi
movq 0x20(%rsp), %rax
movsd 0x68(%rax), %xmm0
leaq 0x133bf1(%rip), %rax    # 0x191c00
subsd (%rax), %xmm0
leaq 0xa8(%rsp), %rdi
callq 0xce6d0
movq 0x20(%rsp), %rdi
callq 0x2b900
movq 0x10(%rsp), %rdi
movq %rax, %rsi
leaq 0xa8(%rsp), %rdx
callq 0xc9cc0
jmp 0x5e17f
cmpl $0x0, 0xc4(%rsp)
jne 0x5e0e6
movq 0x20(%rsp), %rdi
callq 0x2b900
movq 0x20(%rsp), %rdi
movq %rax, 0x8(%rsp)
callq 0x2bf20
movq %rax, %rdi
movl $0x2, %esi
callq 0x2bf30
movq %rax, %rsi
movq 0x20(%rsp), %rax
movsd 0x70(%rax), %xmm0
leaq 0x78(%rsp), %rdi
callq 0xce8a0
movq 0x8(%rsp), %rsi
leaq 0x90(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0xcd7d0
movq 0x20(%rsp), %rdi
callq 0x2bf20
movq %rax, %rdi
movl $0x2, %esi
callq 0x2bf30
movq %rax, %rsi
leaq 0x60(%rsp), %rdi
callq 0xcecc0
movq 0x10(%rsp), %rdi
leaq 0x90(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0xc9cc0
jmp 0x5e17f
movq 0x20(%rsp), %rdi
callq 0x2b900
movq 0x20(%rsp), %rdi
movq %rax, (%rsp)
callq 0x2bf20
movq %rax, %rdi
movl $0x2, %esi
callq 0x2bf30
movq %rax, %rsi
movq 0x20(%rsp), %rax
movsd 0x78(%rax), %xmm0
leaq 0x30(%rsp), %rdi
callq 0xce8a0
movq (%rsp), %rsi
leaq 0x48(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0xcd7d0
movq 0x20(%rsp), %rdi
callq 0x2bf20
movq %rax, %rdi
movl $0x2, %esi
callq 0x2bf30
movq 0x10(%rsp), %rdi
movq %rax, %rdx
leaq 0x48(%rsp), %rsi
callq 0xc9cc0
jmp 0x5e17f
leaq 0x131ba1(%rip), %rdi    # 0x18fd08
movb $0x0, %al
callq 0xf39f0
movq 0x10(%rsp), %rdi
leaq 0x1a0bb6(%rip), %rsi    # 0x1fed30
callq 0xc9be0
movq 0x18(%rsp), %rax
addq $0xd8, %rsp
retq
nopl (%rax)