% file light2.m

clear all;close all;
p=linspace(0,1,100);
%r=sin(p*pi).*(sin(4*pi*p)+2).*exp(-p/2);
r=cos(2*pi*p)+2;
[xc,yc,zc]=cylinder(r,100); % 100 points around diameter

figure(1);
surf(xc,yc,zc);
shading interp;
material shiny;
l=light('pos',[-5 2 1]);
colormap cool
axis equal;
axis square;

fvc=surf2patch(xc,yc,zc,zc);
%fvc = 
%              faces: [19980x4 double]
%           vertices: [21000x3 double]
%    facevertexcdata: [21000x1 double]
v=fvc.vertices;
f=fvc.faces;
c=fvc.facevertexcdata;

T=rot3d_pre(pi/2,2);
vsize=size(v);
vh=[v ones(vsize(1),1)];
v2=T*vh';
fvc2.facevertexcdata=c;
fvc2.faces=f;
v2(4,:)=[];
fvc2.vertices=v2';

figure(2);
patch(fvc2)
view(3)
colormap(cool)
l=light('position',[-5 2 1],'style','local');
shading interp;
material shiny;
grid on;
axis equal;
axis square;


figure(3);
patch(fvc2,'AmbientStrength',1,'DiffuseStrength',0.5,...
    'SpecularStrength',0,'SpecularExponent',5,'SpecularColorReflectance',0,...
    'FaceLighting','phong','EdgeLighting','phong');
ka=1;kd=0.5;ks=1;n=5;sc=1;
shading interp;
colormap(summer);
material shiny;
view(3);
l=light('position',[-5 2 1]);
%material([ka kd ks n sc]);
%lighting phong;
grid on;
axis equal;
axis square;
