This series of commands creates an animation object and configures the object.
Create an animation object.
h = Aero.Animation;
Configure the animation object to set the number of
frames per second (FramesPerSecond
) property. This
configuration controls the rate at which frames are displayed in the
figure window.
h.FramesPerSecond = 10;
Configure the animation object to set the seconds
of animation data per second time scaling (TimeScaling
)
property.
h.TimeScaling = 5;
The combination of FramesPerSecond
and TimeScaling
property
determine the time step of the simulation. These settings result in
a time step of approximately 0.5 s.
Create and load bodies for the animation object. This example uses these bodies to work with and display the simulated and actual flight trajectories. The first body is orange; it represents simulated data. The second body is blue; it represents the actual flight data.
idx1 = h.createBody('pa24-250_orange.ac','Ac3d'); idx2 = h.createBody('pa24-250_blue.ac','Ac3d');
Both bodies are AC3D format files. AC3D is one of several file formats that the animation objects support. FlightGear uses the same file format. The animation object reads in the bodies in the AC3D format and stores them as patches in the geometry object within the animation object.
This series of commands loads the recorded flight trajectory
data, which is contained in files in the
folder.matlabroot
\toolbox\aero\astdemos
simdata
– Contains simulated
flight trajectory data, which is set up as a 6DoF array.
fltdata
– Contains actual
flight trajectory data which is set up in a custom format. To access
this custom format data, the example must set the body object TimeSeriesSourceType parameter
to Custom
and then specify a custom read function.
Load the flight trajectory data.
load simdata load fltdata
Set the time series data for the two bodies.
h.Bodies{1}.TimeSeriesSource = simdata; h.Bodies{2}.TimeSeriesSource = fltdata;
Identify the time series for the second body as custom.
h.Bodies{2}.TimeSeriesSourceType = 'Custom';
Specify the custom read function to access the data
in fltdata
for the second body. The example provides
the custom read function in
. matlabroot
\toolbox\aero\astdemos\CustomReadBodyTSData.m
h.Bodies{2}.TimeseriesReadFcn = @CustomReadBodyTSData;
This command creates a figure object for the animation object.
h.show();
Enable recording of the playback of flight trajectories using the animation object.
h.VideoRecord = 'on'; h.VideoQuality = 50; h.VideoCompression = 'Motion JPEG AVI' h.VideoFilename = 'astMotion_JPEG';
Enable animation recording at any point that you want to preserve an animation sequence.
Note
When choosing the video compression type, keep in mind that you will need the corresponding viewer software. For example, if you create an AVI format, you need a viewer such as Windows Media® Player to view the file.
After you play the animation as described in Playing Back Flight Trajectories Using the Animation Object, astMotion_JPEG
contains
a recording of the playback.
This command plays back the animation bodies for the duration of the time series data. This playback shows the differences between the simulated and actual flight data.
h.play();
If you used the Video
properties to store
the recording, see Viewing Recorded Animation Files for a description of how to
view the files.
If you do not have an animation file to view, see Recording Animation Files.
Open the folder that contains the animation file you want to view.
View the animation file with an application of your choice.
If your animation file is not yet running, start it now from the application.
To prevent other h.play
commands
from overwriting the contents of the animation file, disable the recording
after you are satisfied with the contents.
h.VideoRecord = 'off';
This command series shows how you can manipulate the camera
on the two bodies and redisplay the animation. The PositionFcn
property
of a camera object controls the camera position relative to the bodies
in the animation. In Playing Back Flight Trajectories Using the Animation Object,
the camera object uses a default value for the PositionFcn
property.
In this command series, the example references a custom PositionFcn
function
that uses a static position based on the position of the bodies. No
dynamics are involved.
Note
The custom PositionFcn
function is located
in the
folder.matlabroot
\toolbox\aero\astdemos
Set the camera PositionFcn
to the
custom function staticCameraPosition
.
h.Camera.PositionFcn = @staticCameraPosition;
Run the animation again.
h.play();
This series of commands illustrates how to move and reposition bodies.
Set the starting time to 0.
t = 0;
Move the body to the starting position that is based on the time series data. Use
the Aero.Animation object updateBodies
method.
h.updateBodies(t);
Update the camera position using the custom PositionFcn
function
set in the previous section. Use the Aero.Animation object updateCamera
method.
h.updateCamera(t);
Reposition the bodies by first getting the current body position, then separating the bodies.
Get the current body positions and rotations from the objects of both bodies.
pos1 = h.Bodies{1}.Position; rot1 = h.Bodies{1}.Rotation; pos2 = h.Bodies{2}.Position; rot2 = h.Bodies{2}.Rotation;
Separate and reposition the bodies by moving them to new positions.
h.moveBody(1,pos1 + [0 0 -3],rot1); h.moveBody(2,pos1 + [0 0 0],rot2);
This series of commands illustrates how to create and attach a transparency to a body. The animation object stores the body geometry as patches. This example manipulates the transparency properties of these patches (see Patch Properties).
Note
The use of transparencies might decrease animation speed
on platforms that use software OpenGL® rendering (see opengl
).
Change the body patch properties. Use the Aero.Body PatchHandles
property
to get the patch handles for the first body.
patchHandles2 = h.Bodies{1}.PatchHandles;
Set the face and edge alpha values that you want for the transparency.
desiredFaceTransparency = .3; desiredEdgeTransparency = 1;
Get the current face and edge alpha data and change all values to the alpha values that you want. In the figure, the first body now has a transparency.
for k = 1:size(patchHandles2,1) tempFaceAlpha = get(patchHandles2(k),'FaceVertexAlphaData'); tempEdgeAlpha = get(patchHandles2(k),'EdgeAlpha'); set(patchHandles2(k),... 'FaceVertexAlphaData',repmat(desiredFaceTransparency,size(tempFaceAlpha))); set(patchHandles2(k),... 'EdgeAlpha',repmat(desiredEdgeTransparency,size(tempEdgeAlpha))); end
This series of commands illustrates how to change the color
of a body. The animation object stores the body geometry as patches.
This example manipulates the FaceVertexColorData
property
of these patches.
Change the body patch properties. Use the Aero.Body PatchHandles
property
to get the patch handles for the first body.
patchHandles3 = h.Bodies{2}.PatchHandles;
Set the patch color to red.
desiredColor = [1 0 0];
Get the current face color and data and propagate the new patch color, red, to the face.
The if
condition prevents the windows
from being colored.
The name
property is stored in
the body geometry data (h.Bodies{2}.Geometry.FaceVertexColorData(k).name)
.
The code changes only the indices in patchHandles3
with
nonwindow counterparts in the body geometry data.
Note
If you cannot access the name
property to
determine the parts of the vehicle to color, you must use an alternative
way to selectively color your vehicle.
for k = 1:size(patchHandles3,1) tempFaceColor = get(patchHandles3(k),'FaceVertexCData'); tempName = h.Bodies{2}.Geometry.FaceVertexColorData(k).name; if isempty(strfind(tempName,'Windshield')) &&... isempty(strfind(tempName,'front-windows')) &&... isempty(strfind(tempName,'rear-windows')) set(patchHandles3(k),... 'FaceVertexCData',repmat(desiredColor,[size(tempFaceColor,1),1])); end end
This command series illustrates how to turn off the landing gear on the second body by turning off the visibility of all the vehicle parts associated with the landing gear.
Note
The indices into the patchHandles3
vector
are determined from the name
property. If you cannot
access the name
property to determine the indices,
you must use an alternative way to determine the indices that correspond
to the geometry parts.
for k = [1:8,11:14,52:57] set(patchHandles3(k),'Visible','off') end