# HG changeset patch
# User Markus Mützel <markus.muetzel@gmx.de>
# Date 1472486188 -7200
#      Mon Aug 29 17:56:28 2016 +0200
# Node ID 38d57a43cb7e4a6f755b57c8ebec511869f3dcfb
# Parent  f0836b5ec628f15231d85e40278dcdc5749e4417
Matlab incompatibilities in light.m (bug #48873)

light.m: Change demo for Matlab compatibility. Add additional demo for
"BackFaceLighting".

diff -r f0836b5ec628 -r 38d57a43cb7e scripts/plot/draw/light.m
--- a/scripts/plot/draw/light.m	Mon Aug 29 11:25:12 2016 +0200
+++ b/scripts/plot/draw/light.m	Mon Aug 29 17:56:28 2016 +0200
@@ -377,7 +377,7 @@
 %! [x,y,z] = meshgrid (-.5:0.1:2, -2:0.1:2, -2:0.1:2);
 %! val = x.^2 + y.^2 + z.^2;
 %! fv = isosurface (x, y, z, val, 1);
-%! vn = isonormals (x, y, z, val, fv.vertices, "negate");
+%! vn = isonormals (x, y, z, val, fv.vertices);
 %! h_axes1 = subplot (1, 3, 1);
 %! h_patch = patch (fv, "FaceColor", "c", "EdgeColor", "none", ...
 %!                      "FaceLighting", "Gouraud", "VertexNormals", vn);
@@ -389,7 +389,7 @@
 %!
 %! h_axes2 = subplot (1, 3, 2);
 %! h_patch = patch (fv, "FaceColor", "c", "EdgeColor", "none", ...
-%!                      "FaceLighting", "Gouraud", "VertexNormals", vn);
+%!                      "FaceLighting", "Gouraud", "VertexNormals", -vn);
 %! set (h_patch, "BackFaceLighting", "lit");
 %! h_light = light ();
 %! view (h_axes2, [-50 30]);
@@ -398,7 +398,7 @@
 %!
 %! h_axes3 = subplot (1, 3, 3);
 %! h_patch = patch (fv, "FaceColor", "c", "EdgeColor", "none", ...
-%!                      "FaceLighting", "Gouraud", "VertexNormals", vn);
+%!                      "FaceLighting", "Gouraud", "VertexNormals", -vn);
 %! set (h_patch, "BackFaceLighting", "unlit");
 %! h_light = light ();
 %! view (h_axes3, [-50 30]);
@@ -406,6 +406,72 @@
 %! axis equal
 
 %!demo
+%! ## BackFaceLighting 2
+%! ## Matlab fails for "reverselit" with negated isonormals and for "unlit"
+%! N = 30; iso = .8;
+%! lin = linspace (-1, 1, N);
+%! [x, y, z] = meshgrid (1.2*lin, 1.2*lin, lin);
+%! val = (x).^2 + (y).^2 - iso/2.7*cos (2*pi*z);
+%! val(x>0 & (y-x)>0) = NaN;
+%! fv = isosurface (x, y, z, val, iso);
+%! vn = isonormals (x, y, z, val, fv.vertices);
+%! 
+%! clf;
+%! subplot (2, 3, 1);
+%! view (140, 20);
+%! axis equal
+%! hp = patch (fv, "FaceColor", "r", "EdgeColor", "none", ...
+%!             "BackFaceLighting", "reverselit", "VertexNormals", -vn);
+%! hl = light ("Position", [1 0 .5]);
+%! lighting gouraud
+%! title ({"BackFaceLighting", '"reverselit"', 'isonormals(...,"negate")'});
+%! 
+%! subplot (2, 3, 2);
+%! view (140, 20);
+%! axis equal
+%! hp = patch (fv, "FaceColor", "r", "EdgeColor", "none", ...
+%!             "BackFaceLighting", "lit", "VertexNormals", -vn);
+%! hl = light ("Position", [1 0 .5]);
+%! lighting gouraud
+%! title ({"BackFaceLighting", '"lit"', 'isonormals(...,"negate")'});
+%! 
+%! subplot (2, 3, 3);
+%! view (140, 20);
+%! axis equal
+%! hp = patch (fv, "FaceColor", "r", "EdgeColor", "none", ...
+%!             "BackFaceLighting", "unlit", "VertexNormals", -vn);
+%! hl = light ("Position", [1 0 .5]);
+%! lighting gouraud
+%! title ({"BackFaceLighting", '"unlit"', 'isonormals(...,"negate")'});
+%! 
+%! subplot (2, 3, 4);
+%! view (140, 20);
+%! axis equal
+%! hp = patch (fv, "FaceColor", "r", "EdgeColor", "none", ...
+%!             "BackFaceLighting", "reverselit", "VertexNormals", vn);
+%! hl = light ("Position", [1 0 .5]);
+%! lighting gouraud
+%! title ({"BackFaceLighting", '"reverselit"', "isonormals(...)"});
+%! 
+%! subplot (2, 3, 5);
+%! view (140, 20);
+%! axis equal
+%! hp = patch (fv, "FaceColor", "r", "EdgeColor", "none", ...
+%!             "BackFaceLighting", "lit", "VertexNormals", vn);
+%! hl = light ("Position", [1 0 .5]);
+%! lighting gouraud
+%! title ({"BackFaceLighting", '"lit"', "isonormals(...)"});
+%! 
+%! subplot (2, 3, 6);
+%! view (140, 20);
+%! axis equal
+%! hp = patch (fv, "FaceColor", "r", "EdgeColor", "none", ...
+%!             "BackFaceLighting", "unlit", "VertexNormals", vn);
+%! hl = light ("Position", [1 0 .5]);
+%! lighting gouraud
+%! title ({"BackFaceLighting", '"unlit"', "isonormals(...)"});
+
+%!demo
 %! ## Colored patch
 %! clf;
 %! [x,y,z] = meshgrid (-.2:0.02:.2, -.2:0.02:.2, -.2:0.02:.2);
