20 this->selection.unite(selectedIds); |
20 this->selection.unite(selectedIds); |
21 this->compiler->setSelectedObjects(this->selection); |
21 this->compiler->setSelectedObjects(this->selection); |
22 this->update(); |
22 this->update(); |
23 } |
23 } |
24 |
24 |
25 QString vectorToString(const glm::vec3& vec) |
|
26 { |
|
27 return "(%1, %2, %3)"_q |
|
28 .arg(toDouble(vec.x)) |
|
29 .arg(toDouble(vec.y)) |
|
30 .arg(toDouble(vec.z)); |
|
31 } |
|
32 |
|
33 void Canvas::mouseMoveEvent(QMouseEvent* event) |
25 void Canvas::mouseMoveEvent(QMouseEvent* event) |
34 { |
26 { |
35 const ldraw::Id id = this->pick(event->pos()); |
27 const ldraw::Id id = this->pick(event->pos()); |
36 this->highlighted = id; |
28 this->highlighted = id; |
37 this->totalMouseMove += (event->pos() - this->lastMousePosition).manhattanLength(); |
29 this->totalMouseMove += (event->pos() - this->lastMousePosition).manhattanLength(); |
38 this->worldPosition = this->screenToModelCoordinates(event->pos(), geom::XY); |
30 this->worldPosition = this->screenToModelCoordinates(event->pos(), this->gridPlane); |
39 if (this->worldPosition.has_value()) |
31 if (this->worldPosition.has_value()) |
40 { |
32 { |
|
33 this->worldPosition = glm::inverse(this->gridMatrix) * glm::vec4{*this->worldPosition, 1}; |
41 this->worldPosition = glm::round(*this->worldPosition); |
34 this->worldPosition = glm::round(*this->worldPosition); |
|
35 this->worldPosition = this->gridMatrix * glm::vec4{*this->worldPosition, 1}; |
42 } |
36 } |
43 if (this->worldPosition.has_value()) |
37 if (this->worldPosition.has_value()) |
44 { |
38 { |
45 this->newStatusText("Position: (%1, %2, %3)"_q |
39 this->newStatusText("Position: (%1, %2, %3)"_q |
46 .arg(toDouble(this->worldPosition->x)) |
40 .arg(toDouble(this->worldPosition->x)) |
105 const bool isDark = luma(this->renderPreferences.backgroundColor) < 0.25; |
99 const bool isDark = luma(this->renderPreferences.backgroundColor) < 0.25; |
106 this->gridProgram->setGridColor(isDark ? Qt::white : Qt::black); |
100 this->gridProgram->setGridColor(isDark ? Qt::white : Qt::black); |
107 } |
101 } |
108 }); |
102 }); |
109 PartRenderer::initializeGL(); |
103 PartRenderer::initializeGL(); |
|
104 this->gridMatrix = glm::mat4{ |
|
105 {-4, 0, 0, 0}, |
|
106 {0, 6.9266, -3.6955, 0}, |
|
107 {0, -16.7222, -1.5307, 0}, |
|
108 {0, -13.273, -9.255, 1}, |
|
109 }; |
|
110 this->updateGridMatrix(); |
110 } |
111 } |
111 |
112 |
112 void Canvas::paintGL() |
113 void Canvas::paintGL() |
113 { |
114 { |
114 PartRenderer::paintGL(); |
115 PartRenderer::paintGL(); |
125 const QPointF pos = this->modelToScreenCoordinates(*this->worldPosition); |
126 const QPointF pos = this->modelToScreenCoordinates(*this->worldPosition); |
126 painter.drawEllipse(pos, 5, 5); |
127 painter.drawEllipse(pos, 5, 5); |
127 painter.setPen(Qt::white); |
128 painter.setPen(Qt::white); |
128 painter.drawText(pos + QPointF{5, 5}, vectorToString(*this->worldPosition)); |
129 painter.drawText(pos + QPointF{5, 5}, vectorToString(*this->worldPosition)); |
129 } |
130 } |
|
131 { |
|
132 QPainter axisPainter{this}; |
|
133 axisPainter.setRenderHint(QPainter::Antialiasing); |
|
134 axisPainter.setPen(Qt::red); |
|
135 axisPainter.drawLine( |
|
136 this->modelToScreenCoordinates({10, 0, 0}), |
|
137 this->modelToScreenCoordinates({-10, 0, 0})); |
|
138 axisPainter.setPen(Qt::green); |
|
139 axisPainter.drawLine( |
|
140 this->modelToScreenCoordinates({0, 10, 0}), |
|
141 this->modelToScreenCoordinates({0, -10, 0})); |
|
142 axisPainter.setPen(Qt::blue); |
|
143 axisPainter.drawLine( |
|
144 this->modelToScreenCoordinates({0, 0, 10}), |
|
145 this->modelToScreenCoordinates({0, 0, -10})); |
|
146 } |
130 } |
147 } |
|
148 |
|
149 void Canvas::updateGridMatrix() |
|
150 { |
|
151 const geom::Triangle triangle { |
|
152 this->gridMatrix * glm::vec4{0, 0, 0, 1}, |
|
153 this->gridMatrix * glm::vec4{1, 0, 0, 1}, |
|
154 this->gridMatrix * glm::vec4{0, 1, 0, 1}, |
|
155 }; |
|
156 this->gridPlane = geom::planeFromTriangle(triangle); |
|
157 this->gridProgram->setGridMatrix(this->gridMatrix); |
|
158 } |