POV-Ray : Newsgroups : povray.general : perspective user defined camera? Server Time
18 Apr 2024 00:13:22 EDT (-0400)
  perspective user defined camera? (Message 11 to 18 of 18)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Tor Olav Kristensen
Subject: Re: perspective user defined camera?
Date: 31 Jan 2019 20:35:01
Message: <web.5c53995562f292194c4249d90@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
>
> > No problem. It was an interesting problem to solve.
> >
> > You don't have to deal much with matrices to do this. (I just showed the
> > relationship in case anyone is interested.)
>
> This is only tangentially related:
>
> Would something related to this be the preferred way to set up a scene so that
> an object would occupy a specific position on the screen - back calculating to
> determine where the camera should be?
>
> So, let's say there are 2 views (I think that might be necessary to get Z), each
> showing the same cube (and maybe a reference point like the origin) from a
> different vantage point.
> I'm presuming that a matrix would be the best way to reverse-project back to
> where the camera should be?
>
> It's just something that struck me with the functions, and matrices, and
> user-define camera...

I'm not sure if I understand what you mean.

In order to bring an object to a certain position on the screen, the camera can
be anywhere in space before rotating it towards the object.

To do that you translate the camera to origo, rotate it around an axis - or
reorient it from one vector to another (which is the same as rotating around an
axis) and then you translate it back to where it "came from".

If everything stays in 3 dimensions (i.e. using vectors with 3 components and
3x3 matrices) then the rotation (or reorientation) can be done with a matrix
multiplication, but the translations can not.

If you convert the 3D vectors into 4D vectors (by using homogeneous coordinates)
and use 4x4 matrices, then translations can also be done with matrix
multiplications (which, BTW, is why POV-Ray's matrices have 4 rows). All the
matrices (for translation, rotation/reorientation and back translation) can be
multiplied with each other to create one final matrix that "does it all".
Multiplying the camera vectors by this matrix will now bring the object into the
given screen position.

--
Tor Olav
http://subcube.com


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: perspective user defined camera?
Date: 31 Jan 2019 20:50:00
Message: <web.5c53a56462f292194c4249d90@news.povray.org>
ingo <ing### [at] tagpovrayorg> wrote:
> in news:web.5c4e6a2962f2921970c5131a0@news.povray.org Tor Olav
> Kristensen wrote:
>
> > BTW:
> > It would be nice if user defined cameras could be transformed
> > directly like other cameras. E.g. like this:
> >
>
> Thats what I thought too, but,
>
> This morning after seeing your new code I made a laarge pot of strong
> coffee and started tinkering. It thought me where I went wrong on several
> occasions.
> I consistenly threw away X1_Y and X1_Z components in simmilar constructs
> ;(
>   #local vT1_X = vtransform(x, LookAtTransform);
>   #local X1_X = vT1_X.x;
>   #local X1_Y = vT1_X.y;
>   #local X1_Z = vT1_X.z;
>
> After getting more grip on your code I turned it in a macro and that adds
> flexibility you won't have with direct transforms.
>
> This way you can spend your attention to the screen --> scene transfer
> and then just call the macro. It should work for most camera types.
> I can also see it useful for setting up stereo cams, parallel or toed in.
> Or for greating images with insets where a small region of the image is
> rendered as a detail for a bigger scene.
> I added it to a tile rendering camera without problem.
> So, a lot of options to investigate

It's good that it works and that you are able to proceed with you user defined
tile rendering camera.

If you create something with POV-Ray and Marzipano (or similar tools) it would
be interesting to see.

--
Tor Olav
http://subcube.com


Post a reply to this message

From: Bald Eagle
Subject: Re: perspective user defined camera?
Date: 31 Jan 2019 21:40:01
Message: <web.5c53afdb62f29219765e06870@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:

> > So, let's say there are 2 views (I think that might be necessary to get Z), each
> > showing the same cube (and maybe a reference point like the origin) from a
> > different vantage point.
> > I'm presuming that a matrix would be the best way to reverse-project back to
> > where the camera should be?



> I'm not sure if I understand what you mean.



Assume you have 2 renders of something like [an] object[s] in a Cornell box

https://en.wikipedia.org/wiki/Cornell_box

(but you DON'T have the SDL written to generate said render[s] )

Presumably if there's some known reference dimension[s], then one ought to be
able
to reproduce the geometry - size, shape - of all the objects in the scene.

I assumed it might require at least a second render from a different angle -
preferably an orthogonal one, or if necessary, additional ones that reveal
occluded details.

Probably the camera angle would be needed to construct an accurate projection
matrix, as well.


I was just considering it as an extension of the discussion and experiments at

http://news.povray.org/povray.binaries.images/thread/%3C5baddad1%40news.povray.org%3E/?mtop=424795

and

http://news.povray.org/povray.advanced-users/thread/%3C5bb67852%40news.povray.org%3E/

but expanding it to deal with more data.

Collect data from analyzing / measuring one render, couple that with data from a
second render (different vantage point) and one could quickly, albeit roughly,
recreate a scene when perhaps the source was lost, unavailable, etc.


Post a reply to this message

From: Bald Eagle
Subject: Re: perspective user defined camera?
Date: 31 Jan 2019 21:55:00
Message: <web.5c53b41062f29219765e06870@news.povray.org>
Um, holy crap!

https://3dprintingindustry.com/news/3-sweep-sweeps-the-net-with-smart-2d-to-3d-conversion-17024/


I'm thinking Stephen is going to download this as soon as he's able!  :D


Post a reply to this message

From: ingo
Subject: Re: perspective user defined camera?
Date: 1 Feb 2019 02:03:21
Message: <XnsA9E951F2D665Bseed7@news.povray.org>
in news:web.5c53a56462f292194c4249d90@news.povray.org Tor Olav
Kristensen wrote: 

> If you create something with POV-Ray and Marzipano (or similar tools)
> it would be interesting to see.
> 

I will post once done,

ingo


Post a reply to this message

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.