POV-Ray : Newsgroups : povray.general : What to do with the pixel in the middle : Re: What to do with the pixel in the middle Server Time
18 Apr 2024 21:31:32 EDT (-0400)
  Re: What to do with the pixel in the middle  
From: Tor Olav Kristensen
Date: 2 Feb 2019 14:45:00
Message: <web.5c55f204738ba468c143b2b0@news.povray.org>
ingo <ing### [at] tagpovrayorg> wrote:
> in news:XnsA9EA2A6B5B0Dseed7@news.povray.org ingo wrote:
>...
> #macro udcLookAtTransform(
>     D0_X_Fn, D0_Y_Fn, D0_Z_Fn,
>     pLocation, pLookAt, Angle,
>     optional Roll, optional vDirection,
>     optional vRight, optional vUp
>   )
>   /*==
>   Transforms the direction function of a user defined camera to look into
> the
>   pLookAt direction from the camera location.
>
>   Code base by: Tor Olav Kristensen, http://subcube.com
>   This macro is intended to be used in user defined cameras.
>   For example use, see udcPerspective().
>
>   D0_X_Fn, D0_Y_Fn, D0_Z_Fn (function): the original camera direction
> functions.
>   pLocation  (vec) : the location of the camera
>   pLookAt    (vec) : the point to look at
>   Angle    (float) : horizontal field of view o view angle
>   Roll     (float) : optional, defaults to 0.
>                      Roll, a.k.a. banking, rotates the camera around the
> view
>                      direction vector.
>   vDirection (vec) : optional, defaults to +z.
>   vRigth     (vec) : optional, defaults to
> <image_width/image_height,0,0>.
>   vUp        (vec) : optional, defaults to +y.
>   */
>   #ifndef(local.Roll)
>     #local Roll = 0;
>   #end
>   #ifndef(local.vDirection)
>     #local vDirection = +1*z;
>   #end
>   #ifndef(local.vRight)
>       #local vRight = +image_width/image_height*x;
>   #end
>   #ifndef(local.vUp)
>     #local vUp = +1*y;
>   #end
>   #local vLookAt = pLookAt - pLocation;
>   #local LookAtTransform = transform{
>     Reorient_Trans(z, vLookAt)
>     Axis_Rotate_Trans(vLookAt, Roll)
>   }
>   #local vDirection_1 = vtransform(vDirection, LookAtTransform);
>   #local vRight_1 = vtransform(vRight, LookAtTransform);
>   #local vUp_1 = vtransform(vUp, LookAtTransform);
>   #local <X1_X, X1_Y, X1_Z> = vtransform(x, LookAtTransform);
>   #local <Y1_X, Y1_Y, Y1_Z> = vtransform(y, LookAtTransform);
>   #local <Z1_X, Z1_Y, Z1_Z> = vtransform(z, LookAtTransform);
>   #local D1_X_Fn = function(u,v){
>     0
>     + X1_X*D0_X_Fn(u,v)
>     + Y1_X*D0_Y_Fn(u,v)
>     + Z1_X*D0_Z_Fn(u,v)
>   };
>   #local D1_Y_Fn = function(u,v){
>     0
>     + X1_Y*D0_X_Fn(u, v)
>     + Y1_Y*D0_Y_Fn(u, v)
>     + Z1_Y*D0_Z_Fn(u, v)
>   };
>   #local D1_Z_Fn = function(u,v){
>     0
>     + X1_Z*D0_X_Fn(u, v)
>     + Y1_Z*D0_Y_Fn(u, v)
>     + Z1_Z*D0_Z_Fn(u, v)
>   };
>   (D1_X_Fn, D1_Y_Fn, D1_Z_Fn)
> #end
>
> #macro udcStereo(pLocation,pLookAt,Angle,FocalDist)
>   //http://paulbourke.net/stereographics/stereorender/
>   #local EyeSep = FocalDist/30;
>   #local Delta  = (image_width*EyeSep)/(2*FocalDist*tand(Angle/2));
>   #local Angle1 = 2*atand((image_width+Delta)*tand(Angle/2)/image_width);
>   #local AspectU = image_width+Delta+Delta;
>   #local AspectV = image_height;
>   #local vMovement  = EyeSep/2*vnormalize(vcross(pLookAt-pLocation,
> <0,1,0>));
>   #local pLocationL = pLocation+vMovement;
>   #local pLocationR = pLocation-vMovement;
>   #local <LocationXL, LocationYL, LocationZL> = pLocationL;
>   #local <LocationXR, LocationYR, LocationZR> = pLocationR;
>   #local LocationX = function(u){select((u<=0),-1, LocationXR,
> LocationXL)};
>   #local LocationY = function(u){select((u<=0),-1, LocationYR,
> LocationYL)};
>   #local LocationZ = function(u){select((u<=0),-1, LocationZR,
> LocationZL)};
>   #local D0_X_Fn = function(u,v){u*AspectU};
>   #local D0_Y_Fn = function(u,v){v*AspectV};
>   #local D0_Z_Fn = function(u,v){AspectU/2/tand(Angle/2)};
>   #local pLookAtL = pLookAt+vMovement;
>   #local pLookAtR = pLookAt-vMovement;
>   #local(D1L_X_Fn, D1L_Y_Fn, D1L_Z_Fn) = udcLookAtTransform(
>     D0_X_Fn, D0_Y_Fn, D0_Z_Fn, pLocationL, pLookAtL, Angle1,,,,
>   );
>   #local(D1R_X_Fn, D1R_Y_Fn, D1R_Z_Fn) = udcLookAtTransform(
>     D0_X_Fn, D0_Y_Fn, D0_Z_Fn, pLocationR, pLookAtR, Angle1,,,,
>   );
>   #local D2_X_Fn = function(u,v){select(
>     (u<=0),
>     -1,
>     D1R_X_Fn((u/AspectU*image_width)-0.25,v),
>     D1L_X_Fn((u/AspectU*image_width)+0.25,v)
>   )};
>   #local D2_Y_Fn = function(u,v){select((u<=0),-1, D1R_Y_Fn(u-0.25,v),
> D1L_Y_Fn(u+0.25,v))};
>   #local D2_Z_Fn = function(u,v){select((u<=0),-1, D1R_Z_Fn(u-0.25,v),
> D1L_Z_Fn(u+0.25,v))};
>   camera {
>     user_defined
>     location {
>       function {LocationX(u)}
>       function {LocationY(u)}
>       function {LocationZ(u)}
>     }
>     direction {
>       function {D2_X_Fn(u,v)}
>       function {D2_Y_Fn(u,v)}
>       function {D2_Z_Fn(u,v)}
>     }
>   }
> #end

Note that vDirection_1, vRight_1 and vUp_1 are calculated in your
udcLookAtTransform macro, but not used for anything. So I suggest that you
remove them, and also vDirection, vRight and vUp, as you you will not be able to
change the default direction vectors for the user defined camera.

Further, I assume that you are implementing "Off-axis" stereo camera pairs. If
so then the corresponding direction vectors for both cameras will all be
parallel. (But their position and field of view will be different.) Therefore
you do not need to create two different direction function sets for them. You
can create a common set based on the initial pLocation and pLookAt positions.

--
Tor Olav
http://subcube.com


Post a reply to this message

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