From eded602ef90eacb1732d07a9f72dbb6a16100d0a Mon Sep 17 00:00:00 2001 From: Tats Date: Fri, 4 Apr 2014 00:54:17 -0400 Subject: [PATCH] Fixed bug: texture meshes points were not loaded in the right order --- Shape.cpp | 63 ++++++++++++++++++++++++++++++++++--------------------- Shape.h | 17 +++++++++------ 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/Shape.cpp b/Shape.cpp index 53ba1b0..3dccdbb 100644 --- a/Shape.cpp +++ b/Shape.cpp @@ -93,19 +93,34 @@ QPolygonF Polygon::toPolygon() const return polygon; } -Mesh::Mesh(QPointF p1, QPointF p2, QPointF p3, QPointF p4, int nColumns, int nRows) -: Quad(p1, p2, p3, p4), _nColumns(0), _nRows(0) +Mesh::Mesh() : Quad(), _nColumns(0), _nRows(0) {} + +Mesh::Mesh(QPointF p1, QPointF p2, QPointF p3, QPointF p4) : Quad() { - Q_ASSERT(nColumns >= 2 && nRows >= 2); - init(nColumns, nRows); + // Add points in standard order. + QVector points; + points.push_back(p1); + points.push_back(p2); + points.push_back(p4); + points.push_back(p3); + + // Init. + init(points, 2, 2); } -Mesh::Mesh(const QVector& points, int nColumns, int nRows) -: Quad(), _nColumns(nColumns), _nRows(nRows) +Mesh::Mesh(const QVector& points, int nColumns, int nRows) : Quad() +{ + init(points, nColumns, nRows); +} + +void Mesh::init(const QVector& points, int nColumns, int nRows) { Q_ASSERT(nColumns >= 2 && nRows >= 2); Q_ASSERT(points.size() == nColumns * nRows); + _nColumns = nColumns; + _nRows = nRows; + // Resize the vertices2d vector to appropriate dimensions. resizeVertices2d(_vertices2d, _nColumns, _nRows); @@ -143,24 +158,24 @@ void Mesh::resizeVertices2d(IndexVector2d& vertices2d, int nColumns, int nRows) vertices2d[i].resize(nRows); } -void Mesh::init(int nColumns, int nRows) -{ - // Create vertices correspondence of bouding quad. - resizeVertices2d(_vertices2d, 2, 2); - _vertices2d[0][0] = 0; - _vertices2d[1][0] = 1; - _vertices2d[1][1] = 2; - _vertices2d[0][1] = 3; - - // Init number of columns and rows. - _nColumns = _nRows = 2; - - // Add extra columns and rows. - for (int i=0; i > IndexVector2d; public: - Mesh() : _nColumns(0), _nRows(0) { - init(1, 1); - } - Mesh(QPointF p1, QPointF p2, QPointF p3, QPointF p4, int nColumns=2, int nRows=2); + Mesh(); + + // This constructor creates a quad mesh (four corners) using the same order as for the quad + // constructor (ie. clockwise). + Mesh(QPointF p1, QPointF p2, QPointF p3, QPointF p4); + + // Standard mesh constructor. Mesh(const QVector& points, int nColumns, int nRows); + virtual ~Mesh() {} + // Performs the actual adding of points (used for loading). + void init(const QVector& points, int nColumns, int nRows); + virtual QString getType() const { return "mesh"; } virtual QPolygonF toPolygon() const; @@ -192,8 +199,6 @@ public: void resizeVertices2d(IndexVector2d& vertices2d, int nColumns, int nRows); - void init(int nColumns, int nRows); - // void addColumn(); void addRow();