Skip to content

Commit

Permalink
Working Mouse Input
Browse files Browse the repository at this point in the history
Holy shit, after 14 hours I finally have something working! It's a
little sketchy, but its something we can build upon
  • Loading branch information
zappybiby committed Feb 18, 2017
1 parent 56d1a44 commit dc021d4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
Binary file modified ets2_auto_driving.sdf
Binary file not shown.
Binary file modified ets2_auto_driving.v12.suo
Binary file not shown.
41 changes: 26 additions & 15 deletions ets2_auto_driving/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,20 @@ int main() {

long long int sum = 0;
long long int i = 0;

while (true) {
// Use '+' on NUMPAD to start

This comment has been minimized.

Copy link
@cltsd27

cltsd27 Feb 18, 2017

Collaborator
  • pauses
if (GetAsyncKeyState(VK_ADD) & 0x8000){
while (true) {
// Use '*' on NUMPAD to pause

This comment has been minimized.

Copy link
@cltsd27

cltsd27 Feb 18, 2017

Collaborator

this starts

if (GetAsyncKeyState(VK_MULTIPLY) & 0x8000){
break;
}
}
}
auto begin = chrono::high_resolution_clock::now();
// Grab the game window
HWND hWnd = FindWindow("prism3d", NULL);
HWND consoleWindow = GetConsoleWindow();

Mat image, outputImg;
hwnd2mat(hWnd).copyTo(image);
Expand Down Expand Up @@ -112,14 +121,16 @@ int main() {
LineFinder ld;

ld.setLineLengthAndGap(20, 120);
ld.setMinVote(55);
ld.setMinVote(60);

This comment has been minimized.

Copy link
@zappybiby

zappybiby Feb 18, 2017

Author Collaborator

Having better results with this change

This comment has been minimized.

Copy link
@zappybiby

zappybiby Feb 18, 2017

Author Collaborator

nevermind, lol.


// Uses Proabablistic Hough Transform to return a vector of lines
std::vector<cv::Vec4i> li = ld.findLines(contours);
ld.drawDetectedLines(contours);

// cv::cvtColor(contours, contours, COLOR_GRAY2RGB);
imshow("Test", contours);
HWND Output = FindWindow("Test", NULL);
SetWindowPos(consoleWindow, 0, 960, 250, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
SetWindowPos(Output, 0, 960, 400, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
waitKey(1);
// cv::cvtColor(contours, contours, COLOR_GRAY2RGB);

Expand Down Expand Up @@ -166,28 +177,28 @@ int main() {
SetActiveWindow(hWnd);
POINT pt;
GetCursorPos(&pt);
int average = (left == -150 || right == 150) ? 0 : left + right;
if (left + right < -50)
int average = (left == -150 || right == 150) ? 0 : (left + right) / 2;
if (left + right <= -50 || left + right >= 50)
{
cout << "go left ";
cout << "go " << (left + right < 0 ? "left " : "right ");
GetCursorPos(&pt);
SetCursorPos(pt.x - 1, pt.y);
// must be prime
SetCursorPos(pt.x + average / 13, pt.y);
cout << "current mouse pos: " << "x: " << pt.x << "y: " << pt.y << endl;
}
else if (left + right > -50 && left + right < 50){
else /*if (left + right > -50 && left + right < 50)*/{
cout << "go straight ";
for (int x = 0, y = 0; x < 700 && y < 700; x += 10, y += 10)
{
//SetCursorPos((windowsize.right - windowsize.left) / 2, (windowsize.bottom - windowsize.top) / 2);
SetCursorPos(512, 384);
}
//for (int x = 0, y = 0; x < 700 && y < 700; x += 10, y += 10)
//{
SetCursorPos((windowsize.right) / 2, (windowsize.bottom) / 2);
//}
}
else{
/*else{
cout << "go right ";
GetCursorPos(&pt);
SetCursorPos(pt.x + 1, pt.y);
cout << "current mouse pos: " << "x: " << pt.x << "y: " << pt.y << endl;
}
}*/
cout << "left: " << left << ", right: " << right << ", average: " << average << endl;
}
return 0;
Expand Down
Binary file modified ets2_auto_driving/vc120.pdb
Binary file not shown.

0 comments on commit dc021d4

Please sign in to comment.