【发布时间】:2015-10-09 14:15:34
【问题描述】:
这个问题的背景与我尝试将光线追踪器的输出与 Matlab 的 3d 绘图仪相结合有关。进行光线追踪时,无需对渲染图像应用透视变换。您可以在下图中看到这一点。基本上,光线与视口的交点会根据透视缩放自动调整。
假设我已经创建了一个光线追踪图像(因此我得到了我的相机、焦距、视口尺寸等)。如何在 Matlab 的 3d 绘图环境中创建完全相同的视图?
这是一个例子:
clear
close all
evec = [0 200 300]; % Camera position
recw = 200; % cm width of box
recl = 200; % cm length of box
h = 150; % cm height of box
% Create the front face rectangle
front = zeros(3,5);
front(:,1) = [-recw/2; 0; -recl/2];
front(:,2) = [recw/2; 0; -recl/2];
front(:,3) = [recw/2; h; -recl/2];
front(:,4) = [-recw/2; h; -recl/2];
front(:,5) = front(:,1);
% Back face rectangle
back = zeros(3,5);
back(:,1) = [-recw/2; 0; recl/2];
back(:,2) = [recw/2; 0; recl/2];
back(:,3) = [recw/2; h; recl/2];
back(:,4) = [-recw/2; h; recl/2];
back(:,5) = back(:,1);
% Plot the world view
figure(1);
patch(front(1,:), front(2,:), front(3,:), 'r'); hold all
patch(back(1,:), back(2,:), back(3,:), 'b');
plot3(evec(1), evec(2), evec(3), 'bo');
xlabel('x'); ylabel('y'); zlabel('z');
title('world view'); view([-30 40]);
% Plot the camera view
figure(2);
patch(front(1,:), front(2,:), front(3,:), 'r'); hold all
patch(back(1,:), back(2,:), back(3,:), 'b');
xlabel('x'); ylabel('y'); zlabel('z');
title('Camera view');
campos(evec);
camup([0 1 0]); % Up vector is y+
camproj('perspective');
camtarget([evec(1), evec(2), 0]);
title('camera view');
现在你看到了世界观
和相机视图
我知道如何调整相机位置、相机视角和方向以匹配我的光线追踪器的输出。但是不知道怎么调整matlab自带的透视命令
camproj('perspective')
适用于不同的失真。
注意:在文档中,有viewmtx 命令,它允许您输出对应于某个角度的透视失真的变换矩阵。这不是我想要的。我想通过 Matlab 的 OpenGL 查看器以 3D 形式进行操作。本质上,我想要一个类似的命令
camproj('perspective', distortionamount)
所以我可以将 Matlab 查看器中的失真量与光线追踪器的失真量相匹配。如果您使用 viewmtx 命令创建 2D 投影,您将无法使用 patch' orsurf' 并保持颜色和面不变。
【问题讨论】:
-
该死,想破解 Matlab,是吗?