-2

I want to increase or decrease a float variable that is between 1 and 0.4 depending on the position of the mouse.

For example, mouse moves up, value increases, mouse moves down it decreases, but is not greater than 1 or less than 0.4 I know I did not attach any code, but I just want an indication. Thanks !

Geo_Tek
  • 13
  • 5
  • 1
    " I know I did not attach any code" But that´s what you should do so we know what you´ve tried and where specifically you´re stuck. – MakePeaceGreatAgain Dec 20 '18 at 10:07
  • Well, I've tried several things to link somehow the position of the mouse on the y-axis with this variable, but none of it goes out – Geo_Tek Dec 20 '18 at 10:08
  • And how should *we* know which attemps didn´t work for you in order to not to write the exact same? I doubt that´ll help you, would it? – MakePeaceGreatAgain Dec 20 '18 at 10:10
  • 1
    As a hint find minY and maxY of your screen resolution and the get the difference and map this range into your range 0.4 and 1 – Ali Kanat Dec 20 '18 at 10:11
  • 1
    Then you can transform every position of your mouse into your "world-coordinates" within the provided range. – MakePeaceGreatAgain Dec 20 '18 at 10:12

1 Answers1

0

you can use this method to change your mouse position (for example in y-axis) range to your desired range (between 4.0 to 1)

public static double ConvertRange(
    double originalStart, double originalEnd, // original range
    double newStart, double newEnd, // desired range
     value) // value to convert
{
    double scale = (double)(newEnd - newStart) / (originalEnd - originalStart);
    return newStart + ((value - originalStart) * scale);
}

It is mentioned here

M.Armoun
  • 1,075
  • 3
  • 12
  • 38