diff options
author | Samuel Rødal <sroedal@trolltech.com> | 2008-06-24 14:44:29 +0200 |
---|---|---|
committer | Samuel Rødal <sroedal@trolltech.com> | 2008-06-24 14:45:22 +0200 |
commit | 534a00df0b791111f2e87e84e30fbfed66c3f5e9 (patch) | |
tree | eb5e590b932dcfecdf99539cfbbb9262400e029b | |
parent | 76be46027f110a00bc3f4b6c2d3a2af1b513ff3c (diff) |
Simplify Model input/rendering a bit.
-rw-r--r-- | model.cpp | 32 | ||||
-rw-r--r-- | openglscene.cpp | 2 |
2 files changed, 12 insertions, 22 deletions
@@ -53,25 +53,21 @@ Model::Model(const QString &filename) if (id == "v") { Point3d p; - ts >> p.x >> p.y >> p.z; - m_points << p; - for (int i = 0; i < 3; ++i) { + ts >> p[i]; boundsMin[i] = qMin(boundsMin[i], p[i]); boundsMax[i] = qMax(boundsMax[i], p[i]); } + m_points << p; } else if (id == "f" || id == "fo") { QVarLengthArray<int, 4> p; while (!ts.atEnd()) { QString vertex; ts >> vertex; - - int index; - QTextStream vertexStream(&vertex); - vertexStream >> index; - if (vertexStream.status() == QTextStream::Ok) - p.append(index - 1); + int vertexIndex = vertex.split('/').value(0).toInt(); + if (vertexIndex) + p.append(vertexIndex - 1); } for (int i = 0; i < p.size(); ++i) @@ -123,13 +119,11 @@ void Model::render(bool wireframe, bool normals) const glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); - glShadeModel(GL_SMOOTH); 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); @@ -137,19 +131,15 @@ void Model::render(bool wireframe, bool normals) const glDisable(GL_LIGHT0); glDisable(GL_LIGHTING); } - glDisableClientState(GL_VERTEX_ARRAY); if (normals) { - glColor3f(1, 0, 0); - glBegin(GL_LINES); - for (int i = 0; i < m_normals.size(); ++i) { - Point3d a = m_points.at(i); - Point3d b = m_points.at(i) + m_normals.at(i) * 0.02f; - glVertex3f(a.x, a.y, a.z); - glVertex3f(b.x, b.y, b.z); - } - glEnd(); + QVector<Point3d> normals; + for (int i = 0; i < m_normals.size(); ++i) + normals << m_points.at(i) << (m_points.at(i) + m_normals.at(i) * 0.02f); + glVertexPointer(3, GL_FLOAT, 0, (float *)normals.data()); + glDrawArrays(GL_LINES, 0, normals.size()); } + glDisableClientState(GL_VERTEX_ARRAY); glDisable(GL_DEPTH_TEST); } diff --git a/openglscene.cpp b/openglscene.cpp index 4e45cb1..1c66d9d 100644 --- a/openglscene.cpp +++ b/openglscene.cpp @@ -281,7 +281,7 @@ void OpenGLScene::updateRotation(const QPointF &last, const QPointF ¤t) if (length == 0) { m_angle = 0; } else { - m_angle = -20 * asin(sqrt(length)); + m_angle = -15 * asin(sqrt(length)); m_axis.x /= length; m_axis.y /= length; |