function f = animate_callback(world_state, P)

if P.animate_motion
  hold off  
  
  if ~isempty(P.tree)
    draw_tree(P.tree, P);
  end
  
  if ~isempty(P.cars(1).traces)
    draw_solution(P.cars(1).traces, P);
  end

  for i=1:length(P.cars)
    draw_car(world_state.car_states(i), '', P);
    hold on
  end
  
  for i=1:length(P.obstacles)
    draw_obstacle(P.obstacles(i), '', P);
    hold on
  end

  
  draw_roads('b-', P)
    
  axis equal
  axis([-50, 50, -50, 50])
  drawnow
  set(gcf,'Position',[0 0 1600 1600]);
  
  if ~isempty(P.video)
    writeVideo(P.video, getframe);
  end
  
  if P.animate_real_time
    pause(P.dt)
  end
end  
  
