www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mbcgraph/camlight.m

    function h = camlight(ax, varargin)
%CAMLIGHT Create a light.
%
%   H = CAMLIGHT(AX) creates a light in the specified axes that is
%   positioned using the built-in camlight command and maintains its
%   position relative to the camera when plots are rotated .
%
%   H = CAMLIGHT(AX, ...) passes on all extra arguments to the camlight
%   command whenever the light location is updated.
%
%   CAMLIGHT(H, ...) where H is a handle to a light turns a pre-existing
%   light into a camlight.

%   Copyright 2007-2013 The MathWorks, Inc.

if isgraphics(ax, 'axes')
    h = light('Parent', ax);
else
    h = ax;
    ax = ancestor(h, 'axes');
end
camlight(h, varargin{:});

L = mbcgui.hgclassesutil.proplistener(ax, 'CameraPosition', 'PostSet', @iUpdateLight);
set(h, 'UserData', L);


    function iUpdateLight(src, evt)
        try
            % camlight calls can error when the axes are in certain
            % orientations.  Unfortunately there is no ID to catch for
            % this.
            camlight(h, varargin{:});
        end
    end
end