Skip to content

Commit a37e79f

Browse files
[Render] Introduce scenario.render_origin (#93)
* amend * amend * amend * amend
1 parent 146d0c1 commit a37e79f

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

vmas/simulator/environment/environment.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
DEVICE_TYPING,
2020
override,
2121
TorchUtils,
22-
VIEWER_MIN_ZOOM,
2322
X,
2423
Y,
2524
)
@@ -666,7 +665,9 @@ def render(
666665

667666
self._init_rendering()
668667

669-
zoom = max(VIEWER_MIN_ZOOM, self.scenario.viewer_zoom)
668+
if self.scenario.viewer_zoom <= 0:
669+
raise ValueError("Scenario viewer zoom must be > 0")
670+
zoom = self.scenario.viewer_zoom
670671

671672
if aspect_ratio < 1:
672673
cam_range = torch.tensor([zoom, zoom / aspect_ratio], device=self.device)
@@ -685,8 +686,12 @@ def render(
685686
viewer_size_fit = (
686687
torch.stack(
687688
[
688-
torch.max(torch.abs(all_poses[:, X])),
689-
torch.max(torch.abs(all_poses[:, Y])),
689+
torch.max(
690+
torch.abs(all_poses[:, X] - self.scenario.render_origin[X])
691+
),
692+
torch.max(
693+
torch.abs(all_poses[:, Y] - self.scenario.render_origin[Y])
694+
),
690695
]
691696
)
692697
+ 2 * max_agent_radius
@@ -698,10 +703,10 @@ def render(
698703
)
699704
cam_range *= torch.max(viewer_size)
700705
self.viewer.set_bounds(
701-
-cam_range[X],
702-
cam_range[X],
703-
-cam_range[Y],
704-
cam_range[Y],
706+
-cam_range[X] + self.scenario.render_origin[X],
707+
cam_range[X] + self.scenario.render_origin[X],
708+
-cam_range[Y] + self.scenario.render_origin[Y],
709+
cam_range[Y] + self.scenario.render_origin[Y],
705710
)
706711
else:
707712
# update bounds to center around agent

vmas/simulator/scenario.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
AGENT_OBS_TYPE,
1515
AGENT_REWARD_TYPE,
1616
INITIAL_VIEWER_SIZE,
17-
VIEWER_MIN_ZOOM,
17+
VIEWER_DEFAULT_ZOOM,
1818
)
1919

2020
if typing.TYPE_CHECKING:
@@ -46,8 +46,10 @@ def __init__(self):
4646
self._world = None
4747
self.viewer_size = INITIAL_VIEWER_SIZE
4848
"""The size of the rendering viewer window. This can be changed in the :class:`~make_world` function. """
49-
self.viewer_zoom = VIEWER_MIN_ZOOM
50-
"""The zoom of the rendering camera. This can be changed in the :class:`~make_world` function. """
49+
self.viewer_zoom = VIEWER_DEFAULT_ZOOM
50+
"""The zoom of the rendering camera (a lower value means more zoom). This can be changed in the :class:`~make_world` function. """
51+
self.render_origin = (0.0, 0.0)
52+
"""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. """
5153
self.plot_grid = False
5254
"""Whether to plot a grid in the scenario rendering background. This can be changed in the :class:`~make_world` function. """
5355
self.grid_spacing = 0.1

vmas/simulator/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Y = 1
2121
Z = 2
2222
ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
23-
VIEWER_MIN_ZOOM = 1.2
23+
VIEWER_DEFAULT_ZOOM = 1.2
2424
INITIAL_VIEWER_SIZE = (700, 700)
2525
LINE_MIN_DIST = 4 / 6e2
2626
COLLISION_FORCE = 100

0 commit comments

Comments
 (0)