function image = z(images, camX, camY, camZ, disp, apature)
%code to run if virtual camera z != 0
%basically the gaussian code inside another double for loop

%for every pixel we want to render, calculate s,t,u,v
% then shift the pixels for focal distance, then combine multiple images
% with apature

%NOTE THIS IS VERYYYY SLOW compared to z=0 gaussian code


rows = size(images, 1);
cols = size(images, 2);

image = images{1,1};
image(:,:,:) = 0;

pix_rows = size(image,1);
pix_cols = size(image,2);


for r = 1:pix_rows
   for c = 1:pix_cols
       u = ((2*(c - .5*pix_cols))/pix_cols)+camX;
       v = ((2*(r - .5*pix_rows))/pix_rows)+camY;
       s = camX - camZ*(u - camX);
       t = camY - camZ*( camY - v);
       
       u = max(1, min(round(u), pix_cols));
       v = max(1, min(round(v), pix_rows));
       s = max(1, min(s, cols));
       t = max(1, min(t, rows));
       
       %real apature should loop through all the images, but this is
       % wayyyyy too slow. So I just have the 4 neighbors
       for i = max(1, floor(t) ):min(floor(t)+1, rows)
           for j = max(1, floor(s) ):min(floor(s)+1, cols)
                disp_x = disp*(j - s); 
                disp_y = disp*(i - t);
                index_c = max(1, min(round(disp_x + c), pix_cols));
                index_r = max(1, min(round(-disp_y + r), pix_rows));
               
                %multiply by 2 since im not adding in all images, will be
                %dark otherwise
                pixel = images{i,j}(index_r, index_c, :)*normpdf(i, t, apature)*normpdf(j, s, apature)*2*apature;
                image(r, c, :) = image(r, c, :) + ...
                    pixel;
           end
       end
       
       
       
   end
end


end

