Skip to content

Commit 4efaad0

Browse files
committed
Merge pull request #38 from Databean/fixClicking
Fixed clicking on things
2 parents 2b998ce + 631e06d commit 4efaad0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Renderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Coordinate screenToCoord(const pair<float, float>& screen) {
163163
Coordinate ret;
164164
float y_approx = (screen.second - 0.1f) / std::sin(angle) / scale;
165165
ret.second = std::round(y_approx);
166-
ret.first = std::round((screen.first - 0.2f) / scale - (screen.second - 0.1f) / scale / std::sin(angle) * std::cos(angle)) - 1;
166+
ret.first = std::round((screen.first - 0.2f) / scale - y_approx * std::cos(angle) - 0.5);
167167
return ret;
168168
}
169169

tests/testRenderer.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <iostream>
2+
3+
#include "UnitTest++.h"
4+
#include "Renderer.h"
5+
6+
using std::cout;
7+
using std::endl;
8+
using std::make_pair;
9+
10+
TEST(coordToScreen) {
11+
for(int x = -5; x < 5; x++) {
12+
for(auto y = -5; y < 5; y++) {
13+
auto original = make_pair(x, y);
14+
auto screen = coordToScreen(original);
15+
auto back = screenToCoord(screen);
16+
CHECK(original.first == back.first);
17+
CHECK(original.second == back.second);
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)