From de52447e751f14a505679a949bdfe61c5d72693e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Schr=C3=B6der?= <fschroeder@techfak.uni-bielefeld.de> Date: Wed, 31 Jan 2024 15:42:53 +0100 Subject: [PATCH] Add player position to view restriction and implement angle calculation Player's position has been added to the view restriction in order to provide a more precise representation of the environment. A function for calculating the angle between two points has been implemented in the utils module. Changes have also been made to accommodate these new updates in the 2D visualization module. --- overcooked_simulator/gui_2d_vis/drawing.py | 6 ++++-- overcooked_simulator/overcooked_environment.py | 1 + overcooked_simulator/utils.py | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/overcooked_simulator/gui_2d_vis/drawing.py b/overcooked_simulator/gui_2d_vis/drawing.py index 56b63bc0..ab6f7060 100644 --- a/overcooked_simulator/gui_2d_vis/drawing.py +++ b/overcooked_simulator/gui_2d_vis/drawing.py @@ -92,8 +92,10 @@ class Visualizer: ) if "view_restriction" in state and state["view_restriction"]: - direction = state["view_restriction"][0] - angel = state["view_restriction"][1] + direction = np.array(state["view_restriction"][0]) + pos = np.array(state["view_restriction"][1]) + angel = state["view_restriction"][2] + # rotate direction vector in both direction with the angel # draw 2 large rect which are rotated so that one edge is the viewing border diff --git a/overcooked_simulator/overcooked_environment.py b/overcooked_simulator/overcooked_environment.py index 64757f8c..fc7cbc1c 100644 --- a/overcooked_simulator/overcooked_environment.py +++ b/overcooked_simulator/overcooked_environment.py @@ -622,6 +622,7 @@ class Environment: ).total_seconds(), "view_restriction": [ self.players[player_id].facing_direction.tolist(), + self.players[player_id].pos.tolist(), 40.0, ] if FOG_OF_WAR diff --git a/overcooked_simulator/utils.py b/overcooked_simulator/utils.py index edf11d72..bb0fac2a 100644 --- a/overcooked_simulator/utils.py +++ b/overcooked_simulator/utils.py @@ -100,3 +100,9 @@ def add_list_of_manager_ids_arguments(parser): default=[uuid.uuid4().hex], help="List of manager IDs that can create environments.", ) + + +def angle_between(p1, p2): + ang1 = np.arctan2(*p1[::-1]) + ang2 = np.arctan2(*p2[::-1]) + return np.rad2deg((ang1 - ang2) % (2 * np.pi)) -- GitLab