POV-Ray : Newsgroups : povray.animations : how to check if an object is in the camera view Server Time
28 Jun 2024 22:55:13 EDT (-0400)
  how to check if an object is in the camera view (Message 1 to 8 of 8)  
From: Troya
Subject: how to check if an object is in the camera view
Date: 1 Nov 2005 12:05:01
Message: <web.4367a01218e30032656789670@news.povray.org>
Hi all,

I have an object that takes a lot of time to parse, so I only want to load
into the scene when the object shadow and the object itself is in the view
of the camera.
how I check if the object is going to be in the camera view?
load the object when is needed and dropit when is not.

Thanks
Oscar


Post a reply to this message

From: Jaap
Subject: Re: how to check if an object is in the camera view
Date: 1 Nov 2005 15:15:01
Message: <web.4367cc298e315a6a8399d8d0@news.povray.org>
The only way i can think of is doing it manually, but it can automated a
bit:

define a sphere (location and radius) that completely includes your object
and any possible shadows of it. Then calculate a vector from your camera
point in the look-at direction as well as a vector from the camera to the
center of the sphere.
Then Calculate the angle between the two vectors. This indicated how far
your object is from the center of the camera view (in radians).
Then take the distance from the camera to your object (center of the sphere)
and the radius of the sphere to calculate the "size" of the object in
radians.

then:
distance_center_of_camera_view - (object_size/2) - (diaginal_camera_angle/2)
(all in radians)
if the result is negative, part of the sphere (and so possibly your object)
could be within the camera view.

It would be nice to use the trace function to detect if the sphere is within
the camera view. it might work if you shoot a couple of ray's, one in each
corner of the camera view, and a couple along the edge and in the middle.
(only if your object is relatively big).

once you have worked out whether the object will be vi sable, you can just
use an IF statement to include an include file (with the actual object)
when needed.

anyone who can think of a simpler solution ?

jaap. (let me now if you need any help calculating the above)


Post a reply to this message

From: Norbert Kern
Subject: Re: how to check if an object is in the camera view
Date: 2 Nov 2005 15:25:01
Message: <web.4369204f8e315a6302fdb60@news.povray.org>
Hi,

look at
http://news.povray.org/povray.binaries.images/thread/%3C43236855@news.povray.org%3E/?ttop=218917&toff=50
..
In this thread you find a related topic to your problem.

Norbert Kern



"Troya" <nomail@nomail> wrote:
> Hi all,
>
> I have an object that takes a lot of time to parse, so I only want to load
> into the scene when the object shadow and the object itself is in the view
> of the camera.
> how I check if the object is going to be in the camera view?
> load the object when is needed and dropit when is not.
>
> Thanks
> Oscar


Post a reply to this message

From: Troya
Subject: Re: how to check if an object is in the camera view
Date: 2 Nov 2005 18:30:01
Message: <web.43694ade8e315a6de2083e10@news.povray.org>
Thanks.

I will let you know if I can make it work.
Oscar


Post a reply to this message

From: Troya
Subject: Re: how to check if an object is in the camera view
Date: 5 Nov 2005 15:20:00
Message: <web.436d12e48e315a6de2083e10@news.povray.org>
Thanks Jaap,

it was really good your explanation.
here is code that I'm using, it is not perfect but I think it will work in
90% of the cases. Also thanks to Friedrich A. Lohmueller site he has a page
named "Analytical Geometry with POV-Ray" very good stuff.

// Variables
#declare cameralocation = <5-clock, 0.5, -4.0>;
#declare cameralookat =    <5-clock, 0.5,  0.0>;
#declare camerangle = 90;


//////
#declare sphereradio = .1    ;
#declare sphereposition = <5,1,0>;

#declare A  = cameralocation;  // camera position
#declare B  = cameralookat;  // look at posision
#declare C  = sphereposition;    // cylinder position
#declare AB = B-A;
#declare AC = C-A;
#declare BC = AC-AB;

//#declare D = A + AB + AC;

#declare objectangle = VAngleD(AC,AB);
#if (objectangle<((camerangle+5)/2))
#declare #include "myfile.inc"
#else
#declare #include "myfiletest.inc"
#end

as I told you is not 100% perfect but for animations with really big include
files is a time saver.

oscar


Post a reply to this message

From: Jaap
Subject: Re: how to check if an object is in the camera view
Date: 6 Nov 2005 17:20:01
Message: <web.436e81758e315a6a8399d8d0@news.povray.org>
Very nice.

I see you used an extra 2.5 degrees at either side of the camera angle, and
you
ignored the radius of your object "sphere". You will have to make sure that
this save margin is sufficient for the object size and it's shadows (if
any).
If you are using radiosity, you could replace the object with a simpler
version and a plain texture, because (large) objects outside the camera
view still can affect the lighting when radiosity is used.

I never used this trick myself, but i will try it in my next animation.


Post a reply to this message

From: Jaap
Subject: Re: how to check if an object is in the camera view
Date: 6 Nov 2005 17:50:00
Message: <web.436e87d88e315a6a8399d8d0@news.povray.org>
you could use the sphereradio:  (all code untested)
(I assume you will be change the camera or object position with the "clock")

// Variables
#declare cameralocation = <5-clock, 0.5, -4.0>;
#declare cameralookat =    <5-clock, 0.5,  0.0>;
#declare camerangle = 90;

camera {
  location  cameralocation
  sky       z // you probably use y for up ??)
//up        z
  right     -x*image_width/image_height // (=camera aspect ratio)
  look_at   cameralookat
  angle     camerangle
}

//////
#declare sphereradio = .1    ;
#declare sphereposition = <5,1,0>;

#declare A  = cameralocation;  // camera position
#declare B  = cameralookat;  // look at posision
#declare C  = sphereposition;    // cylinder position
#declare AB = B-A;
#declare AC = C-A;
//#declare BC = AC-AB;  // (not used)
#declare objectDistance = vlength(AC);
#declare objectSize = degrees(asin(sphereradio/objectDistance)); //(half of
it)
#declare extraSize = 1.0; //(degrees) (zero should be possible!)
//#declare D = A + AB + AC;
#declare objectangle = VAngleD(AC,AB);
#if ( objectangle < ((camerangle/2)+extraSize+objectSize) )
  #declare #include "myfile.inc"
#else
  #declare #include "myfiletest.inc" // (empty or simplifyed version)
#end


Post a reply to this message

From: Troya
Subject: Re: how to check if an object is in the camera view
Date: 8 Nov 2005 09:20:01
Message: <web.4370b3df8e315a6656789670@news.povray.org>
great the last revision works much better.
Oscar


Post a reply to this message

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