1 ## Copyright (C) 2010 Etienne Grossmann <etienne@egdn.net>
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
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
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/>.
16 ## s = vrml_Viewpoint (...) - Vrml Viewpoint node
18 ## s is a string of the form :
19 ## ------------------------------------------------------------------
21 ## eventIn SFBool set_bind
22 ## exposedField SFFloat fieldOfView 0.785398 # (0,pi)
23 ## exposedField SFBool jump TRUE
24 ## exposedField SFRotation orientation 0 0 1 0 # [-1,1],(-pi,pi)
25 ## exposedField SFVec3f position 0 0 10 # (-,)
26 ## field SFString description ""
27 ## eventOut SFTime bindTime
28 ## eventOut SFBool isBound
30 ## ------------------------------------------------------------------
33 ## All the fields of the node
35 ## Example : s = vrml_Viewpoint ("location",[0 0 1]);
37 ## See also : vrml_DirectionalLight
39 function s = vrml_Viewpoint (varargin)
41 if mod(nargin,2) != 0, print_usage; end
43 h = struct (varargin{:});
45 tpl = struct ("fieldOfView", "%8.3f",\
47 "orientation", "%8.3f %8.3f %8.3f %8.3f",\
48 "orientation0", "%8.3f %8.3f %8.3f %8.3f",\
49 "position", "%8.3f %8.3f %8.3f",\
50 "description", "\"%s\"",\
53 defaultPos = [0 0 10];
56 if ! isfield (tpl, key)
57 error (sprintf ("vrml_Viewpoint : unknown field '%s'",key));
62 h = rmfield (h, "DEF");
65 if isfield (h, "orientation0")
69 o = [o(:)'/norm(o), norm(o)];
71 o(4) = sign(o(4)) * rem (abs (o(4)), pi);
72 o = [o(1:3)(:)'/norm(o(1:3)), o(4)];
74 error ("Option 'orientation0' has size %i, should be 3 or 4", numel(o));
77 if isfield (h, "position")
83 h = rmfield (h, "orientation0");
86 h.position = rotv (o(1:3), o(4))' * p;
88 elseif isfield (h, "orientation")
92 o = [o(:)'/norm(o), norm(o)];
94 o(4) = sign(o(4)) * rem (abs (o(4)), pi);
95 o = [o(1:3)(:)'/norm(o(1:3)), o(4)];
97 error ("Option 'orientation' has size %i, should be 3 or 4", numel(o));
102 if isfield (h, "position") && numel (h.position) != 3
103 error ("Option 'position' has size %i, should be 3", numel (h.position));
106 if isfield (h, "jump")
117 sprintf(" %-20s %s\n",key, \
118 sprintf (getfield (tpl,key), val))];
121 s = sprintf ("Viewpoint {\n%s}\n", body);
123 s = ["DEF ", DEF," ",s];