This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
H4X0RZ's profile picture

Scaling Coordinates

Started by H4X0RZ, 15 October 2015 - 07:06 AM
H4X0RZ #1
Posted 15 October 2015 - 09:06 AM
(I posted here because this question is not CC related)

I'm coding a Bot (for a game. just to see if it is possible) that "replays" a replay (which would result in getting the same score all the time). Parsing the replay and extracting the mouse-movement wasn't a problem, but scaling the coordinates is harder than I thought.

My actual screen-size is 1920/1080 px. The game window has a resolution of 1080/720 (It has to be windowed because otherwise I can't extract information from the game window-title) and the mouse movement is recorded on a 512/384 grid/whatever (<- these are no integers but floats so they have a decimal point)

I tried something like this:

half_of_screen - half_of_window + coords
Which resulted in my cursor jumping around.

Does anyone have an idea?
Edited on 15 October 2015 - 07:09 AM
Bomb Bloke #2
Posted 15 October 2015 - 10:18 AM
So… you're trying to scale from where, to where?

The math is percentage based; let's say someone clicked at column 160 on a display with 1920 pixels per row. 160 is 8.333…% of 1920 (160 / 1920 * 100), so if the click had been on a screen using 1080 pixels per row, 8.3% of that would place the click at column 90 (1080 / 100 * 8.333…).

Of course, you'd just that translate directly via 160 / 1920 * 1080.

This all assumes that you are actually wanting to scale; presumably you're resizing the game window before "playback"? Are you sure it's not the relativity of the offsets that're giving you trouble?
H4X0RZ #3
Posted 15 October 2015 - 11:31 AM
So… you're trying to scale from where, to where?

The math is percentage based; let's say someone clicked at column 160 on a display with 1920 pixels per row. 160 is 8.333…% of 1920 (160 / 1920 * 100), so if the click had been on a screen using 1080 pixels per row, 8.3% of that would place the click at column 90 (1080 / 100 * 8.333…).

Of course, you'd just that translate directly via 160 / 1920 * 1080.

This all assumes that you are actually wanting to scale; presumably you're resizing the game window before "playback"? Are you sure it's not the relativity of the offsets that're giving you trouble?

That could be it too. My biggest Problem is that the recorded coordinates always have the same dimensions but and can be replayed by the game. I can easily get relative coordinates to the window (the window is at the exact center of the screen) but I can't find a formula that get's the coordinates from a smaller " resolution" fit into my fixed-size window.The click are allways off by many Pixels even If I adjust it so it starts at the right position after some time the movements are off.