% close all
[x,y,z] = meshgrid (-2:0.1:2, -2:0.1:2, -2:0.1:2);
%[x,y,z] = meshgrid (-2:0.5:2, -2:0.5:2, -2:0.5:2);
val = x.^2 + y.^2 + z.^2;
fv = isosurface (x, y, z, val, 1);
fv2 = isosurface (x, y+3, z, val, 1);


graphics_toolkit ("fltk")
hfig = figure;
clf;

h_axes = subplot (1, 2, 1);
h_patch = patch (fv, "FaceColor", "c", "EdgeColor", "none");
% isonormals (x, y, z, val, h_patch)

set(h_axes, "AmbientLightColor", "w")

h_patch2 = patch (fv2, "FaceColor", "r", "EdgeColor", "none");
% isonormals (x, y+3, z, val, h_patch2)

axis equal; axis tight
title ("Isosurfaces with lighting");
view (3)

update_lighting (h_axes)
addlistener (h_axes, 'CameraPosition', @update_lighting)

h_axes2 = subplot(1, 2, 2);
h_patch3 = patch (fv, "FaceColor", "c", "EdgeColor", "none");
isonormals (x, y, z, val, h_patch3)
h_patch4 = patch (fv2, "FaceColor", "r", "EdgeColor", "none");
isonormals (x, y+3, z, val, h_patch4)
axis equal; axis tight
title ("Isosurfaces without lighting");
view (3)


hlink = linkprop ([h_axes, h_axes2], {"CameraPosition"});

rotate3d on
