瀏覽代碼

angle calc

Michael 2 年之前
父節點
當前提交
fe6d96f4a0
共有 3 個文件被更改,包括 14 次插入1 次删除
  1. 7 1
      client/mapView/MapView.cpp
  2. 2 0
      client/mapView/MapView.h
  3. 5 0
      lib/Point.h

+ 7 - 1
client/mapView/MapView.cpp

@@ -129,8 +129,14 @@ void MapView::onMapSwiped(const Point & viewPosition)
 }
 
 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();
+	}
 }
 
 void MapView::onCenteredTile(const int3 & tile)

+ 2 - 0
client/mapView/MapView.h

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

+ 5 - 0
lib/Point.h

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