|
![](/i/fill.gif) |
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
|
![](/i/fill.gif) |