PDA

View Full Version : ASC importer



SKSlayer
06-05-2000, 06:58 AM
Okay, here's the part of the source code that concert my asc importer . But it doesn't work http://www.opengl.org/discussion_boards/ubb/eek.gif http://www.opengl.org/discussion_boards/ubb/redface.gif(. Anyone can help ? No compilation error, but nothing show up at screen (if I just do a DrawFace(test->pFace[0]) I got a triangle showing up (as that's what DrawFace is supposed to do). Does anyone know why isn't this stuff working ?





typedef struct tagVERTEX
{
double x,y,z;
double u,v;
} VERTEX;

typedef struct tagFACE // face
{
VERTEX vertex[3];
} FACE;

typedef struct tagSECTOR
{
int numface;
int numvertex;
VERTEX *pVertex;
FACE *pFace;
} SECTOR;


double RANDOM_DOUBLE(double min, double max)
{
double x;
double r=max-min;

x=rand();

if (x>max)
{
while(x>max)
{
x=x-(r+1);
}
} else if (x while(x {
x=x+(r-1);
}

} else {
x=x; // Already in range
}

return x;
}


void DrawFace(FACE pFace)
{
glBegin(GL_TRIANGLES);
glColor3d(((RANDOM_DOUBLE(0,100))/100),((RANDOM_DOUBLE(0,100))/100),((RANDOM_DOUBLE(0,100))/100)); // TEMPORARY RANDOM COLOR CODE
glVertex3d(pFace.vertex[0].x,pFace.vertex[0].y,pFace.vertex[0].z);
glColor3d(((RANDOM_DOUBLE(0,100))/100),((RANDOM_DOUBLE(0,100))/100),((RANDOM_DOUBLE(0,100))/100)); // TEMPORARY RANDOM COLOR CODE
glVertex3d(pFace.vertex[1].x,pFace.vertex[1].y,pFace.vertex[1].z);
glColor3d(((RANDOM_DOUBLE(0,100))/100),((RANDOM_DOUBLE(0,100))/100),((RANDOM_DOUBLE(0,100))/100)); // TEMPORARY RANDOM COLOR CODE
glVertex3d(pFace.vertex[2].x,pFace.vertex[2].y,pFace.vertex[2].z);

glEnd();
}

void DrawFace(VERTEX *pVertex1,VERTEX *pVertex2, VERTEX *pVertex3)
{
glBegin(GL_TRIANGLES);
glColor3d(((RANDOM_DOUBLE(0,100))/100),((RANDOM_DOUBLE(0,100))/100),((RANDOM_DOUBLE(0,100))/100)); // TEMPORARY RANDOM COLOR CODE
glVertex3d(pVertex1->x,pVertex1->y,pVertex1->z);
glColor3d(((RANDOM_DOUBLE(0,100))/100),((RANDOM_DOUBLE(0,100))/100),((RANDOM_DOUBLE(0,100))/100)); // TEMPORARY RANDOM COLOR CODE
glVertex3d(pVertex2->x,pVertex2->y,pVertex2->z);
glColor3d(((RANDOM_DOUBLE(0,100))/100),((RANDOM_DOUBLE(0,100))/100),((RANDOM_DOUBLE(0,100))/100)); // TEMPORARY RANDOM COLOR CODE
glVertex3d(pVertex3->x,pVertex3->y,pVertex3->z);
glEnd();

}

void DrawSector(SECTOR *pSector)
{
for (int drse=0; drse<=((pSector->numface)-1);drse++)
{
DrawFace(pSector->pFace[drse]);
}
}

void VertexBind(FACE *pFace, VERTEX *pVertex1, VERTEX *pVertex2, VERTEX *pVertex3)
{
pFace->vertex[0].x=pVertex1->x;
pFace->vertex[0].y=pVertex1->y;
pFace->vertex[0].z=pVertex1->z;
pFace->vertex[1].x=pVertex2->x;
pFace->vertex[1].y=pVertex2->y;
pFace->vertex[1].z=pVertex2->z;
pFace->vertex[2].x=pVertex3->x;
pFace->vertex[2].y=pVertex3->y;
pFace->vertex[2].z=pVertex3->z;

}

void VertexBindn(FACE pFace, VERTEX pVertex1, VERTEX pVertex2, VERTEX pVertex3)
{
pFace.vertex[0].x=pVertex1.x;
pFace.vertex[0].y=pVertex1.y;
pFace.vertex[0].z=pVertex1.z;
pFace.vertex[1].x=pVertex2.x;
pFace.vertex[1].y=pVertex2.y;
pFace.vertex[1].z=pVertex2.z;
pFace.vertex[2].x=pVertex3.x;
pFace.vertex[2].y=pVertex3.y;
pFace.vertex[2].z=pVertex3.z;

}

void readstr(FILE *f,char *string)
{
do
{
fgets(string, 255, f);
} while ((string[0] == '/') // (string[0] == '\n'));
return;
}

void Create(SECTOR *pSector, char path[255])
{
double fx, fy, fz, u, v;
int fnumvertex;
int fnumface;
int fvertactu;
int ffaceactu;

FILE *filein;
char oneline[255];
filein = fopen(path, "rt"); // File To Load World Data From

readstr(filein,oneline);
// sscanf(oneline, "i-mesh, Vertices: %o Faces: %o\n", &amp;fnumvertex, &amp;fnumface);
sscanf(oneline, "Tri-mesh, Vertices: %d Faces: %d\n", &amp;fnumvertex, &amp;fnumface);

//MessageBox(NULL,oneline,oneline,MB_OK);

pSector->numvertex=fnumvertex;
pSector->numface=fnumface;
pSector->pVertex = new VERTEX[((pSector->numvertex)+1)];
pSector->pFace = new FACE[((pSector->numface)+1)];
//pSector->pVertex = new VERTEX[((pSector->numvertex))];
//pSector->pFace = new FACE[((pSector->numface))];


for(int loop=0; loop < pSector->numvertex;loop++) // Get Vertex into Sector
{
readstr(filein,oneline);
sscanf(oneline, "Vertex %d: X: %f Y: %f Z: %f", &amp;fvertactu, &amp;fx, &amp;fy, &amp;fz);
pSector->pVertex[fvertactu].x=fx;
pSector->pVertex[fvertactu].y=fy;
pSector->pVertex[fvertactu].z=fz;

}
int fver1,fver2,fver3,fake;
for(int loop2=0; loop2 < pSector->numface;loop2++) // Get Faces into Sector
{
readstr(filein,oneline);
sscanf(oneline, "Face %d: A:%d B:%d C:%d AB:%d BC:%d CA:%d", &amp;ffaceactu, &amp;fver1, &amp;fver2, &amp;fver3, &amp;fake, &amp;fake, &amp;fake);
VertexBindn(pSector->pFace[ffaceactu], pSector->pVertex[fver1], pSector->pVertex[fver2], pSector->pVertex[fver3]);

}

fclose(filein);
return;
}


void DrawingStuff()
{

SECTOR *test=new SECTOR;

Create(test,"data/model/bio.vfm");
glTranslatef(0.0f,0.0f,-50.0f);
DrawSector(test);
delete test;
test=0;
// .vfm is a renamed .asc

}

Zerosignull
06-06-2000, 11:53 AM
LOL you get around alot sky, im going to start work again on it. patients is a vertue

SKSlayer
06-07-2000, 04:19 AM
huh http://www.opengl.org/discussion_boards/ubb/redface.gif), yes I know.