1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-15 11:46:56 +02:00

angle calc

This commit is contained in:
Michael 2023-08-26 20:19:25 +02:00 committed by GitHub
parent bd0f9bb280
commit fe6d96f4a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View File

@ -129,8 +129,14 @@ void MapView::onMapSwiped(const Point & viewPosition)
} }
void MapView::postSwipe(uint32_t msPassed) { void MapView::postSwipe(uint32_t msPassed) {
if(!actions->dragActive) if(!actions->dragActive && swipeHistory.size() > 0)
{
Point diff = swipeHistory.end()->second - swipeHistory.begin()->second;
double angle = diff.angle();
std::cout << angle;
swipeHistory.clear(); swipeHistory.clear();
}
} }
void MapView::onCenteredTile(const int3 & tile) void MapView::onCenteredTile(const int3 & tile)

View File

@ -50,6 +50,8 @@ class MapView : public BasicMapView
std::shared_ptr<MapViewActions> actions; std::shared_ptr<MapViewActions> actions;
std::map<uint64_t, Point> swipeHistory; std::map<uint64_t, Point> swipeHistory;
double postSwipeAngle;
double postSwipeSpeed;
void postSwipe(uint32_t msPassed); void postSwipe(uint32_t msPassed);

View File

@ -116,6 +116,11 @@ public:
return std::sqrt(lengthSquared()); return std::sqrt(lengthSquared());
} }
double angle() const
{
return std::atan2(y, x) * 180.0 / M_PI;
}
template <typename Handler> template <typename Handler>
void serialize(Handler &h, const int version) void serialize(Handler &h, const int version)
{ {