Wed, 22 Jan 2020 00:23:29 +0200
at least VAOs work now
3 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
24 | 3 | * Copyright (C) 2013 - 2020 Teemu Piippo |
3 | 4 | * |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | #pragma once | |
20 | #include <functional> | |
21 | #include <QVector3D> | |
22 | #include "basics.h" | |
20 | 23 | #include "maths.h" |
21 | 24 | #include "matrix.h" |
3 | 25 | |
18 | 26 | struct Point3D |
3 | 27 | { |
18 | 28 | double x, y, z; |
29 | using CoordinateType = decltype(x); | |
30 | void assign(Axis axis, CoordinateType value); | |
31 | CoordinateType& get(Axis ax); | |
32 | CoordinateType get(Axis ax) const; | |
20 | 33 | operator QVariant() const; |
3 | 34 | }; |
35 | ||
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
36 | constexpr Point3D origin = {0, 0, 0}; |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
37 | |
18 | 38 | namespace math |
39 | { | |
21 | 40 | Point3D transform(const Point3D& point, const Matrix4x4& matrix); |
18 | 41 | qreal distance(const Point3D& one, const Point3D& other); |
42 | } | |
43 | ||
44 | Point3D& operator+=(Point3D &point, const QVector3D& other); | |
45 | Point3D operator+(Point3D point, const QVector3D& other); | |
46 | QVector3D operator-(const Point3D& point, const Point3D& other); | |
47 | Point3D operator-(Point3D point, const QVector3D& vector); | |
48 | Point3D& operator-=(Point3D &point, const QVector3D& vector); | |
49 | Point3D& operator*=(Point3D &point, Point3D::CoordinateType scalar); | |
50 | Point3D operator*(const Point3D &point, Point3D::CoordinateType scalar); | |
51 | bool operator<(const Point3D &point, const Point3D& other); | |
52 | bool operator==(const Point3D &point, const Point3D& other); | |
53 | bool operator!=(const Point3D &point, const Point3D& other); | |
54 | ||
55 | inline Point3D operator*(qreal scalar, const Point3D& vertex) | |
3 | 56 | { |
57 | return vertex * scalar; | |
58 | } | |
59 | ||
18 | 60 | Q_DECLARE_METATYPE(Point3D) |
61 | Point3D vertexFromVector(const QVector3D& vector); | |
62 | QVector3D vertexToVector(const Point3D &vertex); | |
63 | QString vertexToStringParens(const Point3D& vertex); | |
64 | unsigned int qHash(const Point3D& key); | |
65 | Point3D operator-(const Point3D& vertex); | |
66 | QDataStream& operator<<(QDataStream& out, const Point3D& vertex); | |
67 | QDataStream& operator>>(QDataStream& in, Point3D& vertex); | |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
68 | |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
69 | /* |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
70 | * Calls 'function' with the x, y and z coordinates of 'vertex'. |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
71 | */ |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
72 | template<typename Function> |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
73 | inline auto xyz(Function&& function, const Point3D& vertex) |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
74 | { |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
75 | return function(vertex.x, vertex.y, vertex.z); |
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
76 | } |