
% Animates and saves a 3D animation of the aircraft path and attitude
% throughout the maneuver. Pass/fail conditions are displayed in the image.
% This script requires that "SimResults.mat" exists in the workspace. This
% .mat file is automatically generated by RunF16Sim with the variable
% "analysisOn" set to true.
%
% <a href="https://github.com/pheidlauf/AeroBenchVV">AeroBenchVV</a>
% Copyright: GNU General Public License 2017
%
% See also: RUNF16SIM, NEW_OBJECT, FLYPATH

%% Create animation of F16 Maneuver
close all;
cd('../flypath3d');
package_setup;
cd('../F16_Sim');
load('SimResults');

% Flypath3D Trajectory Visualization
data = output.states.x_f16_hist([11 10 12 5 6 4],:);
tvec = output.states.time;
figure

% Create an object
new_object('aircraft.mat',data,...
    'model','f-16.mat','scale', 25,...
    'edge',[0 0 0],'face',[0 0 0],'alpha',1,...
    'path','on','pathcolor',[.89 .0 .27],'pathwidth',1);

% Aircraft trajectory visualization
my_flypath('aircraft.mat',...
    'tvec',tvec,...
    'ground',output.flightLimits.altitudeMin,...
    'animate','on','step', 5,...
    'axis','on','axiscolor',[0 0 0],'color',[1 1 1],...
    'font','Georgia','fontsize',6,...
    'view', [-37.5, 30],'window',[1000 1000],...
    'output','output_animation.mp4','dpi',600,...
    'telemetry',output,'zoom',2500);

view(3);
close all;