I'm writing a Wavefront object loader for work because I don't feel comfortable using code I don't understand in professional projects. After the obvious first step, sorting out which parts are which, I'm attempting to load and log vertices. First and foremost, I wrote a C struct to hold the values.
struct Vertice {
float x;
float y;
float z;
};
Next, I needed a way to log this effectively, so I wrote a preprocessor function, inspired by one found on this site. Jeeze, you guys have everything.
#define LogVertice(VERTICE) NSLog(@"Vertice - X: %0.00000f, Y: %0.00000f, Z: %0.00000f", VERTICE.x, VERTICE.y, VERTICE.z);
Next, I actually load try to parse the vertices.
NSArray *verticeLineParts = [currentLine componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
struct Vertice v;
v.x = [[verticeLineParts objectAtIndex:1] floatValue];
v.y = [[verticeLineParts objectAtIndex:2] floatValue];
v.z = [[verticeLineParts objectAtIndex:3] floatValue];
NSLog(@"%@", currentLine);
LogVertice(v);
I'm not sure of the best way to describe the output other than saying it's wrong, so I'll show you. The first five lines of output:
2010-10-14 13:46:03.587 ObjLoader[1353:207] v -0.035910 1.710543 -0.048286
2010-10-14 13:46:03.594 ObjLoader[1353:207] Vertice - X: -0, Y: 2, Z: -0
2010-10-14 13:46:03.595 ObjLoader[1353:207] v -0.041089 1.710543 -0.048951
2010-10-14 13:46:03.596 ObjLoader[1353:207] Vertice - X: -0, Y: 2, Z: -0
2010-10-14 13:46:03.596 ObjLoader[1353:207] v -0.040913 1.711848 -0.048951
2010-10-14 13:46:03.597 ObjLoader[1353:207] Vertice - X: -0, Y: 2, Z: -0
2010-10-14 13:46:03.598 ObjLoader[1353:207] v -0.040396 1.713069 -0.048951
2010-10-14 13:46:03.599 ObjLoader[1353:207] Vertice - X: -0, Y: 2, Z: -0
2010-10-14 13:46:03.600 ObjLoader[1353:207] v -0.039573 1.714114 -0.048951
2010-10-14 13:46:03.600 ObjLoader[1353:207] Vertice - X: -0, Y: 2, Z: -0
And the first five vertices from the file.
v -0.035910 1.710543 -0.048286
v -0.041089 1.710543 -0.048951
v -0.040913 1.711848 -0.048951
v -0.040396 1.713069 -0.048951
v -0.039573 1.714114 -0.048951
I would say I'm a decent Objective-C programmer, but apparently I can't even get my floats right. Can anyone seen my obvious error?