05-04-2022, 04:37 PM
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:
Happy coding!
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:
sha_na_na_na_na_na_na_na_na_na: