diff options
author | Samuel Rødal <sroedal@trolltech.com> | 2008-06-23 11:50:31 +0200 |
---|---|---|
committer | Samuel Rødal <sroedal@trolltech.com> | 2008-06-23 11:50:31 +0200 |
commit | 00b14be3b68b9e2970f2382235ca3273b5499ef5 (patch) | |
tree | 35bd141c210122f956f8b055d54dffedf8722f99 | |
parent | d33e1a6025e80df963745592dbbc5eb53d6ce63f (diff) |
Some small cleanups.
-rw-r--r-- | model.cpp | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -16,6 +16,9 @@ static Point3d readPoint(QTextStream &ts) struct Edge { + Edge() : pointA(0), pointB(0) {} + Edge(int pa, int pb) : pointA(pa), pointB(pb) {} + int pointA; int pointB; }; @@ -37,6 +40,7 @@ Model::Model(const QString &filename) if (!file.open(QIODevice::ReadOnly)) return; + // use a set to avoid duplicate edges QSet<Edge> edges; Point3d min( 1e9, 1e9, 1e9); @@ -49,6 +53,7 @@ Model::Model(const QString &filename) while (!in.atEnd()) { QString input = in.readLine(); + // empty or comment? if (input.isEmpty() || input[0] == '#') continue; @@ -83,10 +88,8 @@ Model::Model(const QString &filename) p.append(index - 1); } - for (int i = 0; i < p.size(); ++i) { - Edge edge = { p[i], p[(i + 1) % p.size()] }; - edges << edge; - } + for (int i = 0; i < p.size(); ++i) + edges << Edge(p[i], p[(i + 1) % p.size()]); for (int i = 0; i < 3; ++i) m_pointIndices << p[i]; @@ -146,22 +149,18 @@ void Model::render(bool wireframe, bool normals) const glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); + glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); - glEnable(GL_DEPTH_TEST); - glEnableClientState(GL_NORMAL_ARRAY); - glVertexPointer(3, GL_FLOAT, 0, (float *)m_points.data()); glNormalPointer(GL_FLOAT, 0, (float *)m_normals.data()); glDrawElements(GL_TRIANGLES, m_pointIndices.size(), GL_UNSIGNED_INT, m_pointIndices.data()); glDisableClientState(GL_NORMAL_ARRAY); - glDisable(GL_DEPTH_TEST); - glDisable(GL_COLOR_MATERIAL); glDisable(GL_LIGHT0); glDisable(GL_LIGHTING); |