POV-Ray : Newsgroups : povray.general : Focus and centering object in the view. : Re: Focus and centering object in the view. Server Time
29 Jul 2024 00:37:38 EDT (-0400)
  Re: Focus and centering object in the view.  
From: Alain
Date: 7 Nov 2013 23:12:23
Message: <527c64a7$1@news.povray.org>

> Hi,
>
>      I have a script where it imports an object and render it to get an image.
>
>      The fact is that all works fine but the question is that the script can
> import any kind of object and it should adapt the camera to focus the object
> almost the 80% of view. I mean, if the object is too small, the camera should
> zoom + to get the object size almost the 80% and in case the object is too big,
> it should zoom - to get the same situation.
>
>      How can I accomplish this?
>

You have another possibility: Adjust the dimention of the object to a 
given dimention.

You can get the extent of the bounding box of an object using 
min_extent(Object_Name) and max_extent(Object_Name).
Using the returned values, you can compute a scaling factor to adjust 
the dimention of the object to your liking.

This will resize an object to 10 units in the vertical direction:

// This assume that you have previously declared
// an object with the name "MyObject"
// Get the extent of MyObject
#declare Min = min_extent(MyObject);
#declare Max = max_extent(MyObject);
// Calculate it's vertical dimention
#declare V_Dim = Max.y - Min.y;
// Instanciate and scale MyObject
object{MyObject scale 10/V_Dim}


Also, you can relocate your object to the origin if needed, like when 
the object was not created at the origin.


Alain


Post a reply to this message

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