Et af problemerne er at du regner i heltal, så hvis ikke dine afstande er meget store vil opløsningen være meget grov og/eller du rammer ved siden af målet.
Jeg prøvede at skruge en funktion sammen, det kan sikket laves smartere: void Move(int mousex, int mousey) { HDC dc = GetDC(MainWindow); if(abs(manx - mousex) > abs(many - mousey)) { double y = many;
double dy = (((double )many - mousey)/((double )manx - mousex)); int x; if(manx < mousex) { for(x = manx; x < mousex; x++) { SetPixel(dc, x, (int )y, RGB(0, 0, 255)); y += dy; } } else { for(x = manx; x > mousex; x--) { SetPixel(dc, x, (int )y, RGB(0, 0, 255)); y -= dy; } } } else { double x = manx; double dx = (((double )many - mousey)/((double )manx - mousex)); int y; if(many < mousey) { for(y = many; y < mousey; y++) { SetPixel(dc, (int )x, y, RGB(0, 0, 255)); x += dx; } } else { for(y = many; y > mousey; y--) { SetPixel(dc, (int )x, y, RGB(0, 0, 255)); x -= dx; } } } ReleaseDC(MainWindow, dc); }
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.