|
3 | 3 | #include "demo_0.h" |
4 | 4 |
|
5 | 5 | #include <QKeyEvent> |
| 6 | +#include <QMouseEvent> |
6 | 7 |
|
7 | 8 | #include "pathfinding/cost_field.h" |
8 | 9 | #include "pathfinding/flow_field.h" |
@@ -596,6 +597,27 @@ void path_demo_0(const util::Path &path) { |
596 | 597 | auto flow_field = std::make_shared<FlowField>(10); |
597 | 598 | flow_field->build(integration_field); |
598 | 599 |
|
| 600 | + window.add_mouse_button_callback([&](const QMouseEvent &ev) { |
| 601 | + if (ev.type() == QEvent::MouseButtonRelease) { |
| 602 | + if (ev.button() == Qt::RightButton) { |
| 603 | + auto grid_plane_normal = Eigen::Vector3f{0, 1, 0}; |
| 604 | + auto grid_plane_point = Eigen::Vector3f{0, 0, 0}; |
| 605 | + auto camera_direction = renderer::camera::cam_direction; |
| 606 | + auto camera_position = camera->get_input_pos( |
| 607 | + coord::input{ev.position().x(), ev.position().y()}); |
| 608 | + |
| 609 | + Eigen::Vector3f intersect = camera_position + camera_direction * (grid_plane_point - camera_position).dot(grid_plane_normal) / camera_direction.dot(grid_plane_normal); |
| 610 | + auto grid_x = static_cast<int>(-1 * intersect[2]); |
| 611 | + auto grid_y = static_cast<int>(intersect[0]); |
| 612 | + |
| 613 | + if (grid_x >= 0 && grid_x < 10 && grid_y >= 0 && grid_y < 10) { |
| 614 | + integration_field->integrate(cost_field, grid_x, grid_y); |
| 615 | + flow_field->build(integration_field); |
| 616 | + } |
| 617 | + } |
| 618 | + } |
| 619 | + }); |
| 620 | + |
599 | 621 | // Create object for the cost field |
600 | 622 | // this will be shown at the start |
601 | 623 | Eigen::Matrix4f model = Eigen::Matrix4f::Identity(); |
|
0 commit comments