Code:
std::vector<float3> normals; uint32_t numNormals = fileHeader.sectionSizes[2] / 6; // 6 (3 short a 2 bytes) per Vertex for (unsigned int i = 0; i < numNormals; i++) { float3 normal; short x, y, z; inputFile.read(reinterpret_cast<char *>(&x), sizeof(x)); inputFile.read(reinterpret_cast<char *>(&y), sizeof(y)); inputFile.read(reinterpret_cast<char *>(&z), sizeof(z)); x = _byteswap_ushort(x); y = _byteswap_ushort(y); z = _byteswap_ushort(z); normal.x = x / (float)0x8000; normal.y = y / (float)0x8000; normal.z = z / (float)0x8000; outFile << "vn " << normal.x << " " << normal.y << " " << normal.z << std::endl; }
Although _byteswap_ushort is only defined for unsigned shorts it should work for signed shorts as well (kinda checked this with manually swapping the bytes).