src/vertex.h

Wed, 22 Jan 2020 00:23:29 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 22 Jan 2020 00:23:29 +0200
changeset 26
3a9e761e4faa
parent 24
1a0faaaceb84
permissions
-rw-r--r--

at least VAOs work now

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

mercurial