void Mesh::removeColumn(int columnId) { // Cannot remove first and last columns Q_ASSERT(columnId >= 1 && columnId < nColumns()-1); // Temporary containers that will be used to rebuild new vertex space. IndexVector2d newVertices2d; resizeVertices2d(newVertices2d, nColumns()-1, nRows()); QVector<QPointF> newVertices(vertices.size()-nRows()); // Right displacement of points already there. qreal rightMoveProp = 1.0f/(nColumns()-2) - 1.0f/(nColumns()-1); // Process all rows. int k = 0; for (int y=0; y<nRows(); y++) { // Get left and right vertices. QPointF left = getVertex2d( 0, y ); QPointF right = getVertex2d( nColumns()-1, y ); QPointF diff = right - left; // Move all columns. for (int x=0; x<nColumns(); x++) { // Ignore points from target column. if (x == columnId) continue; // Get current vertex. QPointF p = getVertex2d( x, y ); // The x value of this point in the new space. int newX = x < columnId ? x : x-1; // Move middle points. if (x > 0 && x < nColumns()-1) { p += (x < columnId ? +1 : -1) * diff * newX * rightMoveProp; } // Assign new containers. newVertices[k] = p; newVertices2d[newX][y] = k; k++; } } // Copy new mapping. vertices = newVertices; _vertices2d = newVertices2d; // Decrement number of columns. _nColumns--; // Reorder. _reorderVertices(); }
void Mesh::removeRow(int rowId) { // Cannot remove first and last columns Q_ASSERT(rowId >= 1 && rowId < nRows()-1); // Temporary containers that will be used to rebuild new vertex space. IndexVector2d newVertices2d; resizeVertices2d(newVertices2d, nColumns(), nRows()-1); QVector<QPointF> newVertices(vertices.size()-nColumns()); // Bottom displacement of points already there. qreal bottomMoveProp = 1.0f/(nRows()-2) - 1.0f/(nRows()-1); // Process all columns. int k = 0; for (int x=0; x<nColumns(); x++) { // Get top and bottom vertices. QPointF top = getVertex2d(x, 0); QPointF bottom = getVertex2d(x, nRows()-1); QPointF diff = bottom - top; // Move all rows. for (int y=0; y<nRows(); y++) { // Ignore points from target row. if (y == rowId) continue; // Get current vertex. QPointF p = getVertex2d( x, y ); // The y value of this point in the new space. int newY = y < rowId ? y : y-1; // Move middle points. if (y > 0 && y < nRows()-1) { p += (y < rowId ? +1 : -1) * diff * newY * bottomMoveProp; } // Assign new containers. newVertices[k] = p; newVertices2d[x][newY] = k; k++; } } // Copy new mapping. vertices = newVertices; _vertices2d = newVertices2d; // Decrement number of rows. _nRows--; // Reorder. _reorderVertices(); }
void Mesh::_reorderVertices() { // Populate new vertices vector. QVector<QPointF> newVertices(vertices.size()); int k = 0; for (int y=0; y<nRows(); y++) for (int x=0; x<nColumns(); x++) newVertices[k++] = getVertex2d( x, y ); // Populate _vertices2d. k = 0; for (int y=0; y<nRows(); y++) for (int x=0; x<nColumns(); x++) _vertices2d[x][y] = k++; // Copy. vertices = newVertices; }
void Rasterizer::ProcessVertices(const vector<Vertex> & vertices, const vector<unsigned short> & indices, const Matrix4x4 & worldMat, bool fill) { _texMap = fill; vector<Vertex> newVertices(vertices); Matrix4x4 worldMatrix; worldMatrix.SetMatrix(worldMat); for ( unsigned int i = 0; i < newVertices.size(); i++) { worldMatrix.Transformation(newVertices, i); } assert((indices.size()%3)==0); int index = (indices.size())/3; int j = 0; for ( int i = 0; i < index; i++) { vector<Vertex> verts; verts.push_back(Vertex(newVertices[indices[j]]._x, newVertices[indices[j]]._y, newVertices[indices[j]]._z, newVertices[indices[j]]._u, newVertices[indices[j]]._v)); verts.push_back(Vertex(newVertices[indices[j+1]]._x, newVertices[indices[j+1]]._y, newVertices[indices[j+1]]._z, newVertices[indices[j+1]]._u, newVertices[indices[j+1]]._v)); verts.push_back(Vertex(newVertices[indices[j+2]]._x, newVertices[indices[j+2]]._y, newVertices[indices[j+2]]._z, newVertices[indices[j+2]]._u, newVertices[indices[j+2]]._v)); NPolygon poly(verts, 3); if (CullCheck(poly)) { DrawPolygon(poly); } j += 3; } }