Joystick Throttle Input Correction

Advanced game related topics
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Joystick Throttle Input Correction

Post by Guimauve »

Hello everyone,

For my 3D game project, I have to use the Joystick axis value to scale the force applied on Rigid Body piloted by the player. For the 3 first axis having values ranging from -32768 to 32767 (the same range as a "Word" variable) are useful but for the last one it's not useful at all. This axis should range for 0 to 65535 (the same range as a "Unicode" variable).

In 2007, I have created this solution but even if it work I'm sure a much faster and simple solution exist.

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Joystick Throttle Input Correction
; File Name : ThrottleInputCorrection.pb
; File version: 1.0.0
; Programming : OK
; Programmed by : Guimauve
; Date : 02-02-2007
; Last Update : 09-08-2012
; PureBasic code : 4.70 Beta 1
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Procedure.u ThrottleInputCorrection(Input.w)
  
  If Input < 0
    ProcedureReturn Input - 32768
  ElseIf Input = 0
    ProcedureReturn 32768
  ElseIf Input > 0
    ProcedureReturn Input + 32768
  EndIf
  
EndProcedure

Debug "; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
Debug "; Here we test when the throttle is set near 0%"
Debug ""

For Index = -32768 To -32763
  Debug ThrottleInputCorrection(Index)
Next

Debug ""
Debug "; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
Debug "; Here we test when the throttle is set near 50%"
Debug ""

For Index = -3 To 3
  Debug ThrottleInputCorrection(Index)
Next

Debug ""
Debug "; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
Debug "; Here we test when the throttle is set near 100%"
Debug ""

For Index = 32762 To 32767
  Debug ThrottleInputCorrection(Index)
Next

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
Any idea to improve this solution.

Best regards
Guimauve
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Joystick Throttle Input Correction

Post by Demivec »

Guimauve wrote:Any idea to improve this solution.

Code: Select all

Procedure.u ThrottleInputCorrection(Input.u)
   ProcedureReturn Input + 32768
EndProcedure
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Re: Joystick Throttle Input Correction

Post by Guimauve »

As simple as that ...

I think it is time for me to find a job to be less stressed. Not finding the solution to a problem as simple as that, it's a shame.

Thanks Demivec.

Best regards.
Guimauve
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Joystick Throttle Input Correction

Post by wilbert »

Wouldn't it be faster to not use a procedure and simply do the addition of 32768 directly ?
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Re: Joystick Throttle Input Correction

Post by Guimauve »

@Wilbert

Code: Select all

Macro JoystickThrottleInputCorrection(Input)
  
  (Input + 32768)
  
EndMacro
Best regards
Guimauve
User avatar
Guimauve
Enthusiast
Enthusiast
Posts: 742
Joined: Wed Oct 22, 2003 2:51 am
Location: Canada

Re: Joystick Throttle Input Correction

Post by Guimauve »

Ok this the final version for the Throttle Input correction.

Code: Select all

Macro ThrottleInputCorrection(Input)
  
  (65535 - (Input + 32768))
  
EndMacro
With the previous version the Input as been inverted. At 0% we have 65535 and at 100% we have 0. With this version at 0% we have 0 and at 100% we have 65535.

Best regards.
Guimauve
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Joystick Throttle Input Correction

Post by wilbert »

Your latest macro can be rewritten as

Code: Select all

Macro ThrottleInputCorrection(Input)
  
  (32767 - Input)
  
EndMacro
:wink:
Post Reply