Here's the problem.
I am trying to implement a custom slider in a game written in java. Due to the nature of the game engine, the slider only supports values from 0.0f to 1.0f. In reality, I may need to have values from 0-20 or 1-4.
Converting from the slider value to the scale value is simple:
protected float sliderToActual(){ return (sliderValue*maxValue); }
The other way around is what confuses me. In the constructor, I set the value (not in the 0-1 scale), the minimum value (ex: 1) and the max value (ex: 20).
Here's some code I wrote to test out the algorithm.
public static void main(String[] args) { float minValue = 2; float maxValue = 20; for (int i=1; i<21; i++) System.out.println(i + " on the scale is " + (i - minValue)/( maxValue - minValue)); }
Which gives the output of:
Originally Posted by Output