function [] = SampleAVDSPlayback();
%SampleAVDSPlayback - a simple example using the AVDS/MATLAB functions
%
%  USAGE - This function builds data files and a playback confgiuration files
%    that AVDS can use to display the sample trajectories.
%
%    - Run SampleAVDSPlayback()
%    - Start AVDS
%    - In AVDS, load the file, 'MATLABExample.ply.ini', to do this from AVDS's 
%      menu select "File->Playback Init->Open"
%    - Start AVDS in Playback mode.
%
%  NOTE: The number of vehicles and trajectories can be changed in the PARAMETERS 
%    section below

%   Steve Rasmussen, December 2000
%   Copyright (c) 2000 by RasSimTech Ltd
%   $Revision: 1.0.0 $  $Date: 2000/12/16 00:00:00 $



%%%%%%%%%%%%%%
% PARAMETERS
%%%%%%%%%%%%%%

iNumberVehicles = 10;

iHorizontalSpacing = 50;
iVerticalSpacing = 10;
iInitAltitude = 1000;

NorthVelocity = 250.0;	%feet/sec	
EastVelocity = 0.0;	%feet/sec	
VerticalVelocity = 0.0;	%feet/sec

XAngularRate = 10.0; %degrees/sec
YAngularRate = 0.0; %degrees/sec
ZAngularRate = 0.0; %degrees/sec

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% write out playback configuration file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ConfigFileName = ['MATLABExample.ply.ini'];
WritePlaybackInit(ConfigFileName);
for (iCount = 1:iNumberVehicles),
   DataFileName = sprintf('Data%d.save.dat',iCount);
   WritePlaybackInit(ConfigFileName,'VehicleSimple',DataFileName);
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% add playback data entities
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SaveAVDSData('Clear');
for (iCount = 1:iNumberVehicles),
   SaveAVDSData('AddEntity');
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% initailize vehicle trajectories
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NorthPosition = zeros(iNumberVehicles,1);
EastPosition = [iHorizontalSpacing:iHorizontalSpacing:iNumberVehicles*iHorizontalSpacing]';
DownPosition = [-iNumberVehicles*iVerticalSpacing:iVerticalSpacing:-iVerticalSpacing]'-iInitAltitude;
XRotation = zeros(iNumberVehicles,1);
YRotation = zeros(iNumberVehicles,1);
ZRotation = zeros(iNumberVehicles,1);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% build vehicle trajectories and store data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TimeIncrement = 0.05;

NorthVelocityInc = NorthVelocity*TimeIncrement;
EastVelocityInc = EastVelocity*TimeIncrement;
VerticalVelocityInc = VerticalVelocity*TimeIncrement;

XAngularRateInc = XAngularRate*TimeIncrement;
YAngularRateInc = YAngularRate*TimeIncrement;
ZAngularRateInc = ZAngularRate*TimeIncrement;

for (CountTime = [0.0:TimeIncrement:10.0]),
   NorthPosition = NorthPosition + NorthVelocityInc;
   EastPosition = EastPosition + EastVelocityInc;
   DownPosition = DownPosition - VerticalVelocityInc;
   XRotation = XRotation + XAngularRateInc;
   YRotation = YRotation + YAngularRateInc;
   ZRotation = ZRotation + ZAngularRateInc;
   for (iEntities = 1:iNumberVehicles),
      DataRow = [CountTime,NorthPosition(iEntities),EastPosition(iEntities), ...
            		DownPosition(iEntities), ...
            		XRotation(iEntities), YRotation(iEntities), ZRotation(iEntities)];
      SaveAVDSData('Store',DataRow,iEntities);  
   end;	%for (iEntities = 1:NumberEntities),
end;	%for (CountTime = dTime1),

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% write out playback data files
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for (iCount = 1:iNumberVehicles),
   DataFileName = sprintf('Data%d.save.dat',iCount);
   SaveAVDSData('WriteEntity',DataFileName,iCount);
end;

return;		%SampleAVDSPlayback