Mon, 20 Jun 2022 21:14:27 +0300
removed some newlines
154 | 1 | #pragma once |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
2 | #include "basics.h" |
200 | 3 | #include "model.h" |
154 | 4 | |
5 | namespace ldraw | |
6 | { | |
7 | /// Determines how quadrilaterals are split into triangles | |
8 | enum class Diagonal | |
9 | { | |
10 | Diagonal_13, | |
11 | Diagonal_24 | |
12 | }; | |
13 | ||
200 | 14 | std::pair<Triangle, Triangle> splitTriangles( |
15 | const Quadrilateral& q, | |
16 | ldraw::Diagonal diagonal); | |
154 | 17 | |
200 | 18 | /* |
154 | 19 | void makeUnofficial(ModelEditor &editor); |
200 | 20 | */ |
186 | 21 | |
232
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
22 | constexpr float circleAngle(int divisions, int i) |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
23 | { |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
24 | constexpr float ofs = 0.5 * pi<>; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
25 | float factor = -2.0f * pi<> / divisions; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
26 | return i * factor + ofs; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
27 | } |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
28 | |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
29 | constexpr glm::vec2 rimpoint(int divisions, int i) |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
30 | { |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
31 | const float angle = circleAngle(divisions, i); |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
32 | return glm::vec2{std::sin(angle), std::cos(angle)}; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
33 | } |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
34 | |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
35 | template<typename Fn> |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
36 | void circleAngles(int segments, int divisions, Fn&& fn) |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
37 | { |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
38 | for (int i = 0; i < segments; i += 1) |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
39 | { |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
40 | const float a1 = circleAngle(divisions, i - 1); |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
41 | const float a2 = circleAngle(divisions, i); |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
42 | const float a3 = circleAngle(divisions, i + 1); |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
43 | fn(a1, a2, a3); |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
44 | } |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
45 | } |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
46 | |
186 | 47 | template<typename Fn> |
48 | void circle(int segments, int divisions, Fn&& fn) | |
49 | { | |
232
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
50 | circleAngles(segments, divisions, [&fn]( |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
51 | const float a1, |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
52 | const float a2, |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
53 | const float a3 |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
54 | ){ |
186 | 55 | fn( |
232
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
56 | glm::vec2{std::sin(a1), std::cos(a1)}, |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
57 | glm::vec2{std::sin(a2), std::cos(a2)}, |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
58 | glm::vec2{std::sin(a3), std::cos(a3)} |
186 | 59 | ); |
232
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
60 | }); |
186 | 61 | } |
154 | 62 | } |
200 | 63 | |
64 | ModelElement inverted(const ModelElement &element); |