• Advertisement
Sign in to follow this  

am trying to load a model but it's not displaying

This topic is 1905 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:48

mtllib test.mtl

#
# object Box001
#

v -12.6264 0.0000 -58.6877
v -12.6264 0.0000 6.8357
v 43.9557 0.0000 6.8357
v 43.9557 0.0000 -58.6877
v 43.9557 -51.9219 6.8357
v -12.6264 -51.9219 6.8357
v -12.6264 -51.9219 -58.6877
v 43.9557 -51.9219 -58.6877
# 8 vertices

vn 0.0000 1.0000 -0.0000
vn 0.0000 -1.0000 -0.0000
vn 0.0000 0.0000 1.0000
vn 1.0000 0.0000 -0.0000
vn 0.0000 0.0000 -1.0000
vn -1.0000 0.0000 -0.0000
# 6 vertex normals

vt 0.0000 65.5234 0.0000
vt 0.0000 0.0000 0.0000
vt 56.5821 0.0000 0.0000
vt 56.5821 65.5234 0.0000
vt 0.0000 -51.9219 0.0000
vt 56.5821 -51.9219 0.0000
vt 65.5234 0.0000 0.0000
vt 65.5234 -51.9219 0.0000
# 8 texture coords

g Box001
usemtl wire_229154215
s 2
f 1/1/1 2/2/1 3/3/1 4/4/1
s 4
f 5/2/2 6/3/2 7/4/2 8/1/2
s 8
f 3/3/3 2/2/3 6/5/3 5/6/3
s 16
f 4/7/4 3/2/4 5/5/4 8/8/4
s 32
f 1/3/5 4/2/5 8/5/5 7/6/5
s 64
f 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;

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.NormalIndex].X,m.VerticesNormals[m.Faces.NormalIndex].Y,m.VerticesNormals[m.Faces.NormalIndex].Z);
glVertex3f(m.Vertices[m.Faces.VertexIndex].X,m.Vertices[m.Faces.VertexIndex].Y,m.Vertices[m.Faces.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!?

Share this post


Link to post
Share on other sites
Advertisement

  1. What does camera() do? Are you sure you are setting up ModelView and Projection matrices properly.
  2. Can you check in debugger or using debug printout how many quads it adds to your list?
  3. You are setting vertex coordinates twice instead of vertex+normal, but this should not be your problem.

Share this post


Link to post
Share on other sites

  1. What does camera() do? Are you sure you are setting up ModelView and Projection matrices properly.
  2. Can you check in debugger or using debug printout how many quads it adds to your list?
  3. You are setting vertex coordinates twice instead of vertex+normal, but this should not be your problem.


1-
[source lang="cpp"]void camera (void) {
glRotatef(xrot,1.0,0.0,0.0); //rotate our camera on teh x-axis (left and right)
glRotatef(yrot,0.0,1.0,0.0); //rotate our camera on the y-axis (up and down)
glTranslated(-xpos,-ypos,-zpos); //translate the screen to the position of our camera
}[/source]
so I can walk through the whole scene! and yes am setting up ModelView and Projection matrices properly.

2- I can but idk how to do it huh.png

3-fixed it Edited by Mr_PoP

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement