function vwrcback(command)
% This function is a callback for viewer.
% It should not be called from the command line.
%
% Keith Rogers 11/30/93
% Mods:
%	preview capability - 12/29/93 Patrick Marchand
%			      (pmarchan@motown.ge.com)
%       12/02/94  Shorten name to appease DOS Users

FigureData = get(gcf,'UserData');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FigureData(1) = handle of slider #1
% FigureData(2) = handle of slider #2
% FigureData(3) = handle of slider #3
% FigureData(4) = handle of text for slider #1
% FigureData(5) = handle of text for slider #2
% FigureData(6) = handle of text for slider #3
% FigureData(7) = handle of text for slider #3
% FigureData(8) = handle of text for slider #3
% FigureData(9) = handle of text for slider #3
% FigureData(10) = handle of view button
% FigureData(11) = handle of apply_button
% FigureData(12) = handle of figure being viewed
% FigureData(13) = handle of axis containing sliders
% FigureData(14) = handle of axis containing display figure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%	Commands
%
%  1:	X-slider moved	
%  2:	Y-slider moved
%  3:	Z-slider moved
%  4:	Roll slider moved
%  5:	Yaw slider moved
%  6:	Pitch slider moved
%  7:	Elevation slider moved
%  8:	Azimuth slider moved
%  9:	Set figure to be viewed
% 10:	Create sliders
% 11:	Apply the Desired Aspect
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if(command < 9)	
	vang = zeros(3,1);
	vang(2:3) = fix([get(FigureData(2),'Value');...
				get(FigureData(3),'Value')]);
	if(FigureData(1))
		vang(1) = fix(get(FigureData(1),'Value'));
	end
	rang = radians(vang);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Callbacks for XYZ Euler Sliders
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if (command == 1)
	T = rot4x(rang(1))*rot4y(rang(2))*rot4z(rang(3));
	set(FigureData(4),'String', num2str(vang(1)));
elseif (command == 2)
	T = rot4x(rang(1))*rot4y(rang(2))*rot4z(rang(3));
	set(FigureData(5),'String', num2str(vang(2)));
elseif (command == 3)
	T = rot4x(rang(1))*rot4y(rang(2))*rot4z(rang(3));
	set(FigureData(6),'String', num2str(vang(3)));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Callbacks for PYR Sliders
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

elseif (command == 4)
	T = rot4x(rang(1))*rot4z(rang(3))*rot4y(rang(2));
	set(FigureData(4),'String', num2str(vang(2)));
elseif (command == 5)
	T = rot4x(rang(1))*rot4z(rang(3))*rot4y(rang(2));
	set(FigureData(6),'String', num2str(vang(3)));
elseif (command == 6)
	T = rot4x(rang(1))*rot4z(rang(3))*rot4y(rang(2));
	set(FigureData(5),'String', num2str(vang(1)));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Callbacks for El-Az Sliders
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

elseif (command == 7)
	T = viewmtx(vang(2),vang(3));
	set(FigureData(6),'String', num2str(vang(3)));
elseif (command == 8)
	T = viewmtx(vang(2),vang(3));
	set(FigureData(5),'String', num2str(vang(2)));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Callback for Popup Menu:
% Sets graphfig according to menu value
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

elseif (command == 9)
	val = get(gco,'Value');
	figures = get(gco,'UserData');
	FigureData(12) = figures(val);
	set(gcf,'UserData',FigureData);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Callback for Popup Menu:
% Creates sliders in appropriate style.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

