Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions vmas/simulator/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
DEVICE_TYPING,
override,
TorchUtils,
VIEWER_MIN_ZOOM,
X,
Y,
)
Expand Down Expand Up @@ -666,7 +665,9 @@ def render(

self._init_rendering()

zoom = max(VIEWER_MIN_ZOOM, self.scenario.viewer_zoom)
if self.scenario.viewer_zoom <= 0:
raise ValueError("Scenario viewer zoom must be > 0")
zoom = self.scenario.viewer_zoom

if aspect_ratio < 1:
cam_range = torch.tensor([zoom, zoom / aspect_ratio], device=self.device)
Expand All @@ -685,8 +686,12 @@ def render(
viewer_size_fit = (
torch.stack(
[
torch.max(torch.abs(all_poses[:, X])),
torch.max(torch.abs(all_poses[:, Y])),
torch.max(
torch.abs(all_poses[:, X] - self.scenario.render_origin[X])
),
torch.max(
torch.abs(all_poses[:, Y] - self.scenario.render_origin[Y])
),
]
)
+ 2 * max_agent_radius
Expand All @@ -698,10 +703,10 @@ def render(
)
cam_range *= torch.max(viewer_size)
self.viewer.set_bounds(
-cam_range[X],
cam_range[X],
-cam_range[Y],
cam_range[Y],
-cam_range[X] + self.scenario.render_origin[X],
cam_range[X] + self.scenario.render_origin[X],
-cam_range[Y] + self.scenario.render_origin[Y],
cam_range[Y] + self.scenario.render_origin[Y],
)
else:
# update bounds to center around agent
Expand Down
8 changes: 5 additions & 3 deletions vmas/simulator/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
AGENT_OBS_TYPE,
AGENT_REWARD_TYPE,
INITIAL_VIEWER_SIZE,
VIEWER_MIN_ZOOM,
VIEWER_DEFAULT_ZOOM,
)

if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -46,8 +46,10 @@ def __init__(self):
self._world = None
self.viewer_size = INITIAL_VIEWER_SIZE
"""The size of the rendering viewer window. This can be changed in the :class:`~make_world` function. """
self.viewer_zoom = VIEWER_MIN_ZOOM
"""The zoom of the rendering camera. This can be changed in the :class:`~make_world` function. """
self.viewer_zoom = VIEWER_DEFAULT_ZOOM
"""The zoom of the rendering camera (a lower value means more zoom). This can be changed in the :class:`~make_world` function. """
self.render_origin = (0.0, 0.0)
"""The origin of the rendering camera when ``agent_index_to_focus`` is None in the ``render()`` arguments. This can be changed in the :class:`~make_world` function. """
self.plot_grid = False
"""Whether to plot a grid in the scenario rendering background. This can be changed in the :class:`~make_world` function. """
self.grid_spacing = 0.1
Expand Down
2 changes: 1 addition & 1 deletion vmas/simulator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Y = 1
Z = 2
ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
VIEWER_MIN_ZOOM = 1.2
VIEWER_DEFAULT_ZOOM = 1.2
INITIAL_VIEWER_SIZE = (700, 700)
LINE_MIN_DIST = 4 / 6e2
COLLISION_FORCE = 100
Expand Down