POV-Ray : Newsgroups : povray.general : perspective user defined camera? Server Time
8 May 2024 03:00:14 EDT (-0400)
  perspective user defined camera? (Message 16 to 18 of 18)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: IGM
Subject: Re: perspective user defined camera?
Date: 31 May 2019 12:15:00
Message: <web.5cf1525762f29219d5f3e7360@news.povray.org>
Hi,
the two alternative cameras, the standard perspective camera and the
ucdPerspective camera, give different images if the pLookAt is not perfectly
<0.0, 0.0, 1.0>. Try commenting the respective row.
Can we explain and fix this?

IGM

// ###############################################

#version 3.8;

global_settings { assumed_gamma 1.0 }

#include "colors.inc"
#include "transforms.inc"

#macro ucdPerspective(pLocation,pLookAt,Angle)

  #local D0_X_Fn = function(u, v) {u*image_width };
  #local D0_Y_Fn = function(u, v) {v*image_height};
  #local D0_Z_Fn = function(u, v) {image_width/2/tan(radians(Angle/2))};

  #local LocationX = pLocation.x;
  #local LocationY = pLocation.y;
  #local LocationZ = pLocation.z;
  #local(D1_X_Fn, D1_Y_Fn, D1_Z_Fn) =
ucdLookAtTransform(D0_X_Fn,D0_Y_Fn,D0_Z_Fn,pLocation,pLookAt,Angle);

  camera {
    user_defined
    location {
      function { LocationX }
      function { LocationY }
      function { LocationZ }
    }
    direction {
    function { D1_X_Fn(u, v) }
    function { D1_Y_Fn(u, v) }
    function { D1_Z_Fn(u, v) }
    }
  }
#end

#macro ucdLookAtTransform(D0_X_Fn,D0_Y_Fn,D0_Z_Fn,pLocation,pLookAt,Angle)
  #local vDirection_0 = +1*z;
  #local vRight_0 = +image_width/image_height*x;
  #local vUp_0 = +1*y;
  //the three above should probably move to the cam definition
  #local vLookAt = pLookAt - pLocation;
  #local LookAtTransform = Reorient_Trans(z, vLookAt)
  #local vDirection_1 = vtransform(vDirection_0, LookAtTransform);
  #local vRight_1 = vtransform(vRight_0, LookAtTransform);
  #local vUp_1 = vtransform(vUp_0, LookAtTransform);
  #local vT1_X = vtransform(x, LookAtTransform);
  #local X1_X = vT1_X.x;
  #local X1_Y = vT1_X.y;
  #local X1_Z = vT1_X.z;
  #local vT1_Y = vtransform(y, LookAtTransform);
  #local Y1_X = vT1_Y.x;
  #local Y1_Y = vT1_Y.y;
  #local Y1_Z = vT1_Y.z;
  #local vT1_Z = vtransform(z, LookAtTransform);
  #local Z1_X = vT1_Z.x;
  #local Z1_Y = vT1_Z.y;
  #local Z1_Z = vT1_Z.z;

  #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

#declare pLocation = <0.0, 0.5, -0.0>;
#declare pLookAt = <0.5, 0.0, 1.0>;
#declare Angle = 90;

// Alternative cameras
ucdPerspective(pLocation,pLookAt,Angle)
// camera { angle Angle right image_width/image_height*x up y location pLocation
look_at pLookAt }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
#declare SphereRadius = 0.3;

sphere { < 0,  0,  2>, SphereRadius pigment { checker White Black } }
sphere { < 0,  0, -2>, SphereRadius pigment { checker White Red   } }
sphere { < 2,  0,  0>, SphereRadius pigment { checker White Green } }
sphere { <-2,  0,  0>, SphereRadius pigment { checker White Blue  } }

union {
    sphere { < 0,  0,  2>, SphereRadius pigment { White } }
    sphere { < 0,  0, -2>, SphereRadius pigment { Red   } }
    sphere { < 2,  0,  0>, SphereRadius pigment { Green } }
    sphere { <-2,  0,  0>, SphereRadius pigment { Blue  } }
    translate 0.5*y
}

background { color Gray80 }

light_source { <1, 1, -1>*100 White }
light_source { <0, 0, 0> Gray20 }


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: perspective user defined camera?
Date: 8 Jun 2019 15:30:00
Message: <web.5cfc0b7462f2921969f45c250@news.povray.org>
"IGM" <iar### [at] gmailcom> wrote:
> Hi,
> the two alternative cameras, the standard perspective camera and the
> ucdPerspective camera, give different images if the pLookAt is not perfectly
> <0.0, 0.0, 1.0>. Try commenting the respective row.
> Can we explain and fix this?
>...

Hi IGM

Please note that Ingo warned that the user defined camera macros he posted were
"very unfinished".

According to the documentation for POV-Ray's camera:
https://www.povray.org/documentation/3.7.0/r3_4.html#r3_4_2
- it seems that POV-Ray performs the look_at transform by first panning and then
tilting the camera.
(See 3.4.2.1.1 Location and Look_At)

The code that I posted did this in a single reorientation.

If this reorientation is split up in two steps (first panning and then tilting),
the results seem to be the same for the created user defined camera and the
built in perspective camera.

You can do this by changing the expression for the LookAtTransform in Ingo's
ucdLookAtTransform macro, like this:

    #local LookAtTransform =
        transform {
            Reorient_Trans(z, vLookAt*(x + z))  // Pan
            Reorient_Trans(vLookAt*(x + z), vLookAt)  // Tilt
        }

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: IGM
Subject: Re: perspective user defined camera?
Date: 9 Jun 2019 03:15:01
Message: <web.5cfcb14f62f2921913ebc39b0@news.povray.org>
> According to the documentation for POV-Ray's camera:
> https://www.povray.org/documentation/3.7.0/r3_4.html#r3_4_2
> - it seems that POV-Ray performs the look_at transform by first panning and then
> tilting the camera.
> (See 3.4.2.1.1 Location and Look_At)

I had read this, but I did not draw the necessary consequences.

> The code that I posted did this in a single reorientation.
>
> If this reorientation is split up in two steps (first panning and then tilting),
> the results seem to be the same for the created user defined camera and the
> built in perspective camera.
>
> You can do this by changing the expression for the LookAtTransform in Ingo's
> ucdLookAtTransform macro, like this:
>
>     #local LookAtTransform =
>         transform {
>             Reorient_Trans(z, vLookAt*(x + z))  // Pan
>             Reorient_Trans(vLookAt*(x + z), vLookAt)  // Tilt
>         }

Thank you Tor for this fix. Now the user_defined camera transform is working
properly!

igmar


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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