def step(self, dt): ball = Ball(self.ball) car = self.car # simulate ball until it gets near the floor while (ball.position[2] > 120 or ball.velocity[2] > 0) and ball.time < car.time + 10: ball.step(1 / 60) ball_local = local(car, ground(ball.position)) target = local(car, self.target) shift = ground(direction(ball_local, target)) shift[1] *= 1.8 shift = normalize(shift) max_turn = clamp(norm(car.velocity) / 800, 0, 1) max_shift = normalize(vec3(1 - max_turn, max_turn * sign(shift[1]), 0)) if abs(shift[1]) > abs(max_shift[1]) or shift[0] < 0: shift = max_shift shift *= clamp(car.boost, 30, 50) shift[1] *= clamp(norm(car.velocity) / 1000, 1, 2) self._shift_direction = normalize(world(car, shift) - car.position) target = world(car, ball_local - shift) speed = distance(car.position, target) / max(0.001, ball.time - car.time) self.drive.target_speed = speed self.drive.target_pos = target self.drive.step(dt) self.controls = self.drive.controls self.finished = self.ball.position[2] < 100 or ground_distance( self.ball, self.car) > 2000
def _difference_eq_update(self, dt: int) -> Tuple[float, float, float, float]: """ :param int dt: time elapsed in milliseconds :return (float, float, float, float) state: Updated (x, y, vx, vy) based on physics over dt See https://www.reddit.com/r/TagPro/wiki/physics for details on physics rules. """ if self.is_popped: return (self.x, self.y, 0, 0) max_vel = max_speed if not self.on_team_tile else max_speed * 2.0 vx = self.vx + clamp( (self.ax - self.vx * damping_coefficient) * dt * 0.001, -max_vel, max_vel) vy = self.vy + clamp( (self.ay - self.vy * damping_coefficient) * dt * 0.001, -max_vel, max_vel) x = self.x + vx * dt * 0.001 y = self.y + vy * dt * 0.001 return (x, y, vx, vy)
def configure(self, intercept: Intercept): super().configure(intercept) if self.target is None: self.arrive.target = intercept.ground_pos + ground_direction( intercept, self.car) * 100 else: self.arrive.target = intercept.ground_pos - ground_direction( intercept, self.target) * 110 additional_jump = clamp((intercept.ball.position[2] - 92) / 500, 0, 1.5) * self.jump_time_multiplier self.dodge.jump.duration = 0.05 + additional_jump self.dodge.target = intercept.ball.position self.arrive.additional_shift = additional_jump * 500
def refresh(self): """ Finds all connected gamepads. Must be called at the start of the run loop if there has been a change. Will uninitialize and then initialize the joystick module """ if self.joystick: self.joystick.quit() self.joystick = None joystick.quit() joystick.init() joyDictList = self.get_all_gamepads() # Must be fetched before initializing the ID, since otherwise we delete that ID afterwards, apparently the objects here are global! self.initialize(clamp(self.joystick_id, 0, maxVal((joystick.get_count() - 1), 0))) self.refreshedGamepad.emit(joyDictList) self.statusChanged.emit(self.joystick.get_init() if self.joystick else False)
def logData(self, text, priority, type=0): """Log the data in a dictionary""" priority = clamp(priority, 0, (len(self.colorForPriority) - 1)) color = self.getColorForPriority(priority) tim = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') item = LogItem(text, priority, tim, color, type) self.data.append(item) # Check if we should add this data to the table right away: if (not self.checkFilterGUI.isChecked() and type is LOGGER_TYPE_GUI ) or (not self.checkFilterRover.isChecked() and type is LOGGER_TYPE_ROVER ) or (not self.checkPrio[priority].isChecked()) or ( not self.matchesCriteria(item, self.searchText.text())): return self.addNewRow(item) self.loggerTable.scrollToBottom()
def step(self, dt): self.update_attrs_from_transform() # reset accelerations self.viewport_acc = Vector(0.0, 0.0) self.scale_acc = 0.0 self.rotation_acc = 0.0 # call all controllers on self for controller in self.controllers: controller.step(self, dt) # update position limit_vector_length(self.viewport_acc, self.viewport_max_acc) self.viewport_vel += self.viewport_acc * dt limit_vector_length(self.viewport_vel, self.viewport_max_vel) self.viewport_center += self.viewport_vel * dt # update scale self.scale_acc = limit_abs(self.scale_acc, self.scale_max_acc) self.scale_vel = limit_abs(self.scale_vel + self.scale_acc * dt, self.scale_max_vel) self.scale = clamp(self.scale + self.scale_vel * dt, self.scale_min, self.scale_max) # update rotation self.rotation_acc = limit_abs(self.rotation_acc, self.rotation_max_acc) self.rotation_vel = limit_abs(self.rotation_vel + self.rotation_acc * dt, self.rotation_max_vel) self.rotation = (self.rotation + self.rotation_vel * dt) % (2.0 * pi) # apply pan, zoom, and rotation self.transform.viewport_center = self.viewport_center self.transform.scale = self.scale self.transform.rotation = self.rotation # align the center of the viewport with the center of the camera viewport_center_x, viewport_center_y = self.viewport_center camera_center_x, camera_center_y = self.center self.transform.align_local_to_parent(viewport_center_x, viewport_center_y, camera_center_x, camera_center_y)
def set_song_progress_percentage(self, song_progress_percentage: int): self._song_progress_percentage = int(clamp(song_progress_percentage, 0, 100)) self.audio_buffer.set_pointer_position_from_percentage(self._song_progress_percentage) self._notify_all_song_progress_subscribers(song_progress_percentage)
def turn_radius(speed: float) -> float: spd = clamp(speed, 0, 2300) return 156 + 0.1 * spd + 0.000069 * spd**2 + 0.000000164 * spd**3 + -5.62E-11 * spd**4
def circle(self, pos: vec3, radius: float): segments = int(clamp(radius / 20, 10, 50)) self.arc(pos, radius, 0, math.pi * 2, segments)
def volume_normalised(self, value: float): self._volume_normalised = clamp(value, MIN_VOLUME_NORMALISED, MAX_VOLUME_NORMALISED) self._set_source_volume(self._volume_normalised) self.notify_all_volume_level_percentage_subscribers(self.volume_percentage)
def estimate_max_car_speed(car: Car): return clamp(max(norm(car.velocity), 1300) + car.boost * 100, 1600, 2300)
def limit_abs(x, lim): """Returns the value 'x' clamped to the interval '[-lim, +lim]'.""" return clamp(x, -lim, +lim)