Animation with Slider Controls in GUIDE
- “Light the Globe and Shift the Light Source” on page 9- 77
Create the Graphic Objects
The axes1_CreateFcn function initializes the axes, the two objects displayed in it, and
two hgtransform objects that affect the rotation of the globe:
- The globe is a surfaceplot generated by surface.
- The geographic graticule (lines of latitude and longitude), also a surfaceplot object,
generated by a call to mesh.
Data for these two objects are rectangular x-y-z grids generated by the sphere function.
The globe's grid is 50-by-50 and the graticule grid is 8-by-15. (Every other row of the 15-
by-15 grid returned by sphere is removed to equalize its North-South and East-West
spans when viewed on the globe.)
The axes x-, y-, and z-limits are set to [-1.02 1.02]. Because the graphic objects are
unit spheres, this leaves a little space around them while constraining all three axes to
remain the same relative and absolute size. The graticule grid is also enlarged by 2%,
which is barely enough to prevent the opaque texture-mapped surface of the globe from
obscuring the graticule. If you watch carefully, you can sometimes see missing pieces of
graticule edges as the globe spins.
Texture and Color the Globe
Code in the axes1_CreateFcn sets the CData for the globe to the 180-by-360 (one
degree) topo terrain grid by setting its FaceColor property to 'texturemap'. You
can use any image or grid to texture a surface. Specify surface properties as a struct
containing one element per property that you must set, as follows:
props.FaceColor= 'texture';
props.EdgeColor = 'none';
props.FaceLighting = 'gouraud';
props.Cdata = topo;
props.Parent = hgrotate;
hsurf = surface(x,y,z,props);
colormap(cmap)
TipYou can create MATLAB structs that contain values for sets of parameters and
provide them to functions instead of parameter-value pairs, and save the structs to MAT-
files for later use.