Advertisement
Guest User

SlopeMap

a guest
Jan 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. int inMax = 0,
  2.     inMin = 0,
  3.     translMax = 1024,
  4.     translMin = 0;
  5.  
  6. rangeMax = getMaxValue();
  7. rangeMin = getMinValue();
  8.  
  9. //Calculate 4 of these (xpos xneg ypos yneg)
  10. float slope = 1.0 * (translMax - translMin) / (rangeMax - rangeMin);
  11.  
  12. int translate(int inputVal, int outputMin, int inputMin, double slope){ return outputMin + slope * (inputVal - inputMin); }
  13.  
  14. //use the correct slope depending on if x & y > centerValue (if xpos or ypos, start from centerValue and not 0 = translMin)
  15. translatedValue = translate(inValue, translMin, rangeMin, slope);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement