matlab 根据视锥参数输出投影矩阵

%Projection Matrix

%left eye

n1 =  0.0296  ;

f1 =  1000    ;

l1 =  -0.03402  ;

r1 =  0.03402  ;

t1 =  0.03402 ;

b1 =  -0.03402  ;

%right eye

n2 =  0.0296  ;

f2 =  1000      ;

l2 =  -0.03402  ;

r2 =  0.03402  ;

t2 =  0.03402  ;

b2 =  -0.03402  ;

ML = zeros(4); MR = zeros(4);

%left eye projection matrix

ML(1, 1) = 2 * n1 / (r1 - l1);

ML(2, 2) = 2 * n1 / (t1 - b1);

ML(1, 3) = (r1 + l1) / (r1 - l1);

ML(2, 3) = (t1 + b1) / (t1 - b1);

ML(3, 3) = (n1 + f1) / (n1 - f1);

ML(3, 4) = 2 * n1 * f1 / (n1 - f1);

ML(4, 3) = -1;

%right eye projection matrix

MR(1, 1) = 2 * n2 / (r2 - l2);

MR(2, 2) = 2 * n2 / (t2 - b2);

MR(1, 3) = (r2 + l2) / (r2 - l2);

MR(2, 3) = (t2 + b2) / (t2 - b2);

MR(3, 3) = (n2 + f2) / (n2 - f2);

MR(3, 4) = 2 * n2 * f2 / (n2 - f2);

MR(4, 3) = -1;

%unity以列为主序

ML = ML';

MR = MR';

fid = fopen('NibiruProjectionConfig.txt','wt');

fprintf(fid,'lefteye =');

for i=1:4

    for j=1:4

fprintf(fid,'%f',ML(i,j));

if (i+j < 8)

    fprintf(fid,', ');

end

    end

end

fprintf(fid,'\nrighteye=');

for i=1:4

    for j=1:4

fprintf(fid,'%f',MR(i,j));

if (i+j < 8)

    fprintf(fid,', ');

end

    end

end

fprintf(fid,'\n#log: ');

fprintf(fid,'left %f,%f,%f,%f,%f,%f ',n1,f1,l1,r1,t1,b1);

fprintf(fid,'right %f,%f,%f,%f,%f,%f',n2,f2,l2,r2,t2,b2);

fclose(fid);

你可能感兴趣的:(matlab 根据视锥参数输出投影矩阵)