function updateEgoVehiclePose(pose)
%UPDATEEGOVEHICLEPOSE Update pose of ego vehicle in Driving Scenario
%
% Copyright 2021 The MathWorks, Inc.
    
    persistent scenario

    if isempty(scenario)
        scenario = getScenarioFromBaseWorkspace;
    end
    
    if ~isempty(scenario)
        % Update position of ego vehicle
        egoVehicle = scenario.Actors(1);    
        egoVehicle.Position = [pose(2) pose(1) 0].*[1 -1 1];
        egoVehicle.Yaw = pose(3) - 90;

        % Update scenario plot
        scenario.Plots(end).plotActors(scenario.Actors);
    end
end


function scenario = getScenarioFromBaseWorkspace
    scenario = [];
    if isvarname("scenario")
        scenario = evalinGlobalScope(bdroot, 'scenario');
    end
end

