Ray Generation Inconsistency

Posted by Myx on Stack Overflow See other posts from Stack Overflow or by Myx
Published on 2010-03-27T15:52:32Z Indexed on 2010/03/27 15:53 UTC
Read the original article Hit count: 345

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.

© Stack Overflow or respective owner

Related posts about raytracing

Related posts about vector