Rendering Help [Solved]


Rendering Help [Solved]
#1
[Edit] I wasn't there was a better forum subsection for DIY rendering, and came across enough projects over there to realize that when I switched over to the show your work arrays, I got my matrices backward for the child transformations.


I've been working on my off again on again graphics engine project and decided to combine my passion for LEGO's as well, but I've hit a stumbling block with loading the .dat files. It seems the once I get a couple levels down everything goes to heck. i've been testing with 4070.dat (1x1 Brick with headlight), and everything seems fine except for the headlight (stud2a.dat) it's squashed on the y axis. Other problems pop up when I try other models. I know it's something in my matrix transformations, and I've tried everything I can think of (went from clean Matrix objects to "show your work" variable arrays, switched from floats to doubles, etc.), and hit a brick wall on searching for examples on the net, so I'm hoping another set of eyes will be what I need. I'm in the testing stage, so the code is kinda ugly, but for the double[12] arrays i'm holding the matrix in, 0->8 is "a" to "i" and 9->11 is "xyz". I'm also attaching a screen shot of 4070.dat with everything but "stud2a" and "stud" removed, so you can see how odd "stud2" looks. Thanks for any help.


Code:
void loadDAT(wchar_t * wcs_filename, bool b_child, double f33_matrix[12], bool b_bfcInvert)
{
    std::ifstream File(wcs_filename);
    std::string Line;
    std::string Name;
    std::string BFC;
    std::string BFCCommand;
    bool b_bfcInvertOut = b_bfcInvert;
    
    while(std::getline(File, Line))
    {
        if(Line == "" || Line[0] == '#')// Skip everything and continue with the next line
        continue;

        std::istringstream LineStream(Line);
        LineStream >> Name;
        LineStream >> BFC;
        LineStream >> BFCCommand;

        if(Name == "0")
        {
            if(BFC == "BFC")
                if(BFCCommand == "INVERTNEXT")
                    if(b_bfcInvertOut) b_bfcInvertOut = false;
                        else b_bfcInvertOut = true;
        }

        if(Name == "4")
        {
            double f_vertex[12];
            sscanf(Line.c_str(), "%*f %*f %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", &f_vertex[0], &f_vertex[1], &f_vertex[2], &f_vertex[3], &f_vertex[4], &f_vertex[5], &f_vertex[6], &f_vertex[7], &f_vertex[8], &f_vertex[9], &f_vertex[10], &f_vertex[11]);
            Sv3_VERTEX v3_temp[4];
            for(int x=0; x < 4;x++)
            {
                v3_temp[x].pos.x = (f33_matrix[0]*f_vertex[(x*3)]) + (f33_matrix[1]*f_vertex[(x*3) + 1]) + (f33_matrix[2]*f_vertex[(x*3) + 2]) + f33_matrix[9];
                v3_temp[x].pos.y = (f33_matrix[3]*f_vertex[(x*3)]) + (f33_matrix[4]*f_vertex[(x*3) + 1]) + (f33_matrix[5]*f_vertex[(x*3) + 2]) + f33_matrix[10];
                v3_temp[x].pos.z = (f33_matrix[6]*f_vertex[(x*3)]) + (f33_matrix[7]*f_vertex[(x*3) + 1]) + (f33_matrix[8]*f_vertex[(x*3) + 2]) + f33_matrix[11];

                v3i_lego.v3ap_vertex.push_back(v3_temp[x]);
            }
        
            if(!b_bfcInvert) v3i_lego.uap_index.push_back(0 + i_triangleCount);
                else v3i_lego.uap_index.push_back(3 + i_triangleCount);
        
            v3i_lego.uap_index.push_back(1 + i_triangleCount);
            
            if(!b_bfcInvert) v3i_lego.uap_index.push_back(3 + i_triangleCount);
                else v3i_lego.uap_index.push_back(0 + i_triangleCount);

            if(!b_bfcInvert) v3i_lego.uap_index.push_back(2 + i_triangleCount);
                else v3i_lego.uap_index.push_back(1 + i_triangleCount);
            
            v3i_lego.uap_index.push_back(3 + i_triangleCount);
            
            if(!b_bfcInvert) v3i_lego.uap_index.push_back(1 + i_triangleCount);
                else v3i_lego.uap_index.push_back(2 + i_triangleCount);

            i_triangleCount += 4;
        }

        if(Name == "3")
        {
            double f_vertex[9];
            sscanf(Line.c_str(), "%*f %*f %lf %lf %lf %lf %lf %lf %lf %lf %lf", &f_vertex[0], &f_vertex[1], &f_vertex[2], &f_vertex[3], &f_vertex[4], &f_vertex[5], &f_vertex[6], &f_vertex[7], &f_vertex[8]);
            Sv3_VERTEX v3_temp[3];
            for(int x=0; x < 3;x++)
            {
                v3_temp[x].pos.x = (f33_matrix[0]*f_vertex[(x*3)]) + (f33_matrix[1]*f_vertex[(x*3) + 1]) + (f33_matrix[2]*f_vertex[(x*3) + 2]) + f33_matrix[9];
                v3_temp[x].pos.y = (f33_matrix[3]*f_vertex[(x*3)]) + (f33_matrix[4]*f_vertex[(x*3) + 1]) + (f33_matrix[5]*f_vertex[(x*3) + 2]) + f33_matrix[10];
                v3_temp[x].pos.z = (f33_matrix[6]*f_vertex[(x*3)]) + (f33_matrix[7]*f_vertex[(x*3) + 1]) + (f33_matrix[8]*f_vertex[(x*3) + 2]) + f33_matrix[11];

                v3i_lego.v3ap_vertex.push_back(v3_temp[x]);
            }
        
            if(!b_bfcInvert) v3i_lego.uap_index.push_back(2 + i_triangleCount);
                else v3i_lego.uap_index.push_back(0 + i_triangleCount);
            
            v3i_lego.uap_index.push_back(1 + i_triangleCount);
    
            if(!b_bfcInvert) v3i_lego.uap_index.push_back(0 + i_triangleCount);
                else v3i_lego.uap_index.push_back(2 + i_triangleCount);

            i_triangleCount += 3;
        }

        if(Name == "1")
        {
            double f_vertex[12];
            wchar_t wcs_filenameSub[200];
            sscanf(Line.c_str(), "%*f %*f %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %S", &f_vertex[9], &f_vertex[10], &f_vertex[11], &f_vertex[0], &f_vertex[1], &f_vertex[2], &f_vertex[3], &f_vertex[4], &f_vertex[5], &f_vertex[6], &f_vertex[7], &f_vertex[8], wcs_filenameSub);
            double f33_out[12] = {f_vertex[0],f_vertex[1],f_vertex[2],f_vertex[3],f_vertex[4],f_vertex[5],f_vertex[6],f_vertex[7],f_vertex[8],f_vertex[9],f_vertex[10],f_vertex[11]};

                double f33_hold[12] = {1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f,0.0f};
            
                f33_hold[0] = (f33_out[0] * f33_matrix[0]) + (f33_out[1] * f33_matrix[3]) + (f33_out[2] * f33_matrix[6]);
                f33_hold[3] = (f33_out[3] * f33_matrix[0]) + (f33_out[4] * f33_matrix[3]) + (f33_out[5] * f33_matrix[6]);
                f33_hold[6] = (f33_out[6] * f33_matrix[0]) + (f33_out[7] * f33_matrix[3]) + (f33_out[8] * f33_matrix[6]);
            
                f33_hold[1] = (f33_out[0] * f33_matrix[1]) + (f33_out[1] * f33_matrix[4]) + (f33_out[2] * f33_matrix[7]);
                f33_hold[4] = (f33_out[3] * f33_matrix[1]) + (f33_out[4] * f33_matrix[4]) + (f33_out[5] * f33_matrix[7]);
                f33_hold[7] = (f33_out[6] * f33_matrix[1]) + (f33_out[7] * f33_matrix[4]) + (f33_out[8] * f33_matrix[7]);
            
                f33_hold[2] = (f33_out[0] * f33_matrix[2]) + (f33_out[1] * f33_matrix[5]) + (f33_out[2] * f33_matrix[8]);
                f33_hold[5] = (f33_out[3] * f33_matrix[2]) + (f33_out[4] * f33_matrix[5]) + (f33_out[5] * f33_matrix[8]);
                f33_hold[8] = (f33_out[6] * f33_matrix[2]) + (f33_out[7] * f33_matrix[5]) + (f33_out[8] * f33_matrix[8]);
                
                f33_hold[9] = f33_hold[0]*f_vertex[9] + f33_hold[1]*f_vertex[10] + f33_hold[2]*f_vertex[11] + f33_matrix[9];
                f33_hold[10] = f33_hold[3]*f_vertex[9] + f33_hold[4]*f_vertex[10] + f33_hold[5]*f_vertex[11] + f33_matrix[10];
                f33_hold[11] = f33_hold[6]*f_vertex[9] + f33_hold[7]*f_vertex[10] + f33_hold[8]*f_vertex[11] + f33_matrix[11];
            
            loadDAT(CfileLocations::getModelsSubParts(wcs_filenameSub),true,f33_hold, b_bfcInvertOut);
        }

    }
}


Attached Files Thumbnail(s)
   
Reply
« Next Oldest | Next Newest »



Forum Jump:


Users browsing this thread: 1 Guest(s)