Thread: Pointer
View Single Post
  #4 (permalink)  
Old March 27th, 2007, 01:02 AM
fReqZz fReqZz is offline
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok. I did this.

Code:
#include <iostream.h>
#include <vector>
#include <fstream.h>

using namespace std;

struct Point
{
    double x,y,z;

};    

struct Tin
{
    int node1, node2, node3;    


};

istream & operator >> (istream & in, Point & pt)
{
    in >> pt.x >> pt.y >> pt.z;

    return in;
}

ostream & operator << (ostream & out , const Point & pt)
{
    out << "(" << pt.x <<","<<  pt.y << "," << pt.z << ")" ;

    return out;
}

Point *ReadVertexFile (char *filename, int &vertexArraySize)
{
    ifstream in (filename, ios::in);


    if (!in.is_open())
    {
    return NULL;
    }

    in >> vertexArraySize;

    Point *vertexArray = new Point[vertexArraySize];

    if (vertexArray == NULL)
    {
        return NULL;
    }

    int index = 0;

    while (in >> vertexArray[index])
    {
        index ++;
    }

    return vertexArray;
}

Tin *ReadTinFile(char *filename, int &TinArraySize)
{
    ifstream in (filename, ios::in);

    if (!in.is_open())
    {
        return NULL;
    }

    in >> TinArraySize;

    Tin *TinArray = new Tin[TinArraySize];

    if (TinArray == NULL)
    {
        return NULL;
    }

    int index = 0;

    while (in >> TinArray[index].node1 >> TinArray[index].node2 >> TinArray[index].node3)
    {
        index ++;
    }

    return TinArray;
}

int main()
{
    int TinArraySize;
    int VertexArraySize;

    Point *vertexArray = ReadVertexFile("lochass.txt", VertexArraySize);
    Tin *TinArray = ReadTinFile("lochas.txt", TinArraySize);

    for ( int i = 0; i < TinArraySize; i++)
    {

        Point vertexA = vertexArray[ TinArray[i].node1 ];
        Point vertexB = vertexArray[ TinArray[i].node2 ];
        Point vertexC = vertexArray[ TinArray[i].node3 ];

        cout << vertexA << "," << vertexB << "," << vertexC << endl;
    }

    return 0;
}
However, one problem. When i wanted to plot the vertex line, it became a problem. OpenGL needs 3 parameter while i have only one for each three coordinates which is vertexA, vertexB and vertexC.

So how could I break those so i can plot it with something like this:

Code:
glVertex3f(node1.x[1],node1.y[1],node1.z[1])
glVertex3f(node2.x[1],node2.y[1],node2.z[1])
glVertex3f(node3.x[1],node3.y[1],node3.z[1])
Thanks.

Reply With Quote