Advertisement

weird coordinates

Started by March 06, 2001 02:50 PM
-1 comments, last by baldurk 23 years, 8 months ago
I have written a program. It reads data in sets of 3, X, Y and Z coords. But after reading the first 3 sets of 3 it over writes the first set of 3 in the second triangle. To explain: 1.0 1.0 1.0 -1.0 1.0 1.0 -1.0 -1.0 1.0 2.0 2.0 2.0 2.0 2.0 -2.0 2.0 -2.0 -2.0 would look like: 1.0 1.0 1.0 -1.0 1.0 1.0 -1.0 -1.0 1.0 -1.0 -1.0 1.0 2.0 2.0 -2.0 2.0 -2.0 -2.0 to it. Weird eh? NEway its annoying to have to work around this so can anyone tell me what is wrong with these functions. Together they read the data. I'll explain the variables later: void assign() { char line[100][255]; float x,y,z; int numtriangles; readstr(fp, line[0]); sscanf(line[0], "numtriangles %u", &numtriangles); model1.triangle = new TRIANGLE[numtriangles]; model1.numtriangles = numtriangles; for(int triloop=0; triloop<model1.numtriangles; triloop++) { for(int vtxloop=0; vtxloop<3; vtxloop++) { readstr(fp, line[triloop]); sscanf(line[triloop], "%f %f %f", &x, &y, &z); model1.triangle[triloop].vertex[vtxloop].x = x; model1.triangle[triloop].vertex[vtxloop].y = y; model1.triangle[triloop].vertex[vtxloop].z = z; model1.triangle[triloop].colour = (float) (triloop%2); debugprint("\ntriangle loop %d, vertex loop %d\n", triloop, vtxloop); debugprint("line is %s", line[triloop]); debugprint("x is %f, y is %f, z is %f\n", x, y, z); } } } and void readstr(FILE *f,char *string) { do { fgets(string, 255, f); } while ((string[0] == '/') || (string[0] == '\n')); return; } some of it is taken from lesson 10. NEway the variables. *fp points to the file and model1 and so on is the equivilent to sector1 from lesson 10. Ignore the debugprint, it just outputs stuff to a file and ignore the colour bit, it works fine. What is wrong with the rest of it?? This message is too long so I'll just say thx in advance Baldur K baldurkarlsson Edited by - baldurk on March 7, 2001 3:46:57 AM

This topic is closed to new replies.

Advertisement