1 ## Copyright (C) 2002 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 ## v = vrml_transfo(s,t,r,c,d)
18 ## s : string of vrml code.
19 ## t : 3 Translation default : [0,0,0]
20 ## r : 3x3 Rotation matrix, or default : eye(3)
21 ## 3 Scaled rotation axis.
22 ## c : 3 or 1 Scale default : 1
23 ## d : string DEF name default : ''
25 ## v : string v is s, enclosed in a Transform {} vrml node with
26 ## rotation, translation and scale params given by r, t and c.
29 function v = vrml_transfo(s,t,r,c,DEF)
31 ## Hint : if s is "%s", you may later do v2 = sprintf (v,s2) which should be
32 ## equal to vrml_transfo (s2,etc)
39 if nargin<2 || isnan (t), t = t0; end # Default translation
40 if nargin<3 || isnan (r), r = r0; end # Default rotation
41 if nargin<4 || isnan (c), c = c0; end # Default scale
42 if nargin<5, DEF = ""; end
45 if nargin > 1, printf ("vrml_transfo : t = %s\n",sprintf ("%f ",t)); end
46 if nargin > 2, printf ("vrml_transfo : r = %s\n",sprintf ("%f ",r)); end
47 if nargin > 3, printf ("vrml_transfo : c = %s\n",sprintf ("%f ",c)); end
48 if nargin > 4, printf ("vrml_transfo : DEF = %s\n",DEF); end
52 ## if nargin<4, s = "%s" ; end
54 if prod(size(t)) != 3, error("t has %i elements, not 3",prod(size(t))); end
57 if prod(size(c))==1, c = [c;c;c]; end
60 if abs (det (r) - 1) > sqrt (eps), r2 = orth (r);
63 [axis,ang] = rotparams (r2);
64 elseif prod(size(r)) == 4
67 elseif prod(size(r)) == 3
72 axis = [0,1,0]; ang = 0;
75 error ("vrml_transfo : rotation should have size 3x3, 3 or 4\n");
78 printf (["vrml_transfo : %8.3f %8.3f %8.3f %8.3f\n",\
79 " %8.3f %8.3f %8.3f\n"],\
81 printf ("length of string is %i\n",prod(size(s)));
85 if length (s) && strcmp(s(prod(size(s))),"\n") # chomp
86 s = s(1:prod(size(s))-1) ;
88 ## strrep is slow, as if it copied everything by hand. So don't indent.
90 # s = [" ",strrep(s,"\n","\n ")] ;
92 if verbose, printf (" done indenting s\n"); end
94 sr = st = ss = sd = "";
95 if abs (ang) > sqrt (eps)
96 sr = sprintf (" rotation %8.3f %8.3f %8.3f %8.3f\n",axis,ang);
98 if any (abs (t - t0)>sqrt (eps))
99 st = sprintf (" translation %8.3f %8.3f %8.3f\n",t);
101 if any (abs (c - c0)>sqrt (eps))
102 ss = sprintf (" scale %8.3f %8.3f %8.3f\n",c);
104 if !isempty (DEF), sd = ["DEF ",DEF," "]; end
106 v = sprintf([sd,"Transform {\n",sr,st,ss,\
107 " children [\n%s\n",\