c++ - Convert X Coordinate from one Resolution to another -
usually convert 1 resolution another:
int newx = (x / oldresolutionx) * newresolutionx;
but time can't use , can't head around math (never @ math, forgive me please). anyways, resolution 1280x720 , want convert point (720/360) this: picture of new resolution
the width 854, height 720, don't have conversion y coordinate. here's (for me) tricky part: 0 not actual 0. x starts @ -107 , ends @ 747. guys explain me how can convert (720/360) 1280x720 resolution? in advance , sorry being bad @ math...
so, need linear mapping [0...1280] [-107...747], leaving y untouched.
int newx = (int)((x / 1280.0) * 854.0) -107
so, whats happening here?
- x vary between 0 , 1280.
- if x == 0: (0/1280) * 854 0 , result equals -107.
- if x == 1280: (1280/1280) * 854 = 854: result 747
some remarks:
- the
.0
used force floating-point type. - the
(int)
cast integer
Comments
Post a Comment