// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Draw.cpp
// Function: gaps::R3OrientedBox::Draw(gaps::RNFlags) const
void R3OrientedBox::
Draw(const R3DrawFlags draw_flags) const
{
    // Check if box is empty
    if (IsEmpty()) return;

    static R2Point texcoords[4] = {
	R2Point(0.0, 0.0),
	R2Point(1.0, 0.0),
	R2Point(1.0, 1.0),
	R2Point(0.0, 1.0)
    };
    static int surface_paths[6][4] = {
	{ 3, 0, 1, 2 },
	{ 4, 7, 6, 5 },
	{ 0, 4, 5, 1 },
	{ 7, 3, 2, 6 },
	{ 3, 7, 4, 0 },
        { 1, 5, 6, 2 }
    };
    static int outline_path[16] = {
	0, 1, 2, 3,
	0, 4, 5, 6,
	7, 4, 5, 1,
	2, 6, 7, 3
    };

    /* Get box corner points */
    R3Point corners[8];
    corners[0] = Corner(RN_NNN_OCTANT);
    corners[1] = Corner(RN_NNP_OCTANT);
    corners[2] = Corner(RN_NPP_OCTANT);
    corners[3] = Corner(RN_NPN_OCTANT);
    corners[4] = Corner(RN_PNN_OCTANT);
    corners[5] = Corner(RN_PNP_OCTANT);
    corners[6] = Corner(RN_PPP_OCTANT);
    corners[7] = Corner(RN_PPN_OCTANT);

    // Draw surface
    if (draw_flags[R3_SURFACES_DRAW_FLAG]) {
	for (int i = 0; i < 6; i++) {
	    R3BeginPolygon();
	    if (draw_flags[R3_SURFACE_NORMALS_DRAW_FLAG]) {
                RNScalar sign = (i < 3) ? 1.0 : -1.0;
                R3LoadNormal(sign * Axis(i%3));
            }
	    for (int j = 0; j < 4; j++) {
		if (draw_flags[R3_VERTEX_TEXTURE_COORDS_DRAW_FLAG]) 
		    R3LoadTextureCoords(texcoords[j]);
		R3LoadPoint(corners[surface_paths[i][j]]);
	    }
	    R3EndPolygon();
	}
    }

    // Draw edges
    if (draw_flags[R3_EDGES_DRAW_FLAG]) {
	R3BeginLine();
	for (int i = 0; i < 16; i++)
	    R3LoadPoint(corners[outline_path[i]]);
	R3EndLine();
    }    
}

