|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Axis/Slider Scale
Hi,
Currently I'm having an issue with the slider of my Logitech joystick. The range is from -1 to 1 and I need to convert it to be from 0 to 1 rather than -1 to 1. How would I go about doing this? I'm using the Logitech Extreme 3D Pro and the axis number is 3. I'm using Java but I figured this is a language-wide issue, hence the post here. Thanks! |
|
#2
|
||||
|
||||
|
Re: Axis/Slider Scale
Code:
(stick.get() + 1) / 2 |
|
#3
|
|||
|
|||
|
Re: Axis/Slider Scale
In my experience, I've found that the slider has been unreliable. So, just watch out buddy.
|
|
#4
|
||||
|
||||
|
Re: Axis/Slider Scale
Quote:
If you are interested, here's the algebra to solve that kind of problem, for any input and output range, assuming you want a linear conversion from input to output: Let x be the input and y be the output. You want a linear conversion, so use the equation for a line: y = mx + b When x is -1 you want y to be 0: 0 = m(-1) + b ....(Equation1) When x is 1 you want y to be 1: 1 = m(1) + b .....(Equation2) You have 2 equations with two unknowns, so solve them. Add the two equations: 1 = 2b .....=>..... b = (1/2) Subtract Equation1 from Equation2: 1 = 2m .....=>..... m=(1/2) So the conversion is y = (1/2)x + (1/2) = (x+1)/2 |
|
#5
|
||||
|
||||
|
Re: Axis/Slider Scale
Quote:
Thank you! |
|
#6
|
|||||
|
|||||
|
Re: Axis/Slider Scale
While I understand that the problem is solved, i'm still rather intrigued -- why did you feel the need to do this; have default be 0.5, and have the joystick(s) serve as a throttle to that?
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|