@@ -192,6 +192,7 @@ def __init__(
192
192
draw_contour = True ,
193
193
window = True ,
194
194
screen_record = False ,
195
+ center_on_map = False ,
195
196
):
196
197
"""
197
198
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__(
235
236
236
237
screen_record: Whether to record the episode. The recorded result can be accessed by
237
238
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.
238
242
"""
239
243
# doc-end
240
244
# LQY: do not delete the above line !!!!!
@@ -251,6 +255,7 @@ def __init__(
251
255
target_agent_heading_up = target_vehicle_heading_up
252
256
253
257
self .position = camera_position
258
+ self .center_on_map = center_on_map
254
259
self .target_agent_heading_up = target_agent_heading_up
255
260
self .show_agent_name = show_agent_name
256
261
self .draw_target_vehicle_trajectory = draw_target_vehicle_trajectory
@@ -525,8 +530,12 @@ def _draw(self, *args, **kwargs):
525
530
field = self ._screen_canvas .get_size ()
526
531
if not self .target_agent_heading_up :
527
532
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 )
530
539
else :
531
540
position = (field [0 ] / 2 , field [1 ] / 2 )
532
541
off = (position [0 ] - field [0 ] / 2 , position [1 ] - field [1 ] / 2 )
0 commit comments