   Caclulating the Output Value of a made from scratch slider
  I am working on builing a slider from scratch using glut and c++. I think this should be a simple problem,but I don't seem to be able to get it right. The slider does work for changing color of an object or to scroll something ,but the numbers output by it are not right.For instance if I set the minimum value to 0.0 and the max value to 1.0 the output values on the low end are negative and the output value on the high end are over 1.0. Below is the code I am using to calculate  what the output value should be. This slider is just a line for the track and with a glPoint for the slider I think some people call it the thumb.This one little problem is  all I have left to finish this thing.//tl is the track length//sy is the slider/thumb y position//ty is the y position of the trackthis->FloatValue = (MaxFloatValue/tl)*(sy-ty); Much Thanks, Jody Bush   
  Try this:float range = MaxFloatValue - MinFloatValue;this->FloatValue = (range / tl)*(sy-ty) + MinFloatValue;Also make sure your signs are right. sy-ty may produce a negative number when the slider value is increased. That would make the equation:float range = MaxFloatValue - MinFloatValue;this->FloatValue = (range / tl) * -(sy-ty) + MinFloatValue;   ;  What's MaxFloatValue? Also, where does ty fall relative to the track? (Beginning? Middle?)   ;  I set a MinFloatValue and a MaxFloatValue via a setter at compile time so that the slider will output the MinFloatValue when it is at the beginning of the track and the MaxFloatValue at the end of the track. the ty is at the beginning of the track and has to be subtracted so that all you are dealing with is the track length.It is a vertical slider, the beginning of the horizontal slider is tx. Thanks for the  reply,I will try that and see if it will work.I did not try using the Min value in the calculation because it should evaluate out to be 0 or 0.0 and should'nt change anything.Thanks again Jody Bush   ;  No that did'nt work,I really did not think it looked like it would but I am at the end of the rope on what to try so I tried it. It seems like it should be a fairly simple math problem,maybe I am leaving out something but I can't think what it would be.I have thought the thing out this way and that and what I have been using is the best that I have come up with,but like I said the numbers are wrong. Much Thanks,Jody Bush   