%% Show Target Outlines in Driving Scenario Simulation
% Create a driving scenario and show how target outlines change as the simulation advances.
%
% Create a driving scenario consisting of two intersecting straight roads. The first road segment is 45 meters long. The second straight road is 32 meters long and intersects the first road. A car traveling at 12.0 meters per second along the first road approaches a running pedestrian crossing the intersection at 2.0 meters per second.

scenario = drivingScenario('SampleTime',0.1,'StopTime',1);
road(scenario,[-10 0 0; 45 -20 0]);
road(scenario,[-10 -10 0; 35 10 0]);
ped = actor(scenario,'ClassID',4,'Length',0.4,'Width',0.6,'Height',1.7);
car = vehicle(scenario,'ClassID',1);
pedspeed = 2.0;
carspeed = 12.0;
trajectory(ped,[15 -3 0; 15 3 0],pedspeed);
trajectory(car,[-10 -10 0; 35 10 0],carspeed);

%
% Create an ego-centric chase plot for the vehicle.

chasePlot(car,'Centerline','on')

%
% Create an empty bird's-eye plot and add an outline plotter and lane boundary plotter. Then, run the simulation. At each simulation step:
% Update the chase plot to display the road boundaries and target outlines.
% Update the bird's-eye plot to display the updated road boundaries and target outlines. The plot perspective is always with respect to the ego vehicle.

bepPlot = birdsEyePlot('XLim',[-50 50],'YLim',[-40 40]);
outlineplotter = outlinePlotter(bepPlot);
laneplotter = laneBoundaryPlotter(bepPlot);
legend('off')

while advance(scenario)
    rb = roadBoundaries(car);
    [position,yaw,length,width,originOffset,color] = targetOutlines(car);    
    plotLaneBoundary(laneplotter,rb)
    plotOutline(outlineplotter,position,yaw,length,width, ...
        'OriginOffset',originOffset,'Color',color)
    pause(0.01)
end

% Copyright 2012 The MathWorks, Inc.