I followed a tutorial online on how to create a obj file parser, so far my parser reads a obj file and stores all the vertices into a struct named coordinate. Am not quite sure, how to use the coordinates in my struct in my main graphic pipeline

My parser:

void ObjParser(const char* szFileName)

    ifstream myfile; //use all the method of the ifstream
    std::vector<coordinate*> vertex;


        //The file is open,use while loop to check file
        char buf[256]; //create buffer to read line

        while(!myfile.eof())//while we are not at the end of the file.
            coord.push_back(new std::string(buf));

        for(int i = 0; i <coord.size(); i++)
            //check if it's a comment or not

             else if(coord[i]->c_str()[0]=='v' && coord[i]->c_str()[1]==' ') 
                 char tmp;
                 float tmp_x,tmp_y,tmp_z;

                 sscanf_s(coord[i]->c_str(),"v %f %f %f",&tmp_x,&tmp_y,&tmp_z); //read in the 3 

                 vertex.push_back(new coordinate(tmp_x,tmp_y,tmp_z)); //and then add it to the end of our vertex list

        //Delete coord to avoid memory leaks
        for(int i = 0; i < coord.size();i++)
        delete coord[i];
        //Display error message, cause the file connot be opened
        MessageBox(NULL, "Error occured while opening file", NULL, NULL);
    //once complete close file.


the structure of my coordinate class:

struct coordinate{

    float x,y,z;
    coordinate(float a, float b,float c) : x(a),y(b),z(c) {};

I wanna be able to use it in my geometry pipeline and create a wireframe of it.
for example at the moment my vertices are had coded like this:

void wireframe(HDC hdc){

    //vertices coordinates:
    const int verticescount = 8;

    Vertex vertices[verticescount] = {Vertex(-5.0f, -5.0f, 5.0f, 1.0f), 
                                      Vertex(5.0f, -5.0f, 5.0f, 1.0f),
                                      Vertex(5.0f, 5.0f, 5.0f, 1.0f),
                                      Vertex(-5.0f, 5.0f, 5.0f, 1.0f),
                                      Vertex(-5.0f, -5.0f, -5.0f, 1.0f),
                                      Vertex(5.0f, -5.0f, -5.0f, 1.0f),
                                      Vertex(5.0f, 5.0f, -5.0f, 1.0f),
                                      Vertex(-5.0f, 5.0f, -5.0f, 1.0f)};


any help appreciated on how to get it working.

sscanf_s(coord[i]->c_str(),"v %f %f %f",&tmp_x,&tmp_y,&tmp_z); //read in the 3
Looks very C-like.

It looks to me like you're going to need some way to specify the relationship of the coordinates, otherwise you can really only draw a line from one coordinate to EVERY other coordinate or assume something equally as silly, right?

I think that information needs to be defined somehow, if that's what you were asking.

Like is the list of coordinates supposed to be in a connect-the-dots fashion for your wireframe where each preceeding coordinate is connected to the successor coordinate? Are you drawing shapes with your coordinates like triangles (set of 3), etc.

It's hard to tell what you're asking.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.