Wed, 22 Jan 2020 01:17:11 +0200
commit work done on plugging vao to the gl renderer, renders nonsense for now
3 | 1 | #include "subfilereference.h" |
21 | 2 | #include "documentmanager.h" |
26 | 3 | #include "invert.h" |
3 | 4 | |
21 | 5 | linetypes::SubfileReference::SubfileReference(const Matrix4x4& transformation, |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
6 | const QString& referenceName, |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
7 | const Color color) : |
13 | 8 | ColoredObject{color}, |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
9 | transformation{transformation}, |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
10 | referenceName{referenceName} |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
11 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
12 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
13 | |
13 | 14 | QVariant linetypes::SubfileReference::getProperty(Property property) const |
3 | 15 | { |
16 | switch (property) | |
17 | { | |
18 | case Property::Transformation: | |
19 | return QVariant::fromValue(this->transformation); | |
20 | case Property::ReferenceName: | |
21 | return this->referenceName; | |
22 | default: | |
13 | 23 | return ColoredObject::getProperty(property); |
3 | 24 | } |
25 | } | |
6 | 26 | |
13 | 27 | auto linetypes::SubfileReference::setProperty( |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
28 | Property property, |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
29 | const QVariant& value) |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
30 | -> SetPropertyResult |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
31 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
32 | switch (property) |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
33 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
34 | case Property::Transformation: |
21 | 35 | this->transformation = value.value<Matrix4x4>(); |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
36 | return SetPropertyResult::Success; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
37 | case Property::ReferenceName: |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
38 | this->referenceName = value.toString(); |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
39 | return SetPropertyResult::Success; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
40 | default: |
13 | 41 | return ColoredObject::setProperty(property, value); |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
42 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
43 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
44 | |
13 | 45 | QString linetypes::SubfileReference::textRepresentation() const |
6 | 46 | { |
21 | 47 | return referenceName + " " + vertexToStringParens(this->position()); |
6 | 48 | } |
21 | 49 | |
50 | void linetypes::SubfileReference::getPolygons( | |
51 | std::vector<gl::Polygon>& polygons, | |
52 | GetPolygonsContext* context) const | |
53 | { | |
54 | Model* model = this->resolve(context->documents); | |
55 | if (model != nullptr) | |
56 | { | |
26 | 57 | const bool needInverting = math::det(this->transformation) < 0; |
21 | 58 | const std::vector<gl::Polygon> modelPolygons = model->getPolygons(context->documents); |
59 | polygons.reserve(polygons.size() + modelPolygons.size()); | |
60 | for (gl::Polygon polygon : modelPolygons) | |
61 | { | |
23
3387a84ddaba
fixed a pile of nonsense that caused subfiles to go haywire
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
62 | for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) |
21 | 63 | { |
23
3387a84ddaba
fixed a pile of nonsense that caused subfiles to go haywire
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
64 | polygon.vertices[i] = math::transform(polygon.vertices[i], this->transformation); |
21 | 65 | } |
26 | 66 | if (needInverting != this->isInverted) |
67 | { | |
68 | gl::invert(polygon); | |
69 | } | |
21 | 70 | if (polygon.color == colors::main) |
71 | { | |
72 | polygon.color = this->colorIndex; | |
73 | } | |
74 | polygon.id = this->id; | |
75 | polygons.push_back(polygon); | |
76 | } | |
77 | } | |
78 | } | |
79 | ||
80 | Point3D linetypes::SubfileReference::position() const | |
81 | { | |
82 | return {this->transformation(0, 3), this->transformation(1, 3), this->transformation(2, 3)}; | |
83 | } | |
84 | ||
26 | 85 | void linetypes::SubfileReference::invert() |
86 | { | |
87 | this->isInverted = not this->isInverted; | |
88 | } | |
89 | ||
21 | 90 | Model* linetypes::SubfileReference::resolve(DocumentManager* documents) const |
91 | { | |
92 | return documents->findModelByName(this->referenceName); | |
93 | } |