POV-Ray : Newsgroups : povray.advanced-users : Calculating visible camera area Server Time
23 Nov 2024 12:55:05 EST (-0500)
  Calculating visible camera area (Message 1 to 10 of 10)  
From: Bald Eagle
Subject: Calculating visible camera area
Date: 25 Oct 2016 12:45:00
Message: <web.580f8b048d6e3073b488d9aa0@news.povray.org>
I thought there had been some discussion about this, Way Back When (TM), but I
could not locate a thread.

I was wondering if there were some way to calculate the positions of the four
corners of the visible render frame, or unit-length-vectors that point from the
camera in those directions.

If there are other formulas for calculating schtuff associated with the final
render and field of view, that would be helpful as well.

Currently just interested in typical perspective camera, though I also use
orthographic frequently.

Thanks


Post a reply to this message

From: Le Forgeron
Subject: Re: Calculating visible camera area
Date: 25 Oct 2016 14:23:16
Message: <580fa314$1@news.povray.org>
Le 25/10/2016 à 18:40, Bald Eagle a écrit :
> I thought there had been some discussion about this, Way Back When (TM), but I
> could not locate a thread.
> 
> I was wondering if there were some way to calculate the positions of the four
> corners of the visible render frame, or unit-length-vectors that point from the
> camera in those directions.
> 
> If there are other formulas for calculating schtuff associated with the final
> render and field of view, that would be helpful as well.
> 
> Currently just interested in typical perspective camera, though I also use
> orthographic frequently.

I'm afraid not, so far at least.

The best I have to propose is just getting the basic data back from the
camera:

http://wiki.povray.org/content/User:Le_Forgeron#Access_to_camera_information

On the good side, it might be possible to call
TracePixelCameraData::CreateCameraRay(Ray& ray, DBL x, DBL y, DBL width,
DBL height, size_t ray_number, TracePixel& parent)
to build the ray and extract its data.

Or you can just use the C++ code of it so far with the previous pieces
of data to make your own computation without patch.


Post a reply to this message

From: Alain
Subject: Re: Calculating visible camera area
Date: 25 Oct 2016 16:53:59
Message: <580fc667@news.povray.org>

> I thought there had been some discussion about this, Way Back When (TM), but I
> could not locate a thread.
>
> I was wondering if there were some way to calculate the positions of the four
> corners of the visible render frame, or unit-length-vectors that point from the
> camera in those directions.
>
> If there are other formulas for calculating schtuff associated with the final
> render and field of view, that would be helpful as well.
>
> Currently just interested in typical perspective camera, though I also use
> orthographic frequently.
>
> Thanks
>
>
If you use an orthographic camera WITHOUT the angle keyword, located on 
the Z axis and looking toward +z, the dimentions are :
Top left : up, -right
Top right : up, right
Bottom left : -up, -right
Bottom right : -up, right

For any other projections, it's not obvious. You'll need to use some 
trigonometry. This can give you the direction vectors that are parallel 
to the edges of the rendered image. As a starting point, take a look at 
the file screen.inc that is made to deal with such situations.


Alain


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Calculating visible camera area
Date: 26 Oct 2016 01:35:01
Message: <web.58103fb2e3118e5d468fc97e0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> I thought there had been some discussion about this, Way Back When (TM), but I
> could not locate a thread.
>
> I was wondering if there were some way to calculate the positions of the four
> corners of the visible render frame, or unit-length-vectors that point from the
> camera in those directions.
>
> If there are other formulas for calculating schtuff associated with the final
> render and field of view, that would be helpful as well.
>
> Currently just interested in typical perspective camera, though I also use
> orthographic frequently.

I once did some work related to this:

http://news.povray.org/povray.binaries.images/thread/<Xns9327B41C265F5torolavk%40204.213.191.226>

I believe that I still have the code somewhere if anyone is interested.

--
Tor Olav
http://subcube.com


Post a reply to this message

From: Bald Eagle
Subject: Re: Calculating visible camera area
Date: 26 Oct 2016 10:15:01
Message: <web.5810b9bbe3118e5db488d9aa0@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:

> I once did some work related to this:
>
http://news.povray.org/povray.binaries.images/thread/<Xns9327B41C265F5torolavk%40204.213.191.226>
>
> I believe that I still have the code somewhere if anyone is interested.

