<><FONT size=1><b><EM>实例43:添加环境效果</EM></b></FONT></P><>h0=figure('toolbar','none',...
'position',[198 56 450 468],...
'name','实例43');
h1=axes('parent',h0,...
'position',[0.15 0.45 0.7 0.5],...
'visible','off');
sphere
h=findobj('type','surface');
shading interp
axis equal
l=light('position',[0 -2 1]);
k(1)=get(h,'specularstrength');
k(2)=get(h,'diffusestrength');
k(3)=get(h,'specularexponent');
k(4)=get(h,'specularcolorreflectance');
u1=uimenu('parent',h0,...
'label','灯光效果',...
'tag','u1',...
'backgroundcolor',[0.75 0.75 0.75]);
u11=uimenu('parent',u1,...
'label','gouraud',...
'tag','u11',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'set(u11,''checked'',''on'');,',...
'set(u12,''checked'',''off'');,',...
'set(h,''facelighting'',''gouraud'')']);
u12=uimenu('parent',u1,...
'label','phong',...
'tag','u12',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'set(u11,''checked'',''off'');,',...
'set(u12,''checked'',''on'');,',...
'set(h,''facelighting'',''gouraud'')']);
u2=uimenu('parent',h0,...
'label','背面灯光',...
'tag','u2',...
'backgroundcolor',[0.75 0.75 0.75]);
u21=uimenu('parent',u2,...
'label','reverselit',...
'tag','u21',...
'checked','on',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'set(u21,''checked'',''on'');,',...
'set(u22,''checked'',''off'');,',...
'set(h,''backfacelighting'',''reverselit'')']);
u22=uimenu('parent',u2,...
'label','reverselit',...
'tag','u22',...
'backgroundcolor',[0.75 0.75 0.75],...
'callback',[...
'set(u21,''checked'',''off'');,',...
'set(u22,''checked'',''on'');,',...
'set(h,''backfacelighting'',''reverselit'')']);
s1=uicontrol('parent',h0,...
'units','points',...
'style','slider',...
'tag','s1',...
'min',0,...
'max',1,...
'value',k(1),...
'position',[20 80 100 15],...
'callback',[...
's1value=get(s1,''value'');,',...
'set(h,''specularstrength'',s1value)']);
t1=uicontrol('parent',h0,...
'units','points',...
'style','text',...
'tag','t1',...
'string','镜面反射强度',...
'position',[20 97 100 15]);
s2=uicontrol('parent',h0,...
'units','points',...
'style','slider',...
'tag','s2',...
'min',0,...
'max',1,...
'value',k(2),...
'position',[20 30 100 15],...
'callback',[...
's2value=get(s2,''value'');,',...
'set(h,''diffusestrength'',s2value)']);
t2=uicontrol('parent',h0,...
'units','points',...
'style','text',...
'tag','t2',...
'string','漫反射强度',...
'position',[20 47 100 15]);
s3=uicontrol('parent',h0,...
'units','points',...
'style','slider',...
'tag','s3',...
'min',0.1,...
'max',1,...
'value',k(3)/20,...
'position',[220 80 100 15],...
'callback',[...
's3value=get(s3,''value'')+eps;,',...
'set(h,''specularexponent'',20*s3value)']);
t3=uicontrol('parent',h0,...
'units','points',...
'style','text',...
'tag','t3',...
'string','镜面指数',...
'position',[220 97 100 15]);
s4=uicontrol('parent',h0,...
'units','points',...
'style','slider',...
'tag','s4',...
'min',0,...
'max',1,...
'value',k(4),...
'position',[220 30 100 15],...
'callback',[...
's4value=get(s4,''value'');,',...
'set(h,''specularcolorreflectance'',s4value)']);
t4=uicontrol('parent',h0,...
'units','points',...
'style','text',...
'tag','t1',...
'string','镜面颜色反射比',...
'position',[220 47 100 15]);
b1=uicontrol('parent',h0,...
'units','points',...
'style','pushbutton',...
'tag','b1',...
'string','关闭',...
'position',[145 45 50 30],...
'callback','close');</P> |