1## Copyright (C) 1998-2003 Joao Cardoso. 2## 3## This program is free software; you can redistribute it and/or modify it 4## under the terms of the GNU General Public License as published by the 5## Free Software Foundation; either version 2 of the License, or (at your 6## option) any later version. 7## 8## This program is distributed in the hope that it will be useful, but 9## WITHOUT ANY WARRANTY; without even the implied warranty of 10## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11## General Public License for more details. 12## 13## This file is part of plplot_octave. 14 15## set_view (alt, az) 16## set_view (script, arg1, ...) 17## set_view () 18## 19## If called with two numeric arguments, sets up the altitude and azimute 20## in degrees for posterior 3d plots. 21## 22## If called without arguments, rotates iteratively a cube using the mouse. 23## 24## If called with one string as the first argument, instead of a cube the string 25## is evaluated as a function and should do a 3D plot, using the remaining arguments. 26## 27## example of callback `script': 28## [x, y, z] = peaks; 29## set_view("surfl", x, y, z); 30## 31## To control the view angle, the following mouse buttons can be used: 32## 33## button 1 press: marks new origin 34## button 1,3 drag: rotate cube 35## button 2 press: finish 36## button 3 press: return to default position 37 38function set_view (alt, az, varargin) 39 40 global __pl 41 strm = __pl_init; 42 43 callback = 0; 44 45 if (nargin == 2 && !ischar(alt)) 46 __pl.az(strm) = az; 47 __pl.alt(strm) = alt; 48 return 49 elseif (nargin >= 2 && ischar(alt)) 50 cmd = alt; 51 arg1 = az; 52 callback = 1; 53 endif 54 55 az = __pl.az(strm); 56 alt = __pl.alt(strm); 57 58 if (!callback) 59 x = y = [0; 1]; 60 z = ones(2); 61 xm = ym = zm = 0; 62 xM = yM = zM = 1; 63 64 plcol0(15); 65 66 __pl_plenv(-1.5, 1.5, -1.5, 2.5, 0, -2); 67 plw3d(2, 2, 2, xm, xM, ym, yM, zm, zM, alt, az) 68 69 plmtex("t", 3, 0.5, 0.5, sprintf("Alt=%d Az=%d", alt, az)); 70 71 plbox3("bnstu", "X axis", 0.0, 0,"bnstu", "Y axis", 0.0, 0,"bdcmnstuv", 72 "Z axis", 0.0, 0) 73 74 plot3d(x,y,z,1,1); 75 plflush; 76 77 xm = ym = zm = 0; 78 xM = yM = zM = 1; 79 else 80 title(sprintf("Alt=%d Az=%d", alt, az)); 81 feval(cmd, arg1, varargin{:}); 82 endif 83 84 ox = oy = 0; 85 c_alt = c_az = 0; 86 87 while (1) 88 [status, state, keysym, button, string, pX, pY, dX, dY, wX, wY, subwin] = plGetCursor; 89 90 if (button == 3) # default position 91 az = -60; alt = 30; 92 ox = dX; oy = dY; 93 c_alt = c_az = 0; 94 elseif(button == 2) # stop 95 break; 96 elseif (button == 1) # mark position 97 ox = dX; oy = dY; 98 alt = alt + c_alt; az = az + c_az; 99 c_alt = c_az = 0; 100 elseif (button == 0) # drag 101 c_az = (dX-ox)*100; 102 c_alt = (oy-dY)*100; 103 endif 104 105 if (alt + c_alt > 90) 106 c_alt = 90 - alt; 107 elseif (alt + c_alt < 0) 108 c_alt = -alt; 109 endif 110 111 if (!callback) 112 __pl_plenv(-1.5, 1.5, -1.5, 2.5, 0, -2); 113 114 plw3d(2, 2, 2, xm, xM, ym, yM, zm, zM, alt+c_alt, az+c_az) 115 116 plbox3("bnstu", "x axis", 0.0, 0,"bnstu", "y axis", 0.0, 117 0,"bdcmnstuv", "z axis", 0.0, 0) 118 119 plmtex("t", 3, 0.5, 0.5, sprintf("Alt=%d Az=%d", alt+c_alt, az+c_az)); 120 121 plot3d(x,y,z,1,1); 122 plflush; 123 else 124 __pl.az(strm) = az + c_az; 125 __pl.alt(strm) = alt + c_alt; 126 title(sprintf("Alt=%d Az=%d", alt+c_alt, az+c_az)); 127 feval(cmd, arg1, varargin{:}); 128 endif 129 130 endwhile 131 132 __pl.az(strm) = az + c_az; 133 __pl.alt(strm) = alt + c_alt; 134 135 136endfunction 137