Hi, so i have a working script that loads the .obj data (triangulated) from a file into 3 separate vectors (x, y, z) , it all loads correctly and in the right order, however
when i try to draw them, they dont turn out right, not really sure how to explain it
ok, im drawing the data, assuming that it is set in sets of 3, for triangles, but when i use a line strip, i can tell that its just not correct
here is a snippet of code im using to draw it (in opengl)
void mod::draw(int x2, int y2, int z2)
{
glBegin(GL_TRIANGLES); //tried polygons too, but it doesnt help
unsigned int i;
for(i=0; i<x.size();i++)
{
glVertex3f(x2+x,y2+y,z2+z);
}
glEnd();
glLoadIdentity();
}
i've attached some pictures to show how it's messing up, in the pictures, im trying to just draw a cube with 4 faces on each side
thanks, any help/tips on how to draw the .obj file correctly would be much appreciated
Maybe you need to offset your indices by 1? Obj's first element is 1, not 0, so you have to subtract one if you want to index the vertices in an array.
Also you should probably post your whole function, I have no idea what your arrays of data contain.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Maybe you need to offset your indices by 1? Obj's first element is 1, not 0, so you have to subtract one if you want to index the vertices in an array.
Also you should probably post your whole function, I have no idea what your arrays of data contain.
well, dont really want to post the script im using to load the files, needless to say i have three vectors (x,y,z) which, after being loaded, contain exactly what is in the .obj file
class mod {
public:
string debg;
vector<float> x;
vector<float> y;
vector<float> z;
void load(string);
void draw(int,int,int);
};
thats how the class is created, and i've just double checked to make sure everything loaded properly, and it is
not sure what you mean by changing my indicies though? do you mean read from [i-1] in the drawing script or something?
Maybe you need to offset your indices by 1? Obj's first element is 1, not 0, so you have to subtract one if you want to index the vertices in an array.
Also you should probably post your whole function, I have no idea what your arrays of data contain.
well, dont really want to post the script im using to load the files, needless to say i have three vectors (x,y,z) which, after being loaded, contain exactly what is in the .obj file
class mod {
public:
string debg;
vector<float> x;
vector<float> y;
vector<float> z;
void load(string);
void draw(int,int,int);
};
thats how the class is created, and i've just double checked to make sure everything loaded properly, and it is
not sure what you mean by changing my indicies though? do you mean read from [i-1] in the drawing script or something?
I believe he means, if in the object file you have
f 1 2 3
then you're indices for the triangle would be 0 1 2
You'll have to write code that says : draw a triangle out of vertices (1,4,3) and vertices (3,2,1). It's not enough to just iterate through the list of vertices and draw them in order.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
oh, you mean the lines with the f tags? i've done nothing with those at all, couldnt find any decent documentation on them, do i need to use them in order to read it correctly?
im going to try something that might make it work, if the F lines are needed
You'll have to write code that says : draw a triangle out of vertices (1,4,3) and vertices (3,2,1). It's not enough to just iterate through the list of vertices and draw them in order.
oh ok thanks alot! in my file its listed like
f 1/1/1 2/2/1 3/3/1
but i guess that means something like vertex/texture/normals
ok thanks, ill try fix my script with this information