我已经编写了从相机的“眼睛”到距相机眼睛一定距离的观察平面生成光线的代码:
R3Ray ConstructRayThroughPixel(...)
{
R3Point p;
double increments_x = (lr.X() - ul.X())/(double)width;
double increments_y = (ul.Y() - lr.Y())/(double)height;
p.SetX( ul.X() + ((double)i_pos+0.5)*increments_x );
p.SetY( lr.Y() + ((double)j_pos+0.5)*increments_y );
p.SetZ( lr.Z() );
R3Vector v = p-camera_pos;
R3Ray new_ray(camera_pos,v);
return new_ray;
}
ul
是视平面lr
的左上角, 是视平面的左下角。它们定义如下:
R3Point org = scene->camera.eye + scene->camera.towards * radius;
R3Vector dx = scene->camera.right * radius * tan(scene->camera.xfov);
R3Vector dy = scene->camera.up * radius * tan(scene->camera.yfov);
R3Point lr = org + dx - dy;
R3Point ul = org - dx + dy;
这里,org
是观察平面的中心,是radius
观察平面和相机眼睛之间的距离, 是从观察平面中心在 xdx
和dy
y 方向上的位移。
该ConstructRayThroughPixel(...)
函数非常适合眼睛位于 (0,0,0) 的相机。然而,当相机位于某个不同的位置时,并非为图像产生所有需要的光线。
有什么建议可能会出错吗?也许我的方程式有问题?
谢谢您的帮助。