elseif (command == 10)		
	axes(FigureData(13));
	view_button = FigureData(10);
	val = get(view_button,'Value');
	ButtonData = get(view_button,'UserData');
	if(val~=ButtonData)
		for i = 1:9
			if(FigureData(i))
				delete(FigureData(i));
			end
		end

		vang = [-60,0,37.5];
		rang = radians(vang);

		if (val == 1)		% Create XYZ sliders

		FigureData(7) = text('String','Z',...
				 'Units','normalized',...
				 'Position',[.1 .5],...
				 'HorizontalAlignment','right',...
				 'VerticalAlignment','bottom');
		SliderZ = uicontrol('Style','Slider',...
				'Units','normalized',...
				'Position',[.11 .5 .47 .23],...
				'Value',vang(3),...
				'Min',-90,...
				'Max',90,...
				'Callback','vwrcback(3)');

		FigureData(8) = text('String','Y',...
				 'Units','normalized',...
			    'Position',[.1 .25],...
				 'HorizontalAlignment','right',...
				 'VerticalAlignment','bottom');
		SliderY = uicontrol('Style','Slider',...
				'Units','normalized',...
				'Position',[.11 .25 .47 .23],...
				'Value',vang(2),...
				'Min',-90,...
				'Max',90,...
				'Callback','vwrcback(2)');

		FigureData(9) = text('String','X',...
				 'Units','normalized',...
			    'Position',[.1 0],...
				 'HorizontalAlignment','right',...
				 'VerticalAlignment','bottom');
		SliderX = uicontrol('Style','Slider',...
				'Units','normalized',...
				'Position',[.11 0 .47 .23],...
				'Value',vang(1),...
				'Min',-90,...
				'Max',90,...
				'Callback','vwrcback(1)');

		FigureData(1:3) = [SliderX;SliderY;SliderZ];
		FigureData(4) = text('String',num2str(vang(1)),...
				'Units','normalized',...
				'Position',[.595 0],...
				'HorizontalAlignment','left',...
				'VerticalAlignment','bottom');
		FigureData(5) = text('String',num2str(vang(2)),...
				'Units','normalized',...
				'Position',[.595 .25],...
				'HorizontalAlignment','left',...
				'VerticalAlignment','bottom');
		FigureData(6) = text('String',num2str(vang(3)),...
				'Units','normalized',...
				'Position',[.595 .5],...
				'HorizontalAlignment','left',...
				'VerticalAlignment','bottom');
		set(gcf,'UserData',FigureData);
		ButtonData = 1;
		set(view_button,'UserData',ButtonData);
		 
		T = rot4x(rang(1))*rot4y(rang(2))*rot4z(rang(3));
		 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create Elevation and Azimuth Sliders
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		 
		elseif (val == 2)  	

		vang = [-37.5 30];
		FigureData(9) = 0;
		FigureData(7) = text('String','El',...
				 'Units','normalized',...
				 'Position',[.1 .525],...
				 'HorizontalAlignment','right',...
				 'VerticalAlignment','bottom');
		SliderZ = uicontrol('Style','Slider',...
				'Units','normalized',...
				'Position',[.11 .5 .47 .23],...
				'Value',vang(2),...
				'Min',-90,...
				'Max',90,...
				'Callback','vwrcback(7)');

		FigureData(8) = text('String','Az',...
				 'Units','normalized',...
			    'Position',[.1 .275],...
				 'HorizontalAlignment','right',...
				 'VerticalAlignment','bottom');
		SliderY = uicontrol('Style','Slider',...
				'Units','normalized',...
				'Position',[.11 .275 .47 .23],...
				'Value',vang(1),...
				'Min',-90,...
				'Max',90,...
				'Callback','vwrcback(8)');

		FigureData(1:3) = [0;SliderY;SliderZ];
		FigureData(4) = 0;
		FigureData(5) = text('String',num2str(vang(1)),...
				'Units','normalized',...
				'Position',[.595 .25],...
				'HorizontalAlignment','left',...
				'VerticalAlignment','bottom');
		FigureData(6) = text('String',num2str(vang(2)),...
				'Units','normalized',...
				'Position',[.595 .5],...
				'HorizontalAlignment','left',...
				'VerticalAlignment','bottom');
		set(gcf,'UserData',FigureData);
		ButtonData = 2;
		set(view_button,'UserData',ButtonData);
		T = viewmtx(vang(1),vang(2));

%%%%%%%%%%%%%%%%%%%%%%
% Create PYR Sliders
%%%%%%%%%%%%%%%%%%%%%%
		 
		elseif (val == 3)  	% Create PYR sliders
		 
		vang = [-60,0,37.5];
		rang = radians(vang);

		FigureData(7) = text('String','Roll',...
				 'Units','normalized',...
				 'Position',[.1 .5],...
				 'HorizontalAlignment','right',...
				 'VerticalAlignment','bottom');
		SliderX = uicontrol('Style','Slider',...
				'Units','normalized',...
				'Position',[.11 .5 .47 .23],...
				'Value',vang(2),...
				'Min',-90,...
				'Max',90,...
				'Callback','vwrcback(4)');

		FigureData(8) = text('String','Yaw',...
				 'Units','normalized',...
				 'Position',[.1 .25],...
				 'HorizontalAlignment','right',...
				 'VerticalAlignment','bottom');
		SliderZ = uicontrol('Style','Slider',...
				'Units','normalized',...
				'Position',[.11 .25 .47 .23],...
				'Value',vang(3),...
				'Min',-90,...
				'Max',90,...
				'Callback','vwrcback(5)');

		FigureData(9) = text('String','Pitch',...
				 'Units','normalized',...
				 'Position',[.1 0],...
				 'HorizontalAlignment','right',...
				 'VerticalAlignment','bottom');
		SliderY = uicontrol('Style','Slider',...
				'Units','normalized',...
				'Position',[.11 0 .47 .23],...
				'Value',vang(1),...
				'Min',-90,...
				'Max',90,...
				'Callback','vwrcback(6)');

		FigureData(1:3) = [SliderY;SliderX;SliderZ];
		FigureData(4) = text('String',num2str(vang(2)),...
				'Units','normalized',...
				'Position',[.595 .525],...
				'HorizontalAlignment','left',...
				'VerticalAlignment','bottom');
		FigureData(5) = text('String',num2str(vang(1)),...
				'Units','normalized',...
				'Position',[.595 .025],...
				'HorizontalAlignment','left',...
				'VerticalAlignment','bottom');
		FigureData(6) = text('String',num2str(vang(3)),...
				'Units','normalized',...
				'Position',[.595 .275],...
				'HorizontalAlignment','left',...
				'VerticalAlignment','bottom');
		set(gcf,'UserData',FigureData);
		ButtonData = 3;
		set(view_button,'UserData',ButtonData);
		T = rot4x(rang(1))*rot4z(rang(3))*rot4y(rang(2));
		end
	end
elseif (command == 11)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  Callback for Apply Button
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	T = get(FigureData(14),'Xform');

	allfigs = get(0,'children');
	if(length(allfigs) > 1)
	   ax = get(allfigs(2),'children');
	   set(ax(1),'Xform',T);
	   Arrows = findobj(ax(1),'Tag','Arrow');
	   if(~isempty(Arrows))
			arrow(Arrows);
	   end
	end
	
end

set(FigureData(14),'Xform',T);
