am trying to load an obj model :
[source lang="plain"]# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware# File Created: 05.11.2012 20:07:48mtllib test.mtl## object Box001#v -12.6264 0.0000 -58.6877v -12.6264 0.0000 6.8357v 43.9557 0.0000 6.8357v 43.9557 0.0000 -58.6877v 43.9557 -51.9219 6.8357v -12.6264 -51.9219 6.8357v -12.6264 -51.9219 -58.6877v 43.9557 -51.9219 -58.6877# 8 verticesvn 0.0000 1.0000 -0.0000vn 0.0000 -1.0000 -0.0000vn 0.0000 0.0000 1.0000vn 1.0000 0.0000 -0.0000vn 0.0000 0.0000 -1.0000vn -1.0000 0.0000 -0.0000# 6 vertex normalsvt 0.0000 65.5234 0.0000vt 0.0000 0.0000 0.0000vt 56.5821 0.0000 0.0000vt 56.5821 65.5234 0.0000vt 0.0000 -51.9219 0.0000vt 56.5821 -51.9219 0.0000vt 65.5234 0.0000 0.0000vt 65.5234 -51.9219 0.0000# 8 texture coordsg Box001usemtl wire_229154215s 2f 1/1/1 2/2/1 3/3/1 4/4/1 s 4f 5/2/2 6/3/2 7/4/2 8/1/2 s 8f 3/3/3 2/2/3 6/5/3 5/6/3 s 16f 4/7/4 3/2/4 5/5/4 8/8/4 s 32f 1/3/5 4/2/5 8/5/5 7/6/5 s 64f 2/7/6 1/2/6 7/5/6 6/8/6 # 6 polygons[/source]
I have a class called Model :
[source lang="cpp"]#ifndef _Model_H_#define _Model_H_#include <vector>struct Coordinate{ float X,Y,Z; Coordinate(float x,float y,float z);};struct TextureCoordinate{ float U,V; TextureCoordinate(float u,float v);};struct Face{ int VertexIndex,TextureIndex,NormalIndex; Face(int vi, int ti, int ni);};class Model{public: Model(void); ~Model(void); bool IsTriangle; std::string Name; std::vector<Coordinate> Vertices; std::vector<Coordinate> VerticesNormals; std::vector<Coordinate> VerticesTexture; std::vector<Face > Faces; int ModelNumber;};#endif[/source]
and am trying to load it like this :-
[source lang="cpp"]Model ModelsLoader::LoadModel(const char * ModelName){ std::ifstream fs(ModelName); char temp[256]; std::string * line; Model m; float tempX,tempY,tempZ; int tempA1,tempA2,tempA3,tempA4; if(fs.is_open()){ while (!fs.eof()) { fs.getline(temp,256); Lines.push_back(new std::string(temp)); } int c,slashes; for (int i = 0; i < Lines.size(); i++) { line = Lines[i]; if(line->size() == 0 ||(*line)[0] == '#' ) continue; else if((*line)[0] == 'v' && (*line)[1] == ' ') { sscanf(line->c_str(),"v %f %f %f",&tempX,&tempY,&tempZ); m.Vertices.push_back( Coordinate(tempX,tempY,tempZ)); } else if((*line)[0] == 'v' && (*line)[1] == 't'){ sscanf(line->c_str(),"vn %f %f %f",&tempX,&tempY,&tempZ); m.VerticesTexture.push_back( Coordinate(tempX,tempY,tempZ)); } else if((*line)[0] == 'v' && (*line)[1] == 'n'){ sscanf(line->c_str(),"vn %f %f %f",&tempX,&tempY,&tempZ); m.VerticesNormals.push_back( Coordinate(tempX,tempY,tempZ)); } else if((*line)[0] == 'f' && (*line)[1] == ' ') { c = std::count(line->begin(),line->end(),' ') - 1; slashes = std::count(line->begin(),line->end(),'/'); if( slashes / c == 2){ int i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12; sscanf(line->c_str(),"f %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d",&i1,&i2,&i3,&i4,&i5,&i6,&i7,&i8,&i9,&i10,&i11,&i12); m.Faces.push_back(Face(i1-1,i2-1,i3-1)); m.Faces.push_back(Face(i4-1,i5-1,i6-1)); m.Faces.push_back(Face(i7-1,i8-1,i9-1)); m.Faces.push_back(Face(i10-1,i11-1,i12-1)); m.IsTriangle = false; } else if (slashes / c == 3) { int i1,i2,i3,i4,i5,i6,i7,i8,i9; sscanf(line->c_str(),"f %d/%d/%d %d/%d/%d %d/%d/%d",&i1,&i2,&i3,&i4,&i5,&i6,&i7,&i8,&i9); m.Faces.push_back(Face(i1-1,i2-1,i3-1)); m.Faces.push_back(Face(i4-1,i5-1,i6-1)); m.Faces.push_back(Face(i7-1,i8-1,i9-1)); m.IsTriangle = true; } } } fs.close(); m.ModelNumber = glGenLists(1); glNewList(m.ModelNumber, GL_COMPILE); for (int i = 0; i < m.Faces.size(); i++) { if(m.IsTriangle){ } else { glBegin(GL_QUADS); for (int i = 0; i < m.Faces.size(); i++) { glVertex3f(m.VerticesNormals[m.Faces[i].NormalIndex].X,m.VerticesNormals[m.Faces[i].NormalIndex].Y,m.VerticesNormals[m.Faces[i].NormalIndex].Z); glVertex3f(m.Vertices[m.Faces[i].VertexIndex].X,m.Vertices[m.Faces[i].VertexIndex].Y,m.Vertices[m.Faces[i].VertexIndex].Z); } glEnd(); } } glEndList(); } Clear(); return m;}[/source]
now when I call the list it's not showing anything:-
[source lang="cpp"]void drawScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective glLoadIdentity(); //Reset the drawing perspective camera(); glCallList(model.ModelNumber); glutSwapBuffers(); //Send the 3D scene to the screen}[/source]
what am doing worng here!?
Mr_PoP
Member Since 20 May 2011Offline Last Active Nov 09 2012 12:06 PM

Find content
Not Telling