POV-Ray : Newsgroups : povray.programming : Spherical Camera Server Time
29 Jul 2024 04:22:18 EDT (-0400)
  Spherical Camera (Message 1 to 1 of 1)  
From: Mike Hough
Subject: Spherical Camera
Date: 19 Jun 1998 04:03:18
Message: <358A1B46.73B43F@aol.com>
I had rather given up on the spherical camera idea until Chris Colefax
pointed out that the effect I was looking for could be achieved by:

" This problem can be quite easily overcome by first
rendering the image with the desired camera:

   camera {location <0, 0, 0> look_at <0, 0, 1>
      right x up y panoramic angle 180}

at a 1:1 ratio, and then rotating the camera by y*180 and rendering to a

second image of the same size.  When the two images are combined
side-by-side you should have the perfect image_map for a sphere."

While I had noticed that I could get half of the spherical projection
this way, that was long before I had stared at the code for hours and
hours.  I decided to go back and look at the code and found that I could
get a full 360 view by simply changing x0 to go from 0 to 2 instead of 0
to 1.  Here's the code for anyone interested in trying it out:

   case TEST_CAMERA_1:

/* Convert the x coordinate to be a DBL from 0.0 to 2.0. */ //changed
from 0.0 to 1.0

      x0 = 2 * x / (DBL)Frame.Screen_Width;

      /* Convert the y coordinate to be a DBL from -1.0 to 1.0. */

      y0 = 2.0 * ((DBL)(Frame.Screen_Height - 1) - y) /
(DBL)Frame.Screen_Height - 1.0;

      /* Get cylindrical coordinates. */

      x0 = (1.0 - x0) * M_PI;

      y0 = M_PI_2 * y0;

      cx = cos(x0);
      sx = sin(x0);

      if (fabs(M_PI_2 - fabs(y0)) < EPSILON)
      {
        if (y0 > 0.0)
        {
          ty = BOUND_HUGE;
        }
        else
        {
          ty = - BOUND_HUGE;
        }
      }
      else
      {
        ty = tan(y0);
      }

      /* Create primary ray. */

      VLinComb3(Ray->Direction, cx, FCR, ty, FCU, sx, FCD);

      initialize_ray_container_state(Ray, Precompute_Camera_Constants);

      Precompute_Camera_Constants = FALSE;

      break;

If rendered with the following camera, the resulting image can be mapped
onto a sphere to recreate the scene.  There does appear to be a slight
amount of distortion, but that may be due to the scene I was rendering.
The top and bottom will be seamless.

camera {
test_camera_1
location <0, 0, 0> look_at <0, 0, 1>
right x
up y
angle 180
}

A 2:1 aspect ratio should be used for the image, so a 1000 pixel wide
image should be 500 pixels in height.  I'm sure this was an odd
workaround and that the code could be changed to work with an angle of
360, but I'm just happy to have found a solution. ;-)

-Mike


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.