Sun, 17 Jun 2018 13:53:33 +0300
replaced the Matrix class with QMatrix4x4
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; |
1403
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1390
diff
changeset
|
35 | void transform(const QMatrix4x4& matrix); |
7a2d84112983
replaced the Matrix class with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents:
1390
diff
changeset
|
36 | void rotate(const QQuaternion& orientation); |
1315
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
37 | Vertex transformed(const GLRotationMatrix& matrix) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
38 | void setCoordinate(Axis ax, qreal value); |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | Vertex& operator+=(const QVector3D& other); |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
41 | Vertex operator+(const QVector3D& other) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
42 | QVector3D operator-(const Vertex& other) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
43 | Vertex operator-(const QVector3D& vector) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
44 | Vertex& operator-=(const QVector3D& vector); |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
45 | Vertex& operator*=(qreal scalar); |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
46 | Vertex operator*(qreal scalar) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
47 | bool operator<(const Vertex& other) const; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
48 | double& operator[](Axis ax); |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
49 | double operator[](Axis ax) 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 | bool operator!=(const Vertex& other) const; |
1390
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1371
diff
changeset
|
52 | |
3eace926af7f
added draw plane feature (doesn't work with circle draw quite right yet)
Teemu Piippo <teemu@hecknology.net>
parents:
1371
diff
changeset
|
53 | static Vertex fromVector(const QVector3D& vector); |
1315
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 | |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
56 | 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
|
57 | { |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
58 | return vertex * scalar; |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
59 | } |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
60 | |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
61 | Q_DECLARE_METATYPE(Vertex) |
1371
b8df4748d04e
automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents:
1370
diff
changeset
|
62 | qreal distance(const Vertex& one, const Vertex& other); |
1319 | 63 | unsigned int qHash(const Vertex& key); |
1371
b8df4748d04e
automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents:
1370
diff
changeset
|
64 | Vertex operator-(const Vertex& vertex); |
1315
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
65 | QDataStream& operator<<(QDataStream& out, const Vertex& vertex); |
23d48a709ffc
moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
66 | QDataStream& operator>>(QDataStream& in, Vertex& vertex); |