Recently I was thinking about creating my own axis x/y, especially 'x', but in that game in which I want to create it, there are no values below 0, because pointX = 0 is on left screen border.
I want to create function which will smoothly count all values depends on our game resolution X.
For example:
parameters: min value, max value, screenX, cursorPosition
if(cursorPosition == screenWidth/2) then
return 0
end
When cursor position is below screenWidth/2, function will smoothly count value between -0 and min value (min value will be, when cursor position = 0)
and the same when cursor pos is above screenWidth/2, function will smoothly count value between 0 and max value (max value will be when cursor position = our screenX)
Can anyone explain to me, how can I reach an effect like that? :)
Regards
use linear interpolation to change the dynamic range. Let assume your view has
xs,ys
resolution and point(0,0)
is top left corner. so the dynamic range per each axis is:and you want to change it to:
So do this:
and if you need to go back for any reason:
where
(minx,miny)
is top left corner and(maxx,maxy)
is bottom right corner. If you want to change also the sign of any axis then you can asminx<maxx
is not required for this so just swap the initial values sominx>maxx
.Not coding in lua but If your values are floating then beware integer rounding while mixing integers and floats together.