I'm having problems reading the Vertex List chunk of the 3DS model format.
I keep getting numbers like: -1.#QNAN which I understand means "quiet not a number" and then numbers like 2.0345E-041, I think that's standard form?
I followed this tutorial,
http://www.spacesimulator.net/tut4_3dsloader.html, but I'm using C++ and i'm converting everything to little endian.
Here's my code:
template <typename T> union Buffer {
unsigned char bytes[sizeof(T)];
T value;
};
bool isLittleEndian() {
Buffer<unsigned short> b;
b.value = 1;
return (b.bytes[0] == 1);
}
template<typename T> void Read(T& value, std::ifstream& in) {
Buffer<T> e;
in.read(reinterpret_cast<char*>(&e.bytes[0]), sizeof(T));
if(isLittleEndian()) {
value = e.value;
return;
}
char t;
for(int i = 0, j = sizeof(T); i < j--; i++) {
t = e.bytes;
e.bytes = e.bytes[j];
e.bytes[j] = t;
}
value = e.value;
}
while(in.tellg() < size) {
Read<unsigned short>(info.ID, in);
Read<int>(info.Size, in);
info.Offset = in.tellg();
switch(info.ID) {
//...
case VERTEX_LIST:
int numVertices;
Read<int>(numVertices, in);
for(i = 0; i < numVertices; i++) {
Read<FLOAT>(v.x, in);
Read<FLOAT>(v.y, in);
Read<FLOAT>(v.z, in);
mesh.Vertices.push_back(v);
v.x = v.y = v.z = 0.0f;
}
in.seekg(info.Offset + info.Size - 6);
break;
//...
default:
in.seekg(info.Size -6, std::ios_base::cur);
break;
}
}