// File: /workspace/github_cpp_makefile_star2_O2/SpiritLooper[P]RDV_OBJRender/model.cpp
// Function: Model::Model(char const*)
Model::Model(const char *filename) : verts_(), faces_() {
    std::ifstream in;
    in.open (filename, std::ifstream::in);
    if (in.fail()) return;
    std::string line;
    while (!in.eof()) {
        std::getline(in, line);
        std::istringstream iss(line.c_str());
        char trash;
        if (!line.compare(0, 2, "v ")) {
            iss >> trash;
            Vec3f v;
            for (int i=0;i<3;i++) iss >> v.raw[i];
            verts_.push_back(v);
        } else if (!line.compare(0, 2, "f ")) {
            std::vector<int> f;
          
            int itrash, idx;
            iss >> trash;
            if ( line.find("/") == std::string::npos ){
                while (iss >> idx ) {
                    idx--; // in wavefront obj all indices start at 1, not zero
                    f.push_back(idx);
                }
            } else {
                while (iss >> idx >> trash >> itrash >> trash >> itrash) {
                    idx--; // in wavefront obj all indices start at 1, not zero
                    f.push_back(idx);
                }
            }
            faces_.push_back(f);
        }
    }
    std::cout << "# v# " << verts_.size() << " f# "  << faces_.size() << std::endl;

    // Centrage du model sur l'origine 
    Vec3f min, max, ecart;
    get_bbox(min,max);
    for (int i = 0; i < 3; i++)
    {
        ecart[i] = (min[i] + max[i]) / 2.;
    }
    

    for (int i = 0; i < (int)verts_.size(); i++)
    {
        for (int j = 0; j < 3; j++)
        {
            verts_[i][j] =  verts_[i][j] - ecart[j];
        }   
    }

    get_bbox(min,max);

    // On cherche quel axe déborde le plus à partir de l'origine
    float rapport = std::max( max[0] , std::max( max[1] , max[2] ) );


    // Reduction à l'échelle du model selon l'axe qui nécessite le plus gros rapport de réduction
    for (int i = 0; i < (int)verts_.size(); i++)
    {
        for (int j = 0; j < 3; j++)
        {
            verts_[i][j] = verts_[i][j] / rapport;    
        }
    }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3f8, %rsp            # imm = 0x3F8
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x18(%rdi), %rax
movq %rax, 0x10(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movups %xmm0, (%rdi)
leaq 0x70(%rsp), %rdi
callq 0x21d0
leaq 0x70(%rsp), %rdi
pushq $0x8
popq %rdx
movq %r14, %rsi
callq 0x2110
movq 0x70(%rsp), %rax
movq -0x18(%rax), %rcx
testb $0x5, 0x90(%rsp,%rcx)
jne 0x45eb
leaq 0x60(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
leaq 0x70(%rsp), %r15
leaq 0x20(%rsp), %r13
leaq 0x40(%rsp), %rbp
leaq 0x278(%rsp), %r14
leaq 0x18(%rsp), %r12
movq -0x18(%rax), %rax
testb $0x2, 0x90(%rsp,%rax)
jne 0x43db
movq %r15, %rdi
leaq 0x50(%rsp), %rsi
callq 0x2050
movq 0x50(%rsp), %rsi
movq %r13, %rdi
movq %rbp, %rdx
callq 0x4e1e
movq %r14, %rdi
movq %r13, %rsi
pushq $0x8
popq %rdx
callq 0x2280
movq %r13, %rdi
callq 0x20c0
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
pushq $0x2
popq %rdx
leaq 0x2f16(%rip), %rcx      # 0x71a0
callq 0x2210
testl %eax, %eax
je 0x4382
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
pushq $0x2
popq %rdx
leaq 0x2efb(%rip), %rcx      # 0x71a3
callq 0x2210
testl %eax, %eax
jne 0x43c9
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq %r14, %rdi
leaq 0xf(%rsp), %rsi
callq 0x2200
leaq 0x50(%rsp), %rdi
leaq 0x2eca(%rip), %rsi      # 0x71a6
xorl %edx, %edx
callq 0x22d0
cmpq $-0x1, %rax
je 0x4352
movq %r14, %rdi
movq %r12, %rsi
callq 0x2100
movq %rax, %rdi
leaq 0xf(%rsp), %rsi
callq 0x2200
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2100
movq %rax, %rdi
leaq 0xf(%rsp), %rsi
callq 0x2200
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2100
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x436b
decl 0x18(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x4e7e
jmp 0x42e9
decl 0x18(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x4e7e
movq %r14, %rdi
movq %r12, %rsi
callq 0x2100
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x4343
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x4e9c
movq %r13, %rdi
callq 0x5152
jmp 0x43c9
movq %r14, %rdi
leaq 0xf(%rsp), %rsi
callq 0x2200
andq $0x0, 0x20(%rsp)
andl $0x0, 0x28(%rsp)
xorl %r15d, %r15d
cmpq $0xc, %r15
je 0x43b9
leaq (%rsp,%r15), %rsi
addq $0x20, %rsi
movq %r14, %rdi
callq 0x22e0
addq $0x4, %r15
jmp 0x439d
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4e5a
leaq 0x70(%rsp), %r15
movq %r14, %rdi
callq 0x20d0
movq 0x70(%rsp), %rax
jmp 0x4234
movq 0x6bf6(%rip), %rdi      # 0xafd8
leaq 0x2dbf(%rip), %rsi      # 0x71a8
callq 0x21a0
movq %rax, %rdi
movq 0x8(%rbx), %rax
subq (%rbx), %rax
pushq $0xc
popq %rbp
cqto
idivq %rbp
movq %rax, %rsi
callq 0x2130
leaq 0x2d9f(%rip), %rsi      # 0x71ae
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
movq 0x20(%rbx), %rax
subq 0x18(%rbx), %rax
pushq $0x18
popq %rcx
cqto
idivq %rcx
movq %rax, %rsi
callq 0x2130
movq %rax, %rdi
callq 0x20e0
leaq 0x278(%rsp), %r14
andq $0x0, (%r14)
andl $0x0, 0x8(%r14)
leaq 0x20(%rsp), %r15
andq $0x0, (%r15)
andl $0x0, 0x8(%r15)
leaq 0x40(%rsp), %r12
andq $0x0, (%r12)
andl $0x0, 0x8(%r12)
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x467e
xorl %r13d, %r13d
cmpq $0x3, %r13
je 0x44d2
movq %r14, %rdi
movq %r13, %rsi
callq 0x3902
movss (%rax), %xmm0
movss %xmm0, 0x10(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x3902
movss 0x10(%rsp), %xmm0
addss (%rax), %xmm0
mulss 0x2c36(%rip), %xmm0     # 0x70e8
movss %xmm0, 0x10(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x3902
movss 0x10(%rsp), %xmm0
movss %xmm0, (%rax)
incq %r13
jmp 0x447a
xorl %r12d, %r12d
leaq 0x40(%rsp), %r14
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
idivq %rbp
cltq
cmpq %rax, %r12
jge 0x454f
imulq $0xc, %r12, %r13
xorl %r15d, %r15d
cmpq $0x3, %r15
je 0x454a
movq (%rbx), %rdi
addq %r13, %rdi
movq %r15, %rsi
callq 0x3902
movss (%rax), %xmm0
movss %xmm0, 0x10(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x3902
movss 0x10(%rsp), %xmm0
subss (%rax), %xmm0
movss %xmm0, 0x10(%rsp)
movq (%rbx), %rdi
addq %r13, %rdi
movq %r15, %rsi
callq 0x3902
movss 0x10(%rsp), %xmm0
movss %xmm0, (%rax)
incq %r15
jmp 0x44f4
incq %r12
jmp 0x44da
leaq 0x278(%rsp), %rsi
leaq 0x20(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x467e
movss 0x8(%r14), %xmm0
maxss 0x4(%r14), %xmm0
maxss (%r14), %xmm0
movss %xmm0, 0x1c(%rsp)
xorl %r15d, %r15d
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
idivq %rbp
cltq
cmpq %rax, %r15
jge 0x45e1
imulq $0xc, %r15, %r12
xorl %r14d, %r14d
cmpq $0x3, %r14
je 0x45dc
movq (%rbx), %rdi
addq %r12, %rdi
movq %r14, %rsi
callq 0x3902
movss (%rax), %xmm0
divss 0x1c(%rsp), %xmm0
movss %xmm0, 0x10(%rsp)
movq (%rbx), %rdi
addq %r12, %rdi
movq %r14, %rsi
callq 0x3902
movss 0x10(%rsp), %xmm0
movss %xmm0, (%rax)
incq %r14
jmp 0x459b
incq %r15
jmp 0x4581
leaq 0x50(%rsp), %rdi
callq 0x20c0
leaq 0x70(%rsp), %rdi
callq 0x2060
addq $0x3f8, %rsp            # imm = 0x3F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x465a
movq %rax, %r14
jmp 0x4664
jmp 0x4619
jmp 0x4631
jmp 0x4636
jmp 0x4619
movq %rax, %r14
jmp 0x4650
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x20c0
jmp 0x4650
jmp 0x4631
jmp 0x4636
movq %rax, %r14
jmp 0x4643
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x5152
leaq 0x278(%rsp), %rdi
callq 0x20d0
leaq 0x50(%rsp), %rdi
callq 0x20c0
leaq 0x70(%rsp), %rdi
callq 0x2060
movq 0x10(%rsp), %rdi
callq 0x4ec8
movq %rbx, %rdi
callq 0x40aa
movq %r14, %rdi
callq 0x22b0