Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mouse Help Needed
#24
This is somewhat off topic, but thought you might be interested.

Although you have the mouse sliders working well, I thought I'd introduce you to a little function that I learned a while back, which I think you will love. I think it was Fellippe that introduced me to the map! function. I use it for all sorts of conversions to translate screen positions to desired data ranges, but you'll find it useful for all sorts of things.



When you collect the mouse data for power and angle you're doing the following two computations:

vel = (mx - 60) / 200 * 100 ' converts place in box to 0 to 100

and

a = (mx - 60) / 200 * 90 ' converts place in box to 0 to 90

Here, you're essentially doing the map function manually.



Substituting the map! function, they become:

vel = map!( mx, 60, 260, 0, 100)

and

a = map!( mx, 60, 260, 0, 90)



No less typing of code, but you can shunt the math to the function and all you have to know is the input value from (in this case) mx, the left to right box limits and the desired range you want those limits translated to. In this way you don't have to reinvent the wheel for each different car.



It will even reverse engineer the LINE statement from:

LINE (61, 41)-(mx, 69), _RGB32(255, 0, 1), BF

to

LINE (61, 41)-(map!( vel, 0, 100, 60, 260), 69), _RGB32(255, 0, 1), BF ' returns mx from vel



Which, in this case, doesn't really do anything in your favor, but just illustrates how it will work in either direction.

Then you can place the following in the SUB/FUNCTION section of your code:



Code: (Select All)
FUNCTION map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
    map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
END FUNCTION 'map!




Happy coding!
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Reply


Messages In This Thread
Mouse Help Needed - by SierraKen - 05-02-2022, 01:30 AM
RE: Mouse Help Needed - by bplus - 05-02-2022, 01:56 AM
RE: Mouse Help Needed - by SierraKen - 05-02-2022, 02:03 AM
RE: Mouse Help Needed - by SierraKen - 05-02-2022, 02:11 AM
RE: Mouse Help Needed - by bplus - 05-02-2022, 02:48 AM
RE: Mouse Help Needed - by bplus - 05-02-2022, 03:54 AM
RE: Mouse Help Needed - by bplus - 05-02-2022, 04:03 AM
RE: Mouse Help Needed - by bplus - 05-02-2022, 04:22 AM
RE: Mouse Help Needed - by SierraKen - 05-02-2022, 04:26 AM
RE: Mouse Help Needed - by SierraKen - 05-02-2022, 04:25 AM
RE: Mouse Help Needed - by SierraKen - 05-02-2022, 04:30 AM
RE: Mouse Help Needed - by bplus - 05-02-2022, 04:32 AM
RE: Mouse Help Needed - by SierraKen - 05-02-2022, 04:33 AM
RE: Mouse Help Needed - by bplus - 05-02-2022, 04:37 AM
RE: Mouse Help Needed - by SierraKen - 05-02-2022, 04:52 AM
RE: Mouse Help Needed - by SierraKen - 05-02-2022, 05:09 AM
RE: Mouse Help Needed - by dcromley - 05-02-2022, 04:51 PM
RE: Mouse Help Needed - by bplus - 05-02-2022, 05:10 PM
RE: Mouse Help Needed - by OldMoses - 05-02-2022, 06:17 PM
RE: Mouse Help Needed - by bplus - 05-02-2022, 06:58 PM
RE: Mouse Help Needed - by OldMoses - 05-02-2022, 11:53 PM
RE: Mouse Help Needed - by SierraKen - 05-03-2022, 11:26 PM
RE: Mouse Help Needed - by SierraKen - 05-03-2022, 11:34 PM
RE: Mouse Help Needed - by OldMoses - 05-04-2022, 04:37 PM
RE: Mouse Help Needed - by bplus - 05-04-2022, 04:43 PM
RE: Mouse Help Needed - by OldMoses - 05-04-2022, 05:04 PM
RE: Mouse Help Needed - by bplus - 05-04-2022, 05:12 PM
RE: Mouse Help Needed - by OldMoses - 05-05-2022, 12:25 AM



Users browsing this thread: 18 Guest(s)