POV-Ray : Newsgroups : povray.general : perspective user defined camera? Server Time
26 Apr 2024 20:32:35 EDT (-0400)
  perspective user defined camera? (Message 6 to 15 of 18)  
<<< Previous 5 Messages Goto Latest 10 Messages Next 3 Messages >>>
From: Bald Eagle
Subject: Re: perspective user defined camera?
Date: 27 Jan 2019 21:25:01
Message: <web.5c4e678b62f29219765e06870@news.povray.org>
"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...


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: perspective user defined camera?
Date: 27 Jan 2019 21:35:00
Message: <web.5c4e6a2962f2921970c5131a0@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
>...
> Below is some more code for you.
>...

BTW:
It would be nice if user defined cameras could be transformed directly like
other cameras. E.g. like this:

camera {
    user_defined
    location 0*z
    direction {
        function { image_width*u }
        function { image_height*v }
        function { image_width/2/tan(radians(Angle/2)) }
    }
    transform {
        LookAtTransform
        AnotherTransform
        translate pLocation
    }
}

- Then one would not have to transform the functions in order to transform the
camera.

The transformation block above does not seem to have any effect on the user
defined camera in the 3.8 version of POV-Ray that I'm using right now on my
Ubuntu PC; 3.8.0-x.freetype.unofficial (g++ 7 @ x86_64-pc-linux-gnu). I haven't
tested this on any 3.8 versions for Windows yet.

--
Tor Olav
http://subcube.com


Post a reply to this message

From: ingo
Subject: Re: perspective user defined camera?
Date: 28 Jan 2019 01:58:24
Message: <XnsA9E5511C8FD22seed7@news.povray.org>
in news:web.5c4e437c62f29219264be49d0@news.povray.org Tor Olav Kristensen 
wrote:

> Below is some more code for you

That will take some time to digest, thanks again Tor Olav,

Ingo


Post a reply to this message

From: ingo
Subject: Re: perspective user defined camera?
Date: 28 Jan 2019 12:27:28
Message: <XnsA9E5BBC3FC244seed7@news.povray.org>
in news:web.5c4e678b62f29219765e06870@news.povray.org Bald Eagle wrote:

> back calculating to
> determine where the camera should be?
> 

Kind of an inverse screen.inc?

ingo


Post a reply to this message

From: ingo
Subject: Re: perspective user defined camera?
Date: 28 Jan 2019 12:40:23
Message: <XnsA9E5BDF46A3E4seed7@news.povray.org>
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 

ingo

very unfinished:
---%<------%<------%<---
#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.0, 0.0, 1.0>;
#declare Angle = 90;

ucdPerspective(pLocation,pLookAt,Angle)

// ===== 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 }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

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

<<< Previous 5 Messages Goto Latest 10 Messages Next 3 Messages >>>

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