Skip to content

Commit ec89300

Browse files
authored
Add a flag to allow center at map in BEV rendering (#838)
1 parent 94db146 commit ec89300

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

metadrive/engine/top_down_renderer.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ def __init__(
192192
draw_contour=True,
193193
window=True,
194194
screen_record=False,
195+
center_on_map=False,
195196
):
196197
"""
197198
Launch a top-down renderer for current episode. Usually, it is launched by env.render(mode="topdown") and will
@@ -235,6 +236,9 @@ def __init__(
235236
236237
screen_record: Whether to record the episode. The recorded result can be accessed by
237238
env.top_down_renderer.screen_frames or env.top_down_renderer.generate_gif(file_name, fps)
239+
240+
center_on_map: Whether to center the camera on the map. If set to True, the camera will not move with the
241+
ego car, and the camera position will be fixed at the center of the map.
238242
"""
239243
# doc-end
240244
# LQY: do not delete the above line !!!!!
@@ -251,6 +255,7 @@ def __init__(
251255
target_agent_heading_up = target_vehicle_heading_up
252256

253257
self.position = camera_position
258+
self.center_on_map = center_on_map
254259
self.target_agent_heading_up = target_agent_heading_up
255260
self.show_agent_name = show_agent_name
256261
self.draw_target_vehicle_trajectory = draw_target_vehicle_trajectory
@@ -525,8 +530,12 @@ def _draw(self, *args, **kwargs):
525530
field = self._screen_canvas.get_size()
526531
if not self.target_agent_heading_up:
527532
if self.position is not None or v is not None:
528-
cam_pos = (self.position or v.position)
529-
position = self._frame_canvas.pos2pix(*cam_pos)
533+
if self.center_on_map:
534+
frame_canvas_size = self._frame_canvas.get_size()
535+
position = (frame_canvas_size[0] / 2, frame_canvas_size[1] / 2)
536+
else:
537+
cam_pos = (self.position or v.position)
538+
position = self._frame_canvas.pos2pix(*cam_pos)
530539
else:
531540
position = (field[0] / 2, field[1] / 2)
532541
off = (position[0] - field[0] / 2, position[1] - field[1] / 2)

0 commit comments

Comments
 (0)