Original Post
Ok here is a dumb questions I have started quickly working on a importer for Milkshape 3D ASCII format files into OpenGL. Yes I am a newbie (been programming for a while but new to OGL) so I have a problem (wouldn''t be writing if I didn''t DAMN should really stop typing to myself) anyway here is the code. Below now everythign works dandy EXCEPT for the NORMALS. Anbybody out there please help. I put everything into arrays for OGL to process. Anybody got any idea why my normals are messing up, the lighting look very weird and I know it''s the normals. Any help would be appreciated.
Last Bastardo
-= Find me a word that rhymes with orange ? =-
// This reads a string from a file
void readstr(FILE *f,char *string)
{
do { fgets(string, 255, f); } while ((string[0] == ''/'') || (string[0] == ''\n''));
return;
}
// This is the defenition for a mesh
typedef struct Mesh_t
{
GLfloat *tlist, *vlist, *nlist, *normals;
int *plist, *nindex;
Mesh_t::~Mesh_t() { delete vlist, plist, tlist, nlist, nindex, normals; }
} Mesh_t;
// This is the model class
class Model_t
{
private:
GLfloat x, y, z, u, v;
int tmp, i, flags, bone_id, pcount, vcount, nx, ny, nz, v1, v2, v3;;
public:
FILE *file;
char line[255];
Mesh_t *meshes;
int num_meshes;
int num_verts, num_polys, num_normals;
void Model_t::Open(char *path)
{
file = fopen(path, "rt");
}
Model_t::~Model_t()
{
fclose(file);
}
void Model_t:
arse()
{
// This locates the number of meshes
while (num_meshes == 0) { readstr(file,line); sscanf(line, "Meshes: %d", #_meshes); }
meshes = new Mesh_t[num_meshes];
pcount = 0;
vcount = 0;
for (i = 0; i < num_meshes; i++)
{
// This locates the number of verticies
while (num_verts == 0) { readstr(file,line); sscanf(line, " %d", #_verts); }
meshes.vlist = new GLfloat[num_verts * 3];
meshes[i].tlist = new GLfloat[num_verts * 2];
for (vcount = 0; vcount < num_verts; vcount++)
{
readstr(file,line);
sscanf(line, " %d %f %f %f %f %f %d ", &flags, &x, &y, &z, &u, &v, &bone_id);
meshes[i].vlist[(vcount*3)] = x;
meshes[i].vlist[(vcount*3) + 1] = y;
meshes[i].vlist[(vcount*3) + 2] = z;
meshes[i].tlist[(vcount*2)] = u;
meshes[i].tlist[(vcount*2) + 1] = v;
}
readstr(file,line); sscanf(line, "%d", #_normals);
meshes[i].nlist = new GLfloat[num_normals * 3];
for (vcount = 0; vcount < num_normals; vcount++)
{
readstr(file,line);
sscanf(line, " %f %f %f", &x, &y, &z);
meshes[i].nlist[(vcount*3)] = x;
meshes[i].nlist[(vcount*3) + 1] = y;
meshes[i].nlist[(vcount*3) + 2] = z;
}
readstr(file,line);
sscanf(line, "%d", #_polys);
meshes[i].plist = new GLint[num_polys * 3];
meshes[i].nindex = new GLint[num_polys * 3];
meshes[i].normals = new GLfloat[num_verts * 3];
for (vcount = 0; vcount < num_polys; vcount++)
{
readstr(file,line);
sscanf(line, "%f %d %d %d %d %d %d", &flags, &v1, &v2, &v3, &nx, &ny, &nz);
meshes[i].plist[(vcount*3)] = v1;
meshes[i].plist[(vcount*3) + 1] = v2;
meshes[i].plist[(vcount*3) + 2] = v3;
meshes[i].nindex[(vcount*3)] = nx;
meshes[i].nindex[(vcount*3) + 1] = ny;
meshes[i].nindex[(vcount*3) + 2] = nz;
printf("%d %d %d\n", v1, v2, v3);
meshes[i].normals[(v1*3)] = meshes[i].nlist[(v1*3)];
meshes[i].normals[(v1*3) + 1] = meshes[i].nlist[(v1*3) + 1];
meshes[i].normals[(v1*3) + 2] = meshes[i].nlist[(v1*3) + 2];
meshes[i].normals[(v2*3)] = meshes[i].nlist[(v2*3)];
meshes[i].normals[(v2*3) + 1] = meshes[i].nlist[(v2*3)+1];
meshes[i].normals[(v2*3) + 2] = meshes[i].nlist[(v2*3)+2];
meshes[i].normals[(v3*3)] = meshes[i].nlist[(v3*3)];
meshes[i].normals[(v3*3) + 1] = meshes[i].nlist[(v3*3) + 1];
meshes[i].normals[(v3*3) + 2] = meshes[i].nlist[(v3*3) + 2];
}
}
}
};