function vrmemb(action)
%VRMEMB Virtual Reality Toolbox example - Membrane.
%  The VRMEMB example shows how to use a MATLAB-generated 3-D graphic
%  object in the Virtual Reality Toolbox.

%   Copyright 1998-2004 HUMUSOFT s.r.o. and The MathWorks, Inc.
%   $Revision: 1.6.4.3 $ $Date: 2004/04/06 01:11:19 $ $Author: batserve $

% the switchboard

if nargin>0
  H = getappdata(gcbf, 'Handles');
  feval(action, H);
  return;
end;

disp(' ');
disp('Loading...');
disp(' ');

% create the world
wh = vrworld('membrane.wrl');

disp(' ');
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
disp('%%% Rotating membrane with MATLAB GUI demo %%%');
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
disp(' ');
disp('%%% This example shows you how to use a MATLAB-generated 3-D graphic');
disp('%%% object in the Virtual Reality Toolbox.');
disp('%%% The membrane object was generated by the function ''logo'' and saved in');
disp('%%% VRML format using the function ''vrml''. After some minor modifications');
disp('%%% in the VRML editor it is directly usable by the Virtual Reality Toolbox.');
disp(' ');
disp('%%% After starting the demo you will see a control panel with two sliders');
disp('%%% and three checkboxes. The sliders are used to rotate and zoom the membrane');
disp('%%% while the checkboxes determine around which axis to rotate.');
disp(' ');
disp('%%% The demo is finished by closing the control panel.');
disp(' ');
disp('%%% Press Enter to start the demonstration.');
disp(' ');
pause;


% open and view the world
open(wh);
view(wh);

% get the nodes
H.membrane = vrnode(wh, 'Membrane');
H.view1 = vrnode(wh, 'View1');

% create the dialog

figh = dialog('Position',[358 402 530 107], 'Name', 'Virtual Reality Toolbox Demo', ...
              'WindowStyle', 'normal', ...
              'CloseRequestFcn', ...
              'w = vrworld(''membrane.wrl''); close(w); try; delete(w); end; closereq');

% create the Rotation control
uicontrol('Parent',figh, 'Position',[108 68 50 14], 'HorizontalAlignment','left', ...
          'String','Rotation', 'Style','text');
H.rotation = uicontrol('Parent',figh, 'Style','slider', 'Position',[164 65 352 20], ...
                       'Min', 0, 'Max', 2*pi, ...
                       'Callback', 'vrmemb rotation');

% create the Zoom control
H.zoom = uicontrol('Parent',figh, 'Style','slider', 'Position',[164 24 352 20], ...
                   'Value', 1, 'Callback', 'vrmemb zoom');
uicontrol('Parent',figh, 'Position',[108 27 50 14], 'String','Zoom', 'Style','text', 'HorizontalAlignment','left');

% draw the checkboxes

H.xaxis = uicontrol('Parent',figh, 'Position',[24 70 60 20], 'String','X', ...
                    'Style','checkbox');
H.yaxis = uicontrol('Parent',figh, 'Position',[24 42 60 20], 'String','Y', ...
                    'Style','checkbox');
H.zaxis = uicontrol('Parent',figh, 'Position',[24 14 60 20], 'String','Z', ...
                    'Style','checkbox', 'Value', 1);
setappdata(figh, 'Handles', H);



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%>%%%%%%
%  
%  ROTATION
%  rotation callback
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function rotation(H)

cur_rot = get(H.rotation,'Value');
cur_x = get(H.xaxis,'Value');
cur_y = get(H.yaxis,'Value');
cur_z = get(H.zaxis,'Value');

% perform rotation only if at least 1 axis selected

if (cur_x || cur_y || cur_z)
 H.membrane.rotation = [cur_x cur_y cur_z cur_rot];
end;



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%>%%%%%%
%  
%  ZOOM
%  zoom callback
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function zoom(H)

cur_zoom = 0.25 + 0.55 * (1-get(H.zoom,'Value'));
H.view1.fieldOfView = cur_zoom;
