]> Creatis software - CreaPhase.git/blob - octave_packages/vrml-1.0.13/vrml_Background.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / vrml-1.0.13 / vrml_Background.m
1 ## Copyright (C) 2002 Etienne Grossmann <etienne@egdn.net>
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16 ##  s = vrml_Background (...)   - Vrml Background node
17 ##  
18 ##  s is a string of the form :
19 ##  ------------------------------------------------------------------
20 ##  Background { 
21 ##    skyColor          [0 0 0]
22 ##    skyAngle          [0]   
23 ##    groundColor       [0 0 0]   
24 ##    groundangle       [0]   
25 ##    backUrl           ""
26 ##    bottomUrl         ""
27 ##    frontUrl          ""
28 ##    leftUrl           ""
29 ##    rightUrl          ""
30 ##    topUrl            ""
31 ##  }
32 ##  ------------------------------------------------------------------
33 ##
34 ## Options :
35 ## All the fields of the node
36 ##
37 ## Example : s = vrml_Background ("skyColor",[0 0 1]);
38 ##
39
40 function s = vrml_Background (varargin)
41
42 hash = struct(varargin{:});
43
44 opts = struct ("skyColor",         3,
45                "groundColor",      3,
46                "skyAngle",         1,
47                "groundAngle",      1,
48                "backUrl",          0,
49                "bottomUrl",        0,
50                "frontUrl",         0,
51                "leftUrl",          0,
52                "rightUrl",         0,
53                "topUrl",           0);
54
55 body = "";
56 for [val,key] = hash,
57   if isfield (opts, key)
58     n = opts.(key);
59     if (n == 0)
60       if (ischar(val))
61         body = [ body, sprintf('   %-20s   "%s"\n', key, val) ];
62       else
63         error ("vrml_Background: field '%s' expects string", key);
64       endif
65     elseif (n == 1)
66       if (isscalar(val))
67         body = [ body, sprintf('   %-20s   [ %8.3f ]\n', key, val) ];
68       else
69         error ("vrml_Background: field '%s' expects scalar", key);
70       endif
71     else
72       if (isvector(val) && length(val) == 3)
73         body = [body, sprintf('   %-20s   [ %8.3f %8.3f %8.3f ]\n', key, val)];
74       else
75         error ("vrml_Background: field '%s' expects [r g b]", key);
76       endif
77     endif
78   else
79     error ("vrml_Background : unknown field '%s'",key);
80   end
81 end
82 s = sprintf ("Background { \n%s}\n", body);
83 endfunction
84