POV-Ray : Newsgroups : povray.advanced-users : Calculating visible camera area : Re: Calculating visible camera area Server Time
28 Apr 2024 08:58:18 EDT (-0400)
  Re: Calculating visible camera area  
From: Bald Eagle
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

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