]> Creatis software - CreaPhase.git/blob - octave_packages/vrml-1.0.13/vrml_PointLight.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / vrml-1.0.13 / vrml_PointLight.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_PointLight (...)   - Vrml PointLight node
17 ##  
18 ##  s is a string of the form :
19 ##  ------------------------------------------------------------------
20 ##  PointLight { 
21 ##    exposedField SFFloat ambientIntensity  0       ## [0,1]
22 ##    exposedField SFVec3f attenuation       1 0 0   ## [0,inf)
23 ##    exposedField SFColor color             1 1 1   ## [0,1]
24 ##    exposedField SFFloat intensity         1       ## [0,1]
25 ##    exposedField SFVec3f location          0 0 0   ## (-inf,inf)
26 ##    exposedField SFBool  on                TRUE 
27 ##    exposedField SFFloat radius            100     ## [0,inf)
28 ##  }
29 ##  ------------------------------------------------------------------
30 ##
31 ## Options :
32 ## All the fields of the node
33 ##
34 ## Example : s = vrml_PointLight ("location",[0 0 1]);
35 ##
36 ## See also : vrml_DirectionalLight
37
38 function s = vrml_PointLight (varargin)
39
40 if mod(nargin,2) != 0, print_usage; end
41 h = struct (varargin{:});
42
43 tpl = struct ("ambientIntensity", "%8.3f",\
44               "intensity",        "%8.3f",\
45               "radius",           "%8.3f",\
46               "on",               "%s",\
47               "attenuation",      "%8.3f %8.3f %8.3f",\
48               "color",            "%8.3f %8.3f %8.3f",\
49               "location",         "%8.3f %8.3f %8.3f");
50
51 body = "";
52 for [val,key] = h,
53
54     if strcmp (key, "DEF")
55       continue;
56     elseif !(isnumeric(val) && isnan (val))
57
58                                 # Check validity of field
59     if ! isfield (tpl, key)
60       error (sprintf ("vrml_PointLight : unknown field '%s'",key));
61     end
62
63
64     body = [body,\
65             sprintf("   %-20s   %s\n",key, \
66                     sprintf (getfield (tpl,key), val))];
67   end
68 end
69 s = sprintf ("PointLight {\n%s}\n", body);
70 if isfield (h,"DEF") && !isempty (h.DEF)
71   s = ["DEF ",h.DEF," ",s];
72 end 
73 endfunction
74