diff options
author | Samuel Rødal <sroedal@trolltech.com> | 2008-12-12 13:54:58 +0100 |
---|---|---|
committer | Samuel Rødal <sroedal@trolltech.com> | 2008-12-12 13:54:58 +0100 |
commit | b2d3f3990bc7b949259da4270659adc9be580fcd (patch) | |
tree | 24544a192c1cabf344cfe1cdf473dfe60b96c809 /model.cpp | |
parent | 48bbfd7f61088c85fe8bdb58d16729edc4c8b107 (diff) |
Speed up QPainter model rendering a bit, and prevent clipping bugs when transforming wireframe lines.
Diffstat (limited to 'model.cpp')
-rw-r--r-- | model.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
@@ -161,16 +161,29 @@ void Model::render(bool wireframe, bool normals) const void Model::render(QPainter *painter, const Matrix4x4 &matrix, bool normals) const { - QVector<QLineF> lines; - for (int i = 0; i < m_edgeIndices.size(); i += 2) - lines << QLineF((matrix * m_points.at(m_edgeIndices.at(i))).toQPoint(), - (matrix * m_points.at(m_edgeIndices.at(i+1))).toQPoint()); + m_mapped.resize(m_points.size()); + for (int i = 0; i < m_points.size(); ++i) + m_mapped[i] = matrix * m_points.at(i); + + m_lines.clear(); + for (int i = 0; i < m_edgeIndices.size(); i += 2) { + const Point3d a = m_mapped.at(m_edgeIndices.at(i)); + const Point3d b = m_mapped.at(m_edgeIndices.at(i+1)); + + if (a.z > 0 && b.z > 0) + m_lines << QLineF(a.toQPoint(), b.toQPoint()); + } if (normals) { - for (int i = 0; i < m_normals.size(); ++i) - lines << QLineF((matrix * m_points.at(i)).toQPoint(), - (matrix * (m_points.at(i) + m_normals.at(i) * 0.02f)).toQPoint()); + for (int i = 0; i < m_normals.size(); ++i) { + const Point3d a = m_mapped.at(i); + const Point3d b = matrix * (m_points.at(i) + m_normals.at(i) * 0.02f); + + if (a.z > 0 && b.z > 0) + m_lines << QLineF(a.toQPoint(), b.toQPoint()); + } } - painter->drawLines(lines); + painter->setRenderHint(QPainter::Antialiasing, false); + painter->drawLines(m_lines); } |