def whole(self, mapper, x, y, what): distance = sqrt(x * x + y * y) if distance < STICK_PAD_MAX_HALF: # Finger lifted or too close to middle self.angle = None else: # Compute current angle angle = atan2(x, y) + PI / 4 # Compute movement if self.haptic: if self.angle is not None: diff = self.angle - angle # Ensure we don't wrap from pi to -pi creating a large delta if angle > PI: # Subtract a full rotation to counter the wrapping angle -= 2 * PI # And same from -pi to pi elif angle < -PI: # Add a full rotation to counter the wrapping angle += 2 * PI if abs( diff ) < 6: # Prevents crazy feedback burst when finger cross 360' angle WholeHapticAction.change(self, mapper, diff * 10000, 0) self.angle = angle # Apply actual constant angle *= STICK_PAD_MAX / PI # Set axis on child action self.action.axis(mapper, angle * self.speed, 0) mapper.force_event.add(FE_PAD)
def whole(self, mapper, x, y, what): distance = sqrt(x*x + y*y) if distance < STICK_PAD_MAX_HALF: # Finger lifted or too close to middle self.angle = None else: # Compute current angle angle = atan2(x, y) + PI / 4 # Compute movement if self.haptic: if self.angle is not None: diff = self.angle - angle # Ensure we don't wrap from pi to -pi creating a large delta if angle > PI: # Subtract a full rotation to counter the wrapping angle -= 2 * PI # And same from -pi to pi elif angle < -PI: # Add a full rotation to counter the wrapping angle += 2 * PI if abs(diff) < 6:# Prevents crazy feedback burst when finger cross 360' angle WholeHapticAction.change(self, mapper, diff * 10000, 0, what) self.angle = angle # Apply actual constant angle *= STICK_PAD_MAX / PI # Set axis on child action self.action.axis(mapper, angle * self.speed, 0) mapper.force_event.add(FE_PAD)
def whole(self, mapper, x, y, what): distance = sqrt(x * x + y * y) if distance < STICK_PAD_MAX_HALF: # Finger lifted or too close to middle self.angle = None self.travelled = 0 else: # Compute current angle angle = atan2(x, y) # Compute movement if self.angle is None: # Finger just touched the pad self.angle, angle = angle, 0 else: self.angle, angle = angle, self.angle - angle # Ensure we don't wrap from pi to -pi creating a large delta if angle > PI: # Subtract a full rotation to counter the wrapping angle -= 2 * PI # And same from -pi to pi elif angle < -PI: # Add a full rotation to counter the wrapping angle += 2 * PI if self.haptic: WholeHapticAction.change(self, mapper, angle * 10000, 0) # Apply bulgarian constant angle *= 10000.0 # Apply movement to child action self.action.change(mapper, -angle * self.speed, 0) mapper.force_event.add(FE_PAD)
def _roll(self, mapper): # Compute time step _tmp = time.time() dt = _tmp - self._lastTime self._lastTime = _tmp # Free movement update velocity and compute movement self._xvel_dq.clear() self._yvel_dq.clear() _hyp = sqrt((self._xvel**2) + (self._yvel**2)) if _hyp != 0.0: _ax = self._a * (abs(self._xvel) / _hyp) _ay = self._a * (abs(self._yvel) / _hyp) else: _ax = self._a _ay = self._a # Cap friction desceleration _dvx = min(abs(self._xvel), _ax * dt) _dvy = min(abs(self._yvel), _ay * dt) # compute new velocity _xvel = self._xvel - copysign(_dvx, self._xvel) _yvel = self._yvel - copysign(_dvy, self._yvel) # compute displacement dx = (((_xvel + self._xvel) / 2) * dt) / self._radscale dy = (((_yvel + self._yvel) / 2) * dt) / self._radscale self._xvel = _xvel self._yvel = _yvel if dx or dy: self.action.add(mapper, dx * self.speed[0], dy * self.speed[1]) if self.haptic: WholeHapticAction.add(self, mapper, dx, dy) mapper.schedule(0, self._roll)
def _roll(self, mapper): # Compute time step t = time.time() dt, self._lastTime = t - self._lastTime, t # Free movement update velocity and compute movement self._xvel_dq.clear() self._yvel_dq.clear() _hyp = sqrt((self._xvel**2) + (self._yvel**2)) if _hyp != 0.0: _ax = self._a * (abs(self._xvel) / _hyp) _ay = self._a * (abs(self._yvel) / _hyp) else: _ax = self._a _ay = self._a # Cap friction desceleration _dvx = min(abs(self._xvel), _ax * dt) _dvy = min(abs(self._yvel), _ay * dt) # compute new velocity _xvel = self._xvel - copysign(_dvx, self._xvel) _yvel = self._yvel - copysign(_dvy, self._yvel) # compute displacement dx = (((_xvel + self._xvel) / 2) * dt) / self._radscale dy = (((_yvel + self._yvel) / 2) * dt) / self._radscale self._xvel = _xvel self._yvel = _yvel self.action.add(mapper, dx * self.speed[0], dy * self.speed[1]) if dx or dy: if self.haptic: WholeHapticAction.add(self, mapper, dx, dy) self._roll_task = mapper.schedule(0.02, self._roll)
def get_haptic(self): if self.action and hasattr(self.action, "get_haptic"): return self.action.get_haptic() else: return WholeHapticAction.get_haptic(self)
def set_haptic(self, hd): if self.action and hasattr(self.action, "set_haptic"): self.action.set_haptic(hd) else: WholeHapticAction.set_haptic(self, hd)
def __init__(self, *params): Modifier.__init__(self, *params) WholeHapticAction.__init__(self)
def __init__(self, *params): # Piece of backwards compatibility if len(params) >= 1 and params[0] in Rels: params = [MouseAction(params[0])] Modifier.__init__(self, *params) WholeHapticAction.__init__(self)