Skip to content
This repository has been archived by the owner on Nov 28, 2019. It is now read-only.

Commit

Permalink
solved jagged 3d model problem, closes #38 and #37
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbekarlsson committed Jan 5, 2018
1 parent 51e5969 commit d217918
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions libninage/src/includes/utils/Model3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Model3D {
std::vector<std::vector<float> > vertexNormals;
std::vector<std::vector<float> > parameterSpaceVertices;
std::vector<std::vector<float> > pologonalFaceElement;
std::vector<std::vector<int> > faces;

void draw();
};
Expand Down
14 changes: 9 additions & 5 deletions libninage/src/utils/Model3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ Model3D::Model3D() {}

void Model3D::draw() {
std::vector<std::vector<float>>::iterator it;
std::vector<std::vector<int>>::iterator faceit;

glPushMatrix();

glDisable(GL_TEXTURE_2D);
glColor3f(255, 255, 255);

glBegin(GL_POLYGON);

for (it = this->vertices.begin(); it != this->vertices.end(); ++it) {
glVertex3f((*it)[0], (*it)[1], (*it)[2]);
for (faceit = this->faces.begin(); faceit != this->faces.end(); ++faceit) {
glBegin(GL_TRIANGLES);
for (int index = 0; index < 3; index++) {
glVertex3f(this->vertices[(*faceit)[index]-1][0], this->vertices[(*faceit)[index]-1][1], this->vertices[(*faceit)[index]-1][2]);
}
glEnd();
}

glEnd();
glPopMatrix();
glEnable(GL_TEXTURE_2D);
}
15 changes: 12 additions & 3 deletions libninage/src/utils/ModelLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,18 @@ Model3D* ModelLoader::load(std::string filepath) {
model->vertexNormals.push_back(vertices);

}
//if(line.find("f ") != std::string::npos) {
// f
//}
if(line.find("f ") != std::string::npos) {
std::istringstream wiss(line);
std::string word;
int c = 0;
std::vector<int> vertices;
while(wiss >> word) {
if (c == 0) { c++; continue; }
vertices.push_back(std::stoi(word));
c++;
}
model->faces.push_back(vertices);
}
}


Expand Down

0 comments on commit d217918

Please sign in to comment.