POV-Ray : Newsgroups : povray.advanced-users : Camera positioning Server Time
28 Jul 2024 16:20:28 EDT (-0400)
  Camera positioning (Message 1 to 4 of 4)  
From: kjm424
Subject: Camera positioning
Date: 17 Dec 2004 05:45:00
Message: <web.41c2b67e219a48abce1a9020@news.povray.org>
I'm currently working on a project that generates povray scenes
programmatically. These scenes can vary in overall dimensions, and I am
having diffculty calculating a camera position that incorporates every
element of the scene, without introducing lots of space around the edges.

Is there a way to calculate the position of the camera, knowing what
direction it should point in. My 3d trig. just isn't up to the challenge.

Values that are known are:
 - A list of scene extremities as 3d coordinates (e.g. a simple block would
have 8 extremities)
 - The camera angle (set at 20 degrees)
 - The direction the camera should point in
 - The aspect ratio

I would appreciate any comments/suggestions(or solutions :) )


Post a reply to this message

From: Derek Chen-Becker
Subject: Re: Camera positioning
Date: 17 Dec 2004 08:33:26
Message: <41c2e026$1@news.povray.org>
kjm424 wrote:
> I'm currently working on a project that generates povray scenes
> programmatically. These scenes can vary in overall dimensions, and I am
> having diffculty calculating a camera position that incorporates every
> element of the scene, without introducing lots of space around the edges.
> 
> Is there a way to calculate the position of the camera, knowing what
> direction it should point in. My 3d trig. just isn't up to the challenge.
> 
> Values that are known are:
>  - A list of scene extremities as 3d coordinates (e.g. a simple block would
> have 8 extremities)
>  - The camera angle (set at 20 degrees)
>  - The direction the camera should point in
>  - The aspect ratio
> 
> I would appreciate any comments/suggestions(or solutions :) )
> 

There may be a simpler way to do this, but basically here's what you 
have to do:

1. Recalculate your scene bounds in camera space. Camera space is 
defined by the matrix

| < right vector>     |   |                           |
| < up vector>        | * | camera translation matrix |
| < direction vector> |   |                           |

To convert from scene space to camera space, take the inverse of that 
matrix and multiply each corner of your original bounds by that. Note 
that the result of these calculations will make the camera move along 
its "direction" vector, so you want to choose a translation matrix that 
makes the direction vector intersect the center point of your scene 
(unless you desire an offset. Then you can recalculate your bounds by 
taking the new max and min of these points in the "camera" x, y and z 
directions.

2. Now that you have the new bounds it's simple trig to determine how 
far away the scene box needs to be from the camera to fit inside the 
view frustum. From this you can calculate a vector from the camera 
location (<0,0,0> in camera space) to center of the original scene box.

3. Perform the inverse of the camera space transformation on the vector 
and add this vector to the center of your viewspace. This gives you the 
correct camera location.

This may be easier to digest in a diagram. I'm sure there's something on 
the Internet, or I could put something together if you want. Also, POV 
may have some built in functions that handle the transformations/bounds 
for you.

Derek


Post a reply to this message

From: kjm424
Subject: Re: Camera positioning
Date: 29 Dec 2004 09:05:01
Message: <web.41d2b921e563b829bce1a9020@news.povray.org>
Derek Chen-Becker <pov### [at] chen-beckerorg> wrote:
> There may be a simpler way to do this, but basically here's what you
> have to do:
>
> 1. Recalculate your scene bounds in camera space. Camera space is
> defined by the matrix
>
> | < right vector>     |   |                           |
> | < up vector>        | * | camera translation matrix |
> | < direction vector> |   |                           |
>
> To convert from scene space to camera space, take the inverse of that
> matrix and multiply each corner of your original bounds by that. Note
> that the result of these calculations will make the camera move along
> its "direction" vector, so you want to choose a translation matrix that
> makes the direction vector intersect the center point of your scene
> (unless you desire an offset. Then you can recalculate your bounds by
> taking the new max and min of these points in the "camera" x, y and z
> directions.
>
> 2. Now that you have the new bounds it's simple trig to determine how
> far away the scene box needs to be from the camera to fit inside the
> view frustum. From this you can calculate a vector from the camera
> location (<0,0,0> in camera space) to center of the original scene box.
>
> 3. Perform the inverse of the camera space transformation on the vector
> and add this vector to the center of your viewspace. This gives you the
> correct camera location.
>
> This may be easier to digest in a diagram. I'm sure there's something on
> the Internet, or I could put something together if you want. Also, POV
> may have some built in functions that handle the transformations/bounds
> for you.
>
> Derek

Thanks Derek.

I think a diagram would be useful as I am not very familiar with matrices.
I'm finding it quite difficult to get my head round different coordinate
systems.

I don't really understand how to get the 'camera translation matrix' when
the distance from the scene to the camera position is an unknown.

Thanks for your help,
Kevin.


Post a reply to this message

From: Florian Brucker
Subject: Re: Camera positioning
Date: 7 Jan 2005 09:11:38
Message: <41de989a@news.povray.org>
Normally, I prefer the other way round: First create a scene with a 
dummy object in it (like box { <-1,-1,-1>,<1,1,1> }) and manually adjust 
your camera so that this object is captured as you want.
Now if you want to create a picture of another object, pick it's largest 
extremity and scale the whole object by 1/extremity, so that it fits 
inside the object you calibrated the camera for.


HTH,
Florian
-- 
camera{look_at-y*10location<8,-3,-8>*10}#local a=0;#while(a<999)sphere{
#local _=.01*a-4.99;#local p=a*.01-5;#local c=.01*a-4.995;<sin(p*pi)*5p
*10pow(p,5)*.01>sin(c*c*c*.1)+1pigment{rgb 3}}#local a=a+1;#end
/******** http://www.torfbold.com ******** http://www.imp.org ********/


Post a reply to this message

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