Matlab:移动光源
Matlab: Moving Light Source
我有一个带阴影的 3-D 对象的 3-D 图。当用户旋转绘图时,如何使光源不断更新为来自用户观看的方向?
看看 MATLAB 的 camlight
命令 (online documentation)。
这是一个让您入门的最小演示:
function camlight_demo
% some example data to plot
surf(peaks);
h = rotate3d;
set(h,'Enable','on');
% add a light
LightSource = camlight('headlight');
% add a callback which will be executed after each rotation
set(h,'ActionPostCallback',{@move_light_source, LightSource});
end
% This function will move the light after each rotation
function move_light_source(src, evt, LightSource)
camlight(LightSource, 'headlight');
end
我有一个带阴影的 3-D 对象的 3-D 图。当用户旋转绘图时,如何使光源不断更新为来自用户观看的方向?
看看 MATLAB 的 camlight
命令 (online documentation)。
这是一个让您入门的最小演示:
function camlight_demo
% some example data to plot
surf(peaks);
h = rotate3d;
set(h,'Enable','on');
% add a light
LightSource = camlight('headlight');
% add a callback which will be executed after each rotation
set(h,'ActionPostCallback',{@move_light_source, LightSource});
end
% This function will move the light after each rotation
function move_light_source(src, evt, LightSource)
camlight(LightSource, 'headlight');
end