From 9153d8fe8fa5f50d7e1d785879456353b576ef8d Mon Sep 17 00:00:00 2001 From: Mark Mine Date: Thu, 14 Aug 2003 18:18:58 +0000 Subject: [PATCH] Improve joystick analog conversion cVS: ---------------------------------------------------------------------- --- .../src/directdevices/DirectDeviceManager.py | 27 ++++++++++--------- direct/src/directdevices/DirectJoybox.py | 6 +++++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/direct/src/directdevices/DirectDeviceManager.py b/direct/src/directdevices/DirectDeviceManager.py index 9b4436f257..4544ee53aa 100644 --- a/direct/src/directdevices/DirectDeviceManager.py +++ b/direct/src/directdevices/DirectDeviceManager.py @@ -135,25 +135,28 @@ class DirectAnalogs(AnalogNode, DirectObject): ((val - self.analogMin) / float(self.analogRange))) + minVal) - def normalize(self, val, minVal = -1, maxVal = 1, sf = 1.0): - max = self.analogMax - min = self.analogMin + def normalize(self, rawValue, minVal = -1, maxVal = 1, sf = 1.0): + aMax = self.analogMax + aMin = self.analogMin center = self.analogCenter deadband = self.analogDeadband range = self.analogRange # Zero out values in deadband - if (abs(val) <= deadband): + if (abs(rawValue-center) <= deadband): return 0.0 - # Apply scale factor - val *= sf - # Clamp value between min and max and scale around center - if (val >= center): - val = (val - center) / float(max - center) + # Clamp value between aMin and aMax and scale around center + if (rawValue >= center): + # Convert positive values to range 0 to 1 + val = min(rawValue * sf, aMax) + percentVal = ((val - (center + deadband))/ + float(aMax - (center + deadband))) else: - val = (val - center) / float(center - min) + # Convert negative values to range -1 to 0 + val = max(rawValue * sf, aMin) + percentVal = -((val - (center - deadband))/ + float(aMin - (center - deadband))) # Normalize values to given minVal and maxVal range - return (((maxVal - minVal) * - ((val - min) / float(range))) + minVal) + return (((maxVal - minVal) * ((percentVal + 1)/2.0)) + minVal) def normalizeChannel(self, chan, minVal = -1, maxVal = 1, sf = 1.0): try: diff --git a/direct/src/directdevices/DirectJoybox.py b/direct/src/directdevices/DirectJoybox.py index 86ec37652a..0874bd341f 100644 --- a/direct/src/directdevices/DirectJoybox.py +++ b/direct/src/directdevices/DirectJoybox.py @@ -283,6 +283,12 @@ class DirectJoybox(PandaObject): self.modifier = [1,1,-1,-1,-1,1] self.setMode(self.joyboxFly, 'HprXyz Mode') + def mopathMode(self): + self.mapping = [R_LEFT_RIGHT, R_FWD_BACK, R_TWIST, + L_LEFT_RIGHT, L_FWD_BACK, L_LEFT_RIGHT] + self.modifier = [1,1,-1,-1,1,0] + self.setMode(self.joyboxFly, 'Mopath Mode') + def walkthruMode(self): self.mapping = [R_LEFT_RIGHT, R_FWD_BACK, L_TWIST, R_TWIST, L_FWD_BACK, L_LEFT_RIGHT]