That would be a great step forward for me to see what you've done.


Perhaps even others could use it as an inspiration for further work on the
alternate camera types and interesting pigment functions I've seen being dabbled
with recently.

Thanks  :)


Post a reply to this message

From: Bald Eagle
Subject: Re: Calculating visible camera area
Date: 31 Oct 2016 12:45:00
Message: <web.581774afe3118e5db488d9aa0@news.povray.org>
Le_Forgeron <jgr### [at] freefr> wrote:
> Le 25/10/2016 à 18:40, Bald Eagle a écrit :

> > I was wondering if there were some way to calculate the positions of the four
> > corners of the visible render frame, or unit-length-vectors that point from the
> > camera in those directions.


> I'm afraid not, so far at least.


Well, there seem to be quite a few pages describing the how, when I search for
"calculating view frustum"

I haven't gotten any of the calculations to work out so far, but perhaps when I
get some of those precious round tuits, I'll make some headway.


Post a reply to this message

From: Bald Eagle
Subject: Re: Calculating visible camera area
Date: 1 Nov 2016 10:15:01
Message: <web.5818a33ee3118e5db488d9aa0@news.povray.org>
Here's what I've managed to work out so far - as you can see, it yields a
view-frustum-shaped frame, but it seems I somehow have the aspect ratio wrong,
and the [real] camera is WAY back from where the placeholder scene camera is.

Not sure where my errors lie.
Perhaps someone could take a look at my values, assumptions, and math.

Also, I peeked at the source code, and it looked to me like the default camera
angle is 90.   The docs imply 67.380
I'd like to get this worked out so I can start playing with frustum culling - it
seems that would be a powerful tool for large scenes with lots of objects.

See:
http://www.flipcode.com/archives/Frustum_Culling.shtml

--------------------------------------------------------------

#version 3.7;

global_settings {
  assumed_gamma 1.0
}

//------------------------------------------
// sets up a model scene and views from an alternate viewpoint
//
// POV-Ray Scene SDL written by
// Bill Walker - 2016
//------------------------------------------


#include "colors.inc"
#include "debug.inc"
  Set_Debug (true)
#include "math.inc"
#include "metals.inc"
#include "stones1.inc"
#include "textures.inc"
#include "woods.inc"




#declare Camera_Origin = camera {
                            location  <0, 0, 0>
                            right    x*image_width/image_height
                            look_at   <0, 0, 0.01>}

#declare Camera_Angle = camera {
                            location  <0.0 , 0.0, -100.0>
                            right    x*image_width/image_height
                            look_at   <100, 30, 0>}
#declare Camera_Front = camera {
                            location  <0.0, 0, -70.0>
      //location  <0.0, 12, -10.0>
                            right    x*image_width/image_height
                            look_at   <0, 0, 0>}
#declare Camera_Rear = camera {
                            location  <0.0, -100.0, -300.0>
                            right    x*image_width/image_height
                            look_at   <0, 0, 0>}
#declare Camera_Top = camera {
                            location  <0, 25.0, 0>
                            right    x*image_width/image_height
                            look_at   <0, 0, 0>}

#declare Camera_Iso = camera {
                            location  <-50, 0, 0>
                            right    x*image_width/image_height
                            look_at   <0, 0, 0>}

//####################
camera {Camera_Front }
//####################


light_source{ <50, 50, -100>  color rgb <1, 1, 1>}    // White top
//light_source{ <0, 0, -100> color rgb <1, 1, 1>}    // White Front


sky_sphere {
 pigment {
  gradient <0, 1, 0>
  color_map {
   [0   color rgb <1, 1, 1>  ]
   [0.4 color rgb <0, 0, 0.8> ]
   [0.6 color rgb <0, 0.14, 0.8> ]
   [1.0 color rgb <1, 1, 1>  ]
  }
 scale 2
 }
}

/*
CAMERA TYPE: perspective
  angle      : ~67.380 ( direction_length=0.5*
             right_length/tan(angle/2) )
  confidence : 0.9 (90%)
  direction  : <0,0,1>
  focal_point: <0,0,0>
  location   : <0,0,0>
  look_at    : z
  right      : 1.33*x
  sky        : <0,1,0>
  up         : y
  variance   : 1/128

direction_length = 0.5 * right_length / tan(angle / 2)
*/