// Assembly:
subq $0x238, %rsp            # imm = 0x238
movq %rsi, 0x230(%rsp)
movq %rdi, 0x228(%rsp)
movq 0x228(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x3c180
cmpl $0x0, %eax
je 0x77a23
jmp 0x77eac
cmpb $0x0, 0x501de6(%rip)    # 0x579810
jne 0x77aa8
leaq 0x501ddd(%rip), %rdi    # 0x579810
callq 0xf8e0
cmpl $0x0, %eax
je 0x77aa8
leaq 0x501d8c(%rip), %rdi    # 0x5797d0
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0xc3140
jmp 0x77a51
leaq 0x501d88(%rip), %rdi    # 0x5797e0
movsd 0xbb5a8(%rip), %xmm0    # 0x133008
xorps %xmm1, %xmm1
callq 0xc3140
jmp 0x77a6a
leaq 0x501d7f(%rip), %rdi    # 0x5797f0
movsd 0xbb58f(%rip), %xmm1    # 0x133008
movaps %xmm1, %xmm0
callq 0xc3140
jmp 0x77a83
leaq 0x501d76(%rip), %rdi    # 0x579800
xorps %xmm0, %xmm0
movsd 0xbb573(%rip), %xmm1    # 0x133008
callq 0xc3140
jmp 0x77a9c
leaq 0x501d6d(%rip), %rdi    # 0x579810
callq 0xf310
leaq 0x150(%rsp), %rax
movq %rax, %rcx
addq $0xc0, %rcx
movq %rcx, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x6eb40
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, 0x28(%rsp)
jne 0x77ac4
movq 0x30(%rsp), %rsi
leaq 0x138(%rsp), %rdi
xorl %edx, %edx
callq 0x39cf0
leaq 0x150(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x6f1e0
movq 0x30(%rsp), %rsi
leaq 0x120(%rsp), %rdi
movl $0x1, %edx
callq 0x39cf0
leaq 0x150(%rsp), %rdi
addq $0x18, %rdi
leaq 0x120(%rsp), %rsi
callq 0x6f1e0
movq 0x30(%rsp), %rsi
leaq 0x108(%rsp), %rdi
movl $0x3, %edx
callq 0x39cf0
leaq 0x150(%rsp), %rdi
addq $0x30, %rdi
leaq 0x108(%rsp), %rsi
callq 0x6f1e0
movq 0x30(%rsp), %rsi
leaq 0xf0(%rsp), %rdi
movl $0x2, %edx
callq 0x39cf0
leaq 0x150(%rsp), %rdi
addq $0x48, %rdi
leaq 0xf0(%rsp), %rsi
callq 0x6f1e0
movq 0x30(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
movl $0x4, %edx
callq 0x39cf0
leaq 0x150(%rsp), %rdi
addq $0x60, %rdi
leaq 0xd8(%rsp), %rsi
callq 0x6f1e0
movq 0x30(%rsp), %rsi
leaq 0xc0(%rsp), %rdi
movl $0x5, %edx
callq 0x39cf0
leaq 0x150(%rsp), %rdi
addq $0x78, %rdi
leaq 0xc0(%rsp), %rsi
callq 0x6f1e0
movq 0x30(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
movl $0x7, %edx
callq 0x39cf0
leaq 0x150(%rsp), %rdi
addq $0x90, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x6f1e0
movq 0x30(%rsp), %rsi
leaq 0x90(%rsp), %rdi
movl $0x6, %edx
callq 0x39cf0
leaq 0x150(%rsp), %rdi
addq $0xa8, %rdi
leaq 0x90(%rsp), %rsi
callq 0x6f1e0
leaq 0x88(%rsp), %rdi
movl $0x2, %esi
callq 0x13d80
movq 0x88(%rsp), %rsi
leaq 0x230(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x77e3c
movl $0x0, 0x84(%rsp)
cmpl $0x6, 0x84(%rsp)
jge 0x77e3a
callq 0x38e90
leaq 0x78(%rsp), %rdi
movl $0x20, %esi
callq 0x13d80
movq 0x78(%rsp), %rsi
leaq 0x230(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x77d8b
movl 0x84(%rsp), %eax
movsd 0xbb317(%rip), %xmm0    # 0x133008
movsd 0xbb31f(%rip), %xmm1    # 0x133018
movsd %xmm1, 0x8(%rsp)
cmpl $0x3, %eax
movsd %xmm0, 0x10(%rsp)
jl 0x77d16
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x30(%rsp), %rdi
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0x70(%rsp), %xmm0
movsd %xmm0, (%rsp)
movl 0x84(%rsp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %edx, %esi
callq 0x3c1f0
movsd (%rsp), %xmm0
movq %rax, %rsi
leaq 0x58(%rsp), %rdi
callq 0x13800
leaq 0x58(%rsp), %rdi
callq 0x38ea0
jmp 0x77d8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x220(%rsp)
movl %eax, 0x21c(%rsp)
leaq 0x501a8f(%rip), %rdi    # 0x579810
callq 0xf300
jmp 0x77eb4
movl $0x0, 0x54(%rsp)
cmpl $0x4, 0x54(%rsp)
jge 0x77e1f
leaq 0x48(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x13d80
movq 0x48(%rsp), %rsi
leaq 0x230(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x77ddc
movslq 0x54(%rsp), %rax
leaq 0x501a00(%rip), %rdi    # 0x5797d0
shlq $0x4, %rax
addq %rax, %rdi
callq 0x789f0
movslq 0x84(%rsp), %rcx
leaq 0x100615(%rip), %rax    # 0x178400
shlq $0x4, %rcx
addq %rcx, %rax
movslq 0x54(%rsp), %rcx
movslq (%rax,%rcx,4), %rax
leaq 0x150(%rsp), %rdi
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x38e40
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x77d93
callq 0x38ec0
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x77ca5
jmp 0x77e3c
leaq 0x40(%rsp), %rdi
movl $0x1, %esi
callq 0x13d80
movq 0x40(%rsp), %rsi
leaq 0x230(%rsp), %rdi
callq 0x13d50
cmpl $0x0, %eax
je 0x77eac
callq 0x38e70
movl $0x0, 0x3c(%rsp)
cmpl $0x10, 0x3c(%rsp)
jge 0x77ea7
movslq 0x3c(%rsp), %rcx
leaq 0x1005de(%rip), %rax    # 0x178460
movslq (%rax,%rcx,4), %rax
leaq 0x150(%rsp), %rdi
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x38e40
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x77e6f
callq 0x38e80
addq $0x238, %rsp            # imm = 0x238
retq
movq 0x220(%rsp), %rdi
callq 0xf890
nopw %cs:(%rax,%rax)