script1 (hallway model 4)

close all
clear

%          1      2      3      4      5      6      7      8
vcube = [ 0 0 0; 1 0 0; 1 1 0; 0 1 0; 0 0 1; 1 0 1; 1 1 1; 0 1 1]';
idx = [1 2 3 4 1 5 6 7 8 5 6 2 3 7 8 4];
vert(1,:) = vcube(1,:)*6;  % hallway width 6 ft.
vert(2,:) = vcube(2,:)*90; % length 90 ft.
vert(3,:) = vcube(3,:)*8;  % height 8 ft.

x = vert(1,idx);
y = vert(2,idx);
z = vert(3,idx);
g = imread('pat2s.jpg');
rgb = cat(3,g,g,g);
rgb = flipdim(rgb,2);
rgb = flipdim(rgb,1);
xdata = [2 4; 2 4];
ydata = [0 0; 0 0];
zdata = [2 2; 4 4];
close all
plot3(x,y,z,'k-');
hold on
h(3) = surface(xdata,ydata,zdata,rgb,'FaceColor','texturemap','EdgeColor','none');
hold off

%hold on
campos([3 3 3]);
camtarget([3 0 3]);
camup([0 0 1]);
camva(40);
camproj('perspective');
set(gcf,'renderer','zbuffer')
axis equal
axis off
set(gcf,'Position',[100 100 640 640]);
set(gca,'Position',[0 0 1 1]);
str = 'DataAspectRatio';
fprintf('%s: %g %g %g\n',str,get(gca,str));
%hold off
DataAspectRatio: 1 1 1
% this should show just the target board
phi = 40;
f = sqrt(2)/2/tan(phi*pi/360);
fprintf('focal length %g\n',f);
camz = f*sqrt(2);
campos([3 camz 3]);
fprintf('camz %g\n',camz);
focal length 1.94276
camz 2.74748
% this command results in expanding the horizontal field
set(gcf,'Position',[100 100 640 480]);
set(gcf,'Position',[100 100 640 640]);

% now you can just barely see the edges of walls and floor
campos([3 3.02*camz 3]);
nf = 0;
for camz= 3:2:17
    campos([3  camz 3]);
    f = getframe(gcf);
    nf = nf + 1;
    filename = ['image_' int2str(nf) '.jpg'];
    imwrite(f.cdata,filename);
end
for k=1:nf
    filename = ['image_' int2str(k) '.jpg'];
    img = imread(filename);
    figure
    imshow(img);
end