usually i would do this to convert from one resolution into another:
int newX = (x / oldResolutionX) * newResolutionX;
But this time i can't use it and i can't get my head around the math (never was really good at math, forgive me please). Anyways, my Resolution is 1280x720 and i want to convert a point like (720/360) to this: Picture of new Resolution
The Width is 854, Height is 720, so i don't have to do a conversion for the y coordinate. But here's the (for me) tricky part: 0 is not the actual 0. X starts at -107 and ends at 747. Could you guys explain to me how i can convert (720/360) from 1280x720 into this Resolution? Thanks in advance and sorry for being bad at math...
So, you need a linear mapping from [0...1280] to [-107...747], leaving y untouched.
int newX = (int)((x / 1280.0) * 854.0) -107
So, whats happening here?
Some remarks:
.0
is used to force a floating-point type. (int)
is to cast it back to a integer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.