Mon, 02 Apr 2018 13:21:15 +0300
automatically center the model in the renderer
1315
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
1 | /* |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
1326 | 3 | * Copyright (C) 2013 - 2018 Teemu Piippo |
1315
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
4 | * |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
9 | * |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
14 | * |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
17 | */ |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
18 | |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
19 | #pragma once |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | #include <functional> |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
21 | #include <QVector3D> |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
22 | #include "../basics.h" |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
23 | |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
24 | struct Vertex |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
25 | { |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
26 | qreal x, y, z; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
27 | |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
28 | using ApplyFunction = std::function<void(Axis, double&)>; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
29 | using ApplyConstFunction = std::function<void(Axis, double)>; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
30 | |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
31 | void apply(ApplyFunction func); |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | void apply(ApplyConstFunction func) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
33 | QString toString(bool mangled = false) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
34 | QVector3D toVector() const; |
1324
563a9b65777b
roundToDecimals no longer needs an lvalue. applyToMatrix removed.
Teemu Piippo <teemu@hecknology.net>
parents:
1319
diff
changeset
|
35 | void transform(const class Matrix& matrix, const Vertex& pos); |
1315
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
36 | Vertex transformed(const GLRotationMatrix& matrix) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
37 | void setCoordinate(Axis ax, qreal value); |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
38 | |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | Vertex& operator+=(const QVector3D& other); |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | Vertex operator+(const QVector3D& other) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
41 | QVector3D operator-(const Vertex& other) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
42 | Vertex operator-(const QVector3D& vector) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
43 | Vertex& operator-=(const QVector3D& vector); |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
44 | Vertex& operator*=(qreal scalar); |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
45 | Vertex operator*(qreal scalar) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
46 | bool operator<(const Vertex& other) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
47 | double& operator[](Axis ax); |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
48 | double operator[](Axis ax) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
49 | bool operator==(const Vertex& other) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
50 | bool operator!=(const Vertex& other) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
51 | }; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
52 | |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
53 | inline Vertex operator*(qreal scalar, const Vertex& vertex) |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
54 | { |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
55 | return vertex * scalar; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
56 | } |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
57 | |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | Q_DECLARE_METATYPE(Vertex) |
1371
b8df4748d04e
automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents:
1370
diff
changeset
|
59 | qreal distance(const Vertex& one, const Vertex& other); |
1319 | 60 | unsigned int qHash(const Vertex& key); |
1371
b8df4748d04e
automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents:
1370
diff
changeset
|
61 | Vertex operator-(const Vertex& vertex); |
1315
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
62 | QDataStream& operator<<(QDataStream& out, const Vertex& vertex); |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
63 | QDataStream& operator>>(QDataStream& in, Vertex& vertex); |