Is there a way of converting X value and Y value to a Single Value and then reverse? I need to send the positions in 1 value.
Plooscva :D
Printable View
Is there a way of converting X value and Y value to a Single Value and then reverse? I need to send the positions in 1 value.
Plooscva :D
Well, one way to do it is to multiply the X value by the maximum value that Y can be, then adding the Y to it (or the other way round). This gives a continuous series of unique values...
For example, if your frame is 640x480:
X=50, Y=100 ... Combined value = 50*480 + 100 = 2500
X=47, Y=479 ... Combined value = 22560 + 479 = 23039
(In total, 307,200 positions are possible in 640x480.)
To get it back, the X is the result of dividing the combined value by the maximum value of Y, and the Y is the remainder.
23039 / 480 = 47 r 479
Ok I found a way to work round but still this will come in helpful one day. Cheers :D