#declare Camera_Location = <0, 0, 0>;
 #declare P = Camera_Location;
#declare Camera_LookAt = <0, 0, 30>;
#declare ResolutionX = image_width;
#declare ResolutionY = image_height;

#declare Distance = Camera_LookAt - Camera_Location;
#declare V = vnormalize(Distance);
#declare Up = <0, 1, 0>;
#declare Right = <ResolutionX/ResolutionY, 0, 0>;
//#declare Right = vcross(V, Up);
#declare W = Right;

#declare nDis = 10;
#declare fDis = 30;
// Field of View (fov)
#declare Fov = 67.380;
#declare AR = ResolutionX/ResolutionY;
#declare Hnear = 2*tan(Fov/2)*nDis;
#declare Wnear = Hnear * AR;
#declare Hfar = 2*tan(Fov/2)*fDis;
#declare Wfar = Hfar * AR;
#declare Cnear = P + V * nDis;
#declare Cfar = P + V * fDis;
#declare NearTopLeft     = Cnear + (Up * (Hnear/2)) - (W * (Wnear/2));
#declare NearTopRight    = Cnear + (Up * (Hnear/2)) + (W * (Wnear/2));
#declare NearBottomLeft  = Cnear - (Up * (Hnear/2)) - (W * (Wnear/2));
#declare NearBottomRight = Cnear - (Up * (Hnear/2)) + (W * (Wnear/2));

#declare FarTopLeft     =   Cfar + (Up * ( Hfar/2)) - (W * ( Wfar/2));
#declare FarTopRight    =   Cfar + (Up * ( Hfar/2)) + (W * ( Wfar/2));
#declare FarBottomLeft  =   Cfar - (Up * ( Hfar/2)) - (W * ( Wfar/2));
#declare FarBottomRight =   Cfar - (Up * ( Hfar/2)) + (W * ( Wfar/2));




//#declare Towards = Distance / abs(Camera_Location.z);

// direction_length = 0.5 * right_length / tan(angle / 2)
// tan(angle / 2) * direction_length = 0.5 * right_length
// tan(angle / 2) = (0.5 * right_length) / direction_length
// (angle / 2) = atan2( (0.5 * right_length), direction_length)
// angle = 2* atan2( (0.5 * right_length), direction_length)

// tan (Theta) = Opposite / Adjacent
// tan (Theta) = (ResolutionX/2) / Distance
 // Distance * tan (Theta) = (ResolutionX/2)
 // 2 * Distance * tan (Theta) = ResolutionX
// Theta = atan2 ((ResolutionX/2), Distance)

//#declare Angle = atan2 ((ResolutionX/2), Distance);
//#declare Angle = 67.38;
//#declare Distance = 0.5 * Right / tan(radians(Angle) / 2);

//#declare Top_Left  = Camera_Location + (Distance * Towards * <0, 0, 1>) -
(Distance * tan(Angle) * Right);
//#declare Top_Right = Camera_Location + (Distance * Towards * <0, 0, 1>) +
(Distance * tan(Angle) * Right);

// {Be sure to include debug.inc file!}
#debug concat( "Distance = ", vstr(3, Distance, ", ", 3, 3), " \n")
#debug concat( "Right = ", vstr(3, Right, ", ", 3, 3), " \n")
//#debug concat( "Top_Left = ", vstr(3, Top_Left, ", ", 3, 0), " \n")
//#debug concat( "Top_Right = ", vstr(3, Top_Right, ", ", 3, 0), " \n")

sphere {Camera_Location, 0.1 pigment {Green}}
sphere {Camera_LookAt, 0.5 pigment {Yellow}}

//sphere {Top_Left, 0.2 pigment {Red}}
//sphere {Top_Right, 0.2 pigment {Red}}

//cylinder {Top_Left, Top_Right, 0.05 pigment {Blue}}
#declare NearSphere = 0.2;
#declare FarSphere = 0.2;

