src/vertex.cpp

Wed, 22 Jan 2020 01:17:11 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 22 Jan 2020 01:17:11 +0200
changeset 27
c57fb7a5ffa3
parent 24
1a0faaaceb84
permissions
-rw-r--r--

commit work done on plugging vao to the gl renderer, renders nonsense for 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: 21
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
24
1a0faaaceb84 added license
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
8 * (at your option) any later version.
3
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 #include "main.h"
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 #include "vertex.h"
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 /*
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 void Vertex::transform(const Matrix& matrix, const Vertex& pos)
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 double x2 = (matrix(0, 0) * x) + (matrix(0, 1) * y) + (matrix(0, 2) * z) + pos.x;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 double y2 = (matrix(1, 0) * x) + (matrix(1, 1) * y) + (matrix(1, 2) * z) + pos.y;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 double z2 = (matrix(2, 0) * x) + (matrix(2, 1) * y) + (matrix(2, 2) * z) + pos.z;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 this->x = x2;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 this->y = y2;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 this->z = z2;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 */
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
34 Point3D::CoordinateType& Point3D::get(Axis axis)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 switch (axis)
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 case X:
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 return this->x;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 case Y:
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 return this->y;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 case Z:
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 return this->z;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 default:
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 throw std::runtime_error("Non-axis given to Vertex::operator[]");
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
49 Point3D::CoordinateType Point3D::get(Axis axis) const
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 switch (axis)
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 case X:
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 return this->x;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 case Y:
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56 return this->y;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 case Z:
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 return this->z;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 default:
5
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
60 return 0;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63
20
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
64 Point3D::operator QVariant() const
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
65 {
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
66 return QVariant::fromValue(*this);
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
67 }
cef43609a374 fixed build
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
68
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
69 void Point3D::assign(Axis axis, CoordinateType value)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
70 {
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
71 this->get(axis) = value;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
72 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
74 Point3D VertexFromVector(const QVector3D& vector)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
75 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
76 return {vector.x(), vector.y(), vector.z()};
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
77 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
78
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
79 Point3D operator*(const Point3D& point, Point3D::CoordinateType scalar)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
80 {
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
81 return {point.x * scalar, point.y * scalar, point.z * scalar};
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
82 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
83
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
84 Point3D& operator+=(Point3D& point, const QVector3D& other)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
85 {
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
86 point.x += other.x();
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
87 point.y += other.y();
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
88 point.z += other.z();
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
89 return point;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
90 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
91
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
92 Point3D operator+(Point3D point, const QVector3D& other)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
93 {
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
94 point += other;
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
95 return point;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
96 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
97
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
98
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
99 QVector3D vertexToVector(const Point3D& vertex)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
100 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
101 return {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
102 static_cast<float>(vertex.x),
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
103 static_cast<float>(vertex.y),
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
104 static_cast<float>(vertex.z)
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
105 };
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
106 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
107
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
108 Point3D operator-(Point3D point, const QVector3D& vector)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
109 {
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
110 point -= vector;
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
111 return point;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
112 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
113
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
114 Point3D& operator-=(Point3D& point, const QVector3D& vector)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
115 {
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
116 point.x -= vector.x();
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
117 point.y -= vector.y();
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
118 point.z -= vector.z();
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
119 return point;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
120 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
121
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
122 QVector3D operator-(const Point3D& point, const Point3D& other)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
123 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
124 return {
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
125 static_cast<float>(point.x - other.x),
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
126 static_cast<float>(point.y - other.y),
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
127 static_cast<float>(point.z - other.z)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
128 };
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
129 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
130
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
131 Point3D& operator*=(Point3D& point, Point3D::CoordinateType scalar)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
132 {
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
133 point.x *= scalar;
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
134 point.y *= scalar;
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
135 point.z *= scalar;
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
136 return point;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
137 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
138
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
139 bool operator==(const Point3D& point, const Point3D& other)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
140 {
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
141 return point.x == other.x and point.y == other.y and point.z == other.z;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
142 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
143
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
144 bool operator!=(const Point3D& point, const Point3D& other)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
145 {
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
146 return not (point == other);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
147 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
148
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
149 bool operator<(const Point3D& point, const Point3D& other)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
150 {
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
151 if (not qFuzzyCompare(point.x, other.x))
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
152 return point.x < other.x;
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
153 else if (not qFuzzyCompare(point.y, other.y))
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
154 return point.y < other.y;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
155 else
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
156 return point.z < other.z;
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
157 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
158
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
159 /*
21
Teemu Piippo <teemu@hecknology.net>
parents: 20
diff changeset
160 * Transforms the specified vertex with a transformation matrix
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
161 */
21
Teemu Piippo <teemu@hecknology.net>
parents: 20
diff changeset
162 Point3D math::transform(const Point3D& point, const Matrix4x4& matrix)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
163 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
164 return {
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
165 matrix(0, 0) * point.x
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
166 + matrix(0, 1) * point.y
21
Teemu Piippo <teemu@hecknology.net>
parents: 20
diff changeset
167 + matrix(0, 2) * point.z
Teemu Piippo <teemu@hecknology.net>
parents: 20
diff changeset
168 + matrix(0, 3),
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
169 matrix(1, 0) * point.x
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
170 + matrix(1, 1) * point.y
21
Teemu Piippo <teemu@hecknology.net>
parents: 20
diff changeset
171 + matrix(1, 2) * point.z
Teemu Piippo <teemu@hecknology.net>
parents: 20
diff changeset
172 + matrix(1, 3),
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
173 matrix(2, 0) * point.x
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
174 + matrix(2, 1) * point.y
21
Teemu Piippo <teemu@hecknology.net>
parents: 20
diff changeset
175 + matrix(2, 2) * point.z
Teemu Piippo <teemu@hecknology.net>
parents: 20
diff changeset
176 + matrix(2, 3),
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
177 };
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
178 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
179
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
180 /*
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
181 * Returns the distance from one vertex to another.
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
182 */
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
183 qreal math::distance(const Point3D& one, const Point3D& other)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
184 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
185 return (one - other).length();
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
186 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
187
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
188 /*
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
189 * Returns a vertex with all coordinates inverted.
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
190 */
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
191 Point3D operator-(const Point3D& vertex)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
192 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
193 return {-vertex.x, -vertex.y, -vertex.z};
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
194 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
195
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
196 /*
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
197 * Inserts this vertex into a data stream. This is needed for vertices to be
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
198 * stored in QSettings.
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
199 */
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
200 QDataStream& operator<<(QDataStream& out, const Point3D& vertex)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
201 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
202 return out << vertex.x << vertex.y << vertex.z;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
203 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
204
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
205 /*
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
206 * Takes a vertex from a data stream.
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
207 */
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
208 QDataStream& operator>>(QDataStream& in, Point3D& vertex)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
209 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
210 return in >> vertex.x >> vertex.y >> vertex.z;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
211 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
212
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
213 unsigned int qHash(const Point3D& key)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
214 {
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
215 return qHash(key.x) ^ utility::rotl10(qHash(key.y)) ^ utility::rotl20(qHash(key.z));
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
216 }
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
217
18
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
218 QString vertexToStringParens(const Point3D& vertex)
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
219 {
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
220 return utility::format("(%1, %2, %3)", vertex.x, vertex.y, vertex.z);
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 5
diff changeset
221 }

mercurial