문제

I have written code that generates a ray from the "eye" of the camera to the viewing plane some distance away from the camera's eye:

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 is the upper left corner of the viewing plane and lr is the lower left corner of the viewing plane. They are defined as follows:

  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;

Here, org is the center of the viewing plane with radius being the distance between the viewing plane and the camera eye, dx and dy are the displacements in the x and y directions from the center of the viewing plane.

The ConstructRayThroughPixel(...) function works perfectly for a camera whose eye is at (0,0,0). However, when the camera is at some different position, not all needed rays are produced for the image.

Any suggestions what could be going wrong? Maybe something wrong with my equations?

Thanks for the help.

도움이 되었습니까?

해결책 2

The reason why my code wasn't working was because I was treating x,y,z values separately. This is wrong, since the camera can be facing in any direction and thus if it was facing down the x-axis, the x coordinates would be the same, producing increments of 0 (which is incorrect). Instead, what should be done is an interpolation of corner points (where points have x,y,z coordinates). Please see answer in related post: 3D coordinate of 2D point given camera and view plane

다른 팁

Here's a quibble that may have nothing to do with you problem:

When you do this:

R3Vector dx = scene->camera.right * radius * tan(scene->camera.xfov);
R3Vector dy = scene->camera.up * radius * tan(scene->camera.yfov);

I assume that the right and up vectors are normalized, right? In that case you want sin not tan. Of course, if the fov angles are small it won't make much difference.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top