sphere {NearTopLeft, NearSphere pigment {Orange}}
sphere {NearTopRight, NearSphere pigment {Orange}}
sphere {NearBottomLeft, NearSphere pigment {Orange}}
sphere {NearBottomRight, NearSphere pigment {Orange}}

cylinder {NearTopLeft, NearTopRight, NearSphere/2 pigment {Orange}}
cylinder {NearTopRight, NearBottomRight, NearSphere/2 pigment {Orange}}
cylinder {NearBottomRight, NearBottomLeft, NearSphere/2 pigment {Orange}}
cylinder {NearBottomLeft, NearTopLeft, NearSphere/2 pigment {Orange}}

sphere {FarTopLeft, FarSphere pigment {Violet}}
sphere {FarTopRight, FarSphere pigment {Violet}}
sphere {FarBottomLeft, FarSphere pigment {Violet}}
sphere {FarBottomRight, FarSphere pigment {Violet}}

cylinder {FarTopLeft, FarTopRight, FarSphere/2 pigment {Violet}}
cylinder {FarTopRight, FarBottomRight, FarSphere/2 pigment {Violet}}
cylinder {FarBottomRight, FarBottomLeft, FarSphere/2 pigment {Violet}}
cylinder {FarBottomLeft, FarTopLeft, FarSphere/2 pigment {Violet}}

cylinder {Camera_Location, FarTopRight, NearSphere/2 pigment {White}}
cylinder {Camera_Location, FarBottomRight, NearSphere/2 pigment {White}}
cylinder {Camera_Location, FarBottomLeft, NearSphere/2 pigment {White}}
cylinder {Camera_Location, FarTopLeft, NearSphere/2 pigment {White}}


Post a reply to this message

From: Mike Horvath
Subject: Re: Calculating visible camera area
Date: 3 Nov 2016 21:32:32
Message: <581be530@news.povray.org>
On 10/25/2016 12:40 PM, Bald Eagle wrote:
> I thought there had been some discussion about this, Way Back When (TM), but I
> could not locate a thread.
>
> I was wondering if there were some way to calculate the positions of the four
> corners of the visible render frame, or unit-length-vectors that point from the
> camera in those directions.
>
> If there are other formulas for calculating schtuff associated with the final
> render and field of view, that would be helpful as well.
>
> Currently just interested in typical perspective camera, though I also use
> orthographic frequently.
>
> Thanks
>
>

Maybe you could use my updated screen.inc to calculate the area? I 
posted it in p.t.s-f just now.

Mike


Post a reply to this message

From: Bald Eagle
Subject: Re: Calculating visible camera area
Date: 4 Nov 2016 12:45:01
Message: <web.581cba19e3118e5db488d9aa0@news.povray.org>
Mike Horvath <mik### [at] gmailcom> wrote:

> Maybe you could use my updated screen.inc to calculate the area? I
> posted it in p.t.s-f just now.

Yes, thanks, Mike.
That was on my list of things to look into.

First, of course, was brute force trying to crack this nut with my hard, thick,
skull - I being an Aries and all   ;)   :D

Gonna be busy for the next week or so, but maybe I'll have a chance to work
through it and have some sort of epiphany.
I already suspect I'm basing my approach on a vertical aperture rather than a
horizontal one, but that ought to be corrected easily enough.


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Calculating visible camera area
Date: 6 Nov 2016 12:30:01
Message: <web.581f67d6e3118e5d16a478410@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
>
> > I once did some work related to this:
> >
http://news.povray.org/povray.binaries.images/thread/<Xns9327B41C265F5torolavk%40204.213.191.226>
> >
> > I believe that I still have the code somewhere if anyone is interested.
>
> That would be a great step forward for me to see what you've done.
>
>
> Perhaps even others could use it as an inspiration for further work on the
> alternate camera types and interesting pigment functions I've seen being dabbled
> with recently.
>
> Thanks  :)


Today I finally found the relevant file on an old hard drive.
Now my camera macros can be found here:

From: Tor Olav Kristensen
Subject: Camera macros
Date: 6 Nov 2016 17:20:01
Newsgroup: povray.text.scene-files
http://news.povray.org/povray.text.scene-files/thread/%3Cweb.581f64ae58540c2516a478410%40news.povray.org%3E/

--
Tor Olav
http://subcube.com


Post a reply to this message

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