def draw(self): position = self.body.transform * self.fixture.shape.pos * PPM position = (position[0], SCREEN_HEIGHT - position[1]) pygame.draw.circle(self.screen, self.color, [int(x) for x in position], int(self.radius * PPM)) current_forward_normal = self.body.GetWorldVector((0, 1)) pygame.draw.line(self.screen, Color.White, world_to_pixels(self.body.worldCenter), world_to_pixels(self.body.worldCenter + current_forward_normal * self.radius))
def draw(self): vertices = [(self.body.transform * v) * PPM for v in self.fixture.shape.vertices] vertices = [(v[0], SCREEN_HEIGHT - v[1]) for v in vertices] pygame.draw.polygon(self.screen, Color.Red, vertices) p = self.body.GetWorldPoint( localPoint=(0, self.height)) # upper point of the box forward = self.body.GetWorldVector( (0, 1)) # transform.forward of this box pygame.draw.line(self.screen, Color.White, world_to_pixels(vec2(p)), world_to_pixels(vec2(p) + forward))
def draw(self): for triangle in self.triangle_list: triangle.draw() self.wall.draw() # self.goal.draw() self.inner_circle.draw() # Goal square M1 = vec2(np.cos(3*(np.pi/12)) * 11 + 18, 18) M2 = vec2(36, 18) M3 = vec2(36, np.sin(3*(np.pi/12)) * 11 + 18) M4 = vec2(np.cos(3*(np.pi/12)) * 11 + 18, np.sin(3*(np.pi/12)) * 11 + 18) pygame.draw.line(self.screen, Color.Orange, world_to_pixels(M1), world_to_pixels(M2)) pygame.draw.line(self.screen, Color.Orange, world_to_pixels(M2), world_to_pixels(M3)) pygame.draw.line(self.screen, Color.Orange, world_to_pixels(M3), world_to_pixels(M4)) pygame.draw.line(self.screen, Color.Orange, world_to_pixels(M4), world_to_pixels(M1))
def draw(self): position = self.body.transform * self.fixture.shape.pos * PPM position = (position[0], SCREEN_HEIGHT - position[1]) pygame.draw.circle(self.screen, self.color, [int(x) for x in position], int(self.car_radius * PPM)) current_forward_normal = self.body.GetWorldVector((0, 1)) pygame.draw.line( self.screen, Color.White, world_to_pixels(self.body.worldCenter), world_to_pixels(self.body.worldCenter + current_forward_normal * self.car_radius)) # Draw raycasts for i in range(self.num_sensors): v = self.body.GetWorldVector(self.raycast_vectors[i]) p1 = self.body.worldCenter + v * self.car_radius p2 = p1 + v * self.sensors[i] # self.raycast_length if self.sensors[i] <= self.raycast_length / 2: ray_color = self.raycastDangerColor else: ray_color = self.raycastSafeColor pygame.draw.line(self.screen, ray_color, world_to_pixels(p1), world_to_pixels(p2)) # DEBUG gizmo -------------------------------------------------------------------------------------------------- # Starting point s = None if self.env_name == 'RaceCircle': s = vec2(c.x + r, c.y) pygame.draw.line(self.screen, Color.Magenta, world_to_pixels(c), world_to_pixels(s + vec2(7, 0))) elif self.env_name == 'RaceCircle_v2': s = vec2(c.x - r, c.y) pygame.draw.line(self.screen, Color.Magenta, world_to_pixels(c), world_to_pixels(s + vec2(-7, 0))) # Orthogonal projection to the circle ph = None if self.env_name == 'RaceCircle': theta = Util.angle_direct(Util.normalize(s - c), Util.normalize(self.body.position - c)) theta = Util.deg_to_rad(theta) ph = vec2(r * np.cos(theta) + c.x, r * np.sin(theta) + c.y) elif self.env_name == 'RaceCircle_v2': theta = Util.angle_direct(Util.normalize(s - c), Util.normalize(self.body.position - c)) theta = Util.deg_to_rad(theta) ph = vec2(-r * np.cos(theta) + c.x, -r * np.sin(theta) + c.y) pygame.draw.line(self.screen, Color.Red, world_to_pixels(c), world_to_pixels(ph)) # Tangent to the circle tangent = None if self.env_name == 'RaceCircle': tangent = Util.rotate(Util.normalize(c - ph), -90.0) elif self.env_name == 'RaceCircle_v2': tangent = Util.rotate(Util.normalize(c - ph), 90.0) pygame.draw.line(self.screen, Color.Yellow, world_to_pixels(ph), world_to_pixels(ph + tangent))