mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
implement speed and move
This commit is contained in:
parent
fe6d96f4a0
commit
2286e0c7b1
@ -131,12 +131,28 @@ void MapView::onMapSwiped(const Point & viewPosition)
|
||||
void MapView::postSwipe(uint32_t msPassed) {
|
||||
if(!actions->dragActive && swipeHistory.size() > 0)
|
||||
{
|
||||
Point diff = swipeHistory.end()->second - swipeHistory.begin()->second;
|
||||
double angle = diff.angle();
|
||||
Point diff = Point(0, 0);
|
||||
for (auto & x : swipeHistory)
|
||||
diff += x.second;
|
||||
|
||||
std::cout << angle;
|
||||
uint64_t timediff = swipeHistory.rbegin()->first - swipeHistory.begin()->first;
|
||||
|
||||
postSwipeAngle = diff.angle();
|
||||
postSwipeSpeed = static_cast<double>(diff.length()) / static_cast<double>(timediff); // unit: pixel/millisecond
|
||||
|
||||
std::cout << postSwipeAngle << " " << postSwipeSpeed << " " << diff.x << "x" << diff.y << " " << timediff << "\n";
|
||||
swipeHistory.clear();
|
||||
}
|
||||
if(postSwipeSpeed > 0.1) {
|
||||
double len = postSwipeSpeed * static_cast<double>(msPassed);
|
||||
Point delta = Point(len * cos(postSwipeAngle), len * sin(postSwipeAngle));
|
||||
|
||||
std::cout << len << " " << delta.x << "x" << delta.y << "\n";
|
||||
|
||||
controller->setViewCenter(model->getMapViewCenter() + delta, model->getLevel());
|
||||
|
||||
postSwipeSpeed /= 1.1;
|
||||
}
|
||||
}
|
||||
|
||||
void MapView::onCenteredTile(const int3 & tile)
|
||||
|
@ -118,7 +118,7 @@ public:
|
||||
|
||||
double angle() const
|
||||
{
|
||||
return std::atan2(y, x) * 180.0 / M_PI;
|
||||
return std::atan2(y, x); // rad
|
||||
}
|
||||
|
||||
template <typename Handler>
|
||||
|
Loading…
Reference in New Issue
Block a user