function Rot=RotationMatrix(eyepos)
% eyepos can either be a single eyeposition structure, or a cell array of
% such structures

if ~iscell(eyepos)
	tmp = eyepos;
	clear eyepos;
	eyepos{1} = tmp;
end

for j=1:length(eyepos)
	cosH = cosd(eyepos{j}.azimuth);
	sinH = sind(eyepos{j}.azimuth);
	cosV = cosd(eyepos{j}.elevation);
	sinV = sind(eyepos{j}.elevation);
	cosT = cosd(eyepos{j}.torsion);
	sinT = sind(eyepos{j}.torsion);

	% Find rotation matrices
	RotH = [cosH 0 sinH ; 0 1 0 ; -sinH 0 cosH];
	RotV = [ 1 0 0 ; 0 cosV -sinV ; 0  sinV cosV ];
	RotT = [cosT -sinT 0 ; sinT cosT 0; 0  0 1];
	Rot{j} = RotV*RotH*RotT;
end

if exist('tmp','var') % then the original eyepos supplied was not a cell array; return something that is not a cell array
	Rot = Rot{1};
end