Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/3dview/gridmesh.cpp
Show All 15 Lines | 1 | /* Atelier KDE Printer Host for 3D Printing | |||
---|---|---|---|---|---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | GNU General Public License for more details. | 17 | GNU General Public License for more details. | ||
18 | 18 | | |||
19 | You should have received a copy of the GNU General Public License | 19 | You should have received a copy of the GNU General Public License | ||
20 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #include <QGeometryRenderer> | 23 | #include <QGeometryRenderer> | ||
24 | #include <QSize> | ||||
24 | #include <QVector3D> | 25 | #include <QVector3D> | ||
25 | #include <QVector2D> | | |||
26 | #include "gridmesh.h" | 26 | #include "gridmesh.h" | ||
27 | #include "linemeshgeometry.h" | 27 | #include "linemeshgeometry.h" | ||
28 | 28 | | |||
29 | GridMesh::GridMesh(Qt3DCore::QNode *parent) : Qt3DRender::QGeometryRenderer(parent) | 29 | GridMesh::GridMesh(Qt3DCore::QNode *parent) : Qt3DRender::QGeometryRenderer(parent) | ||
30 | { | 30 | { | ||
31 | setInstanceCount(1); | 31 | setInstanceCount(1); | ||
32 | setIndexOffset(0); | 32 | setIndexOffset(0); | ||
33 | setFirstInstance(0); | 33 | setFirstInstance(0); | ||
34 | setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines); | 34 | setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines); | ||
35 | 35 | | |||
36 | QVector2D s(20, 20); | 36 | QSize meshResolution(20, 20); | ||
37 | QVector<QVector3D> vertices; | 37 | QVector<QVector3D> vertices; | ||
38 | for (uint i = 0; i <= s.x(); i++) { | 38 | | ||
39 | for (uint j = 0; j <= s.y(); j++) { | 39 | for (int x = 0; x <= meshResolution.width(); x++) { | ||
40 | vertices.append(QVector3D(i, 0, 0)); | 40 | vertices.append(QVector3D(x, 0, 0)); | ||
41 | vertices.append(QVector3D(i, j, 0)); | 41 | vertices.append(QVector3D(x, meshResolution.width(), 0)); | ||
42 | vertices.append(QVector3D(0, j, 0)); | | |||
43 | vertices.append(QVector3D(i, j, 0)); | | |||
44 | } | 42 | } | ||
43 | | ||||
44 | for (int y = 0; y <= meshResolution.height(); y++) { | ||||
45 | vertices.append(QVector3D(0, y, 0)); | ||||
46 | vertices.append(QVector3D(meshResolution.height(), y, 0)); | ||||
45 | } | 47 | } | ||
46 | 48 | | |||
47 | auto geometry = new LineMeshGeometry(vertices, this); | 49 | auto geometry = new LineMeshGeometry(vertices, this); | ||
48 | setVertexCount(geometry->vertexCount()); | 50 | setVertexCount(geometry->vertexCount()); | ||
49 | setGeometry(geometry); | 51 | setGeometry(geometry); | ||
50 | } | 52 | } | ||
51 | 53 | | |||
52 | GridMesh::~GridMesh() | 54 | GridMesh::~GridMesh() | ||
53 | { | 55 | { | ||
54 | } | 56 | } |