-
Notifications
You must be signed in to change notification settings - Fork 1
/
navmesh_render_area.hpp
101 lines (79 loc) · 3.59 KB
/
navmesh_render_area.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef NAVMESH_RENDER_AREA_HPP_
#define NAVMESH_RENDER_AREA_HPP_
#include "navmesh_render_area_base.hpp"
#include <Pathfinder/pathfinder.h>
#include <Pathfinder/vector.h>
#include <QPainter>
#include <QString>
#include <QWheelEvent>
#include <QWidget>
#include <utility>
#include <vector>
template<typename NavmeshTriangulationType>
class NavmeshRenderArea : public NavmeshRenderAreaBase {
private:
using PathfinderType = pathfinder::Pathfinder<NavmeshTriangulationType>;
using PathfindingResult = typename PathfinderType::PathfindingResult;
using IndexType = typename NavmeshTriangulationType::IndexType;
public:
explicit NavmeshRenderArea(QWidget *parent = nullptr);
QSize minimumSizeHint() const override;
void mouseMoveEvent(QMouseEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
QSize sizeHint() const override;
void setNavmeshTriangulation(const NavmeshTriangulationType &navmeshTriangulation);
void setPath(const PathfindingResult &pathfindingResult);
void resetPath() override;
// Polyanya animation
void stepBackPlaybackAnimation() override;
void startPlaybackAnimation() override;
void pausePlaybackAnimation() override;
void stopPlaybackAnimation() override;
void stepForwardPlaybackAnimation() override;
void setFramePlaybackAnimation(const QString &text) override;
double getNavmeshMinX() const override;
double getNavmeshMinY() const override;
double getNavmeshWidth() const override;
double getNavmeshHeight() const override;
protected:
// Navmesh data
const NavmeshTriangulationType *navmeshTriangulation_{nullptr};
void paintEvent(QPaintEvent *event) final;
// Override this function to draw something under the navigation mesh triangulation.
// The painter state is saved by the caller; you are not obligated to do so nor end with the painter in any specific state.
virtual void paintUnderNavmeshTriangulation(QPainter &painter) { /* Do nothing */ }
pathfinder::Vector transformWidgetCoordinateToNavmeshCoordinate(const pathfinder::Vector &v) const;
pathfinder::Vector transformNavmeshCoordinateToWidgetCoordinate(const pathfinder::Vector &v) const;
private:
// View data
double navmeshRenderAreaMargin_{0.0};
double navmeshMinX_{0.0}, navmeshMinY_{0.0};
double navmeshWidth_{0.0}, navmeshHeight_{0.0};
// Pathfinding data
const PathfindingResult *pathfindingResult_{nullptr};
// Data for animating the polyanya pathfinding algorithm
QTimer *animationTimer_{nullptr};
int animationIndex_;
std::vector<std::pair<size_t, size_t>> ends_;
std::vector<typename PathfinderType::IntervalType> pushedIntervals_;
std::vector<typename PathfinderType::IntervalType> visitedIntervals_;
std::vector<std::optional<QPolygonF>> pushedIntervalsAsQPolygonF_;
std::vector<std::optional<QPolygonF>> visitedIntervalsAsQPolygonF_;
void setSizeBasedOnNavmesh();
void drawVertices(QPainter &painter);
void drawEdges(QPainter &painter);
void drawAnimatedPathfinding(QPainter &painter);
void drawShortestPath(QPainter &painter);
void drawAllPairsDistances(QPainter &painter);
void drawPathfindingStartAndGoal(QPainter &painter);
void drawTriangles(QPainter &painter, const std::vector<IndexType> &triangles, const QColor &color);
void drawVertexLabels(QPainter &painter);
void drawEdgeLabels(QPainter &painter);
void drawTriangleLabels(QPainter &painter);
// Polyanya animation
void advanceAnimationFrame();
void preProcessAnimationData();
std::optional<QPolygonF> intervalToQPolygonF(const typename PathfinderType::IntervalType &interval) const;
};
#include "navmesh_render_area.inl"
#endif // NAVMESH_RENDER_AREA_HPP_