POV-Ray : Newsgroups : povray.general : Focus and centering object in the view. Server Time
25 Dec 2024 20:54:36 EST (-0500)
  Focus and centering object in the view. (Message 1 to 3 of 3)  
From: apalabrados
Subject: Focus and centering object in the view.
Date: 5 Nov 2013 05:40:01
Message: <web.5278ca56326f8209feb993600@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?

The code I use is:

#include "{{INCLUDE_FILE}}"
#include "{{BASE_PATH}}/axes_macro.inc"
#include "math.inc"
#include "finish.inc"
#include "transforms.inc"
#include "{{BASE_PATH}}/base_render.inc"
#include "{{BASE_PATH}}/center_volumen.inc"
#include "colors.inc"
#include "textures.inc"

#declare maxcorner  = 0;
#declare mincorner  = 0;
#declare max_x  = 0;
#declare min_x  = 0;
#declare max_y  = 0;
#declare min_y  = 0;
#declare max_z  = 0;
#declare min_z  = 0;

background {color rgb 0.1}

global_settings {
  assumed_gamma 2
  ambient_light rgb<1, 0, 0>
}

sky_sphere
{
 pigment
 {
  gradient y
  color_map
  {
   [0.0 rgb <1.0,1.0,1.0>]  //153, 178.5, 255 //150, 240, 192
   [0.7 rgb <0.9,0.9,0.9>]  //  0,  25.5, 204 //155, 240, 96
  }
  scale 2
  translate 1
 }
}

object {

 {{MODELNAME}}

 Center_Trans({{MODELNAME}}, x+y+z)

 texture {
  pigment { Red }
  finish { ambient 0.1
                 diffuse 0.9
                 phong 1 }
 }

 #declare maxcorner  = max_extent({{MODELNAME}});
 #declare mincorner  = min_extent({{MODELNAME}});
 #declare max_x  = max(maxcorner.x,mincorner.x);
 #declare min_x  = min(maxcorner.x,mincorner.x);
 #declare max_y  = max(maxcorner.y,mincorner.y);
 #declare min_y  = min(maxcorner.y,mincorner.y);
 #declare max_z  = max(maxcorner.z,mincorner.z);
 #declare min_z  = min(maxcorner.z,mincorner.z);

 FindObjectCenter( {{MODELNAME}} )
}

camera {
    location <0,200,0>
 up    <0,1,0>
 look_at <0,0,0>
}

object {
 light_source {
   <max_x+100, 0, 0>
   rgb 0.5
  shadowless
 }
}
light_source {
        <0, max_y+100, 0>
        rgb 0.5
 shadowless
}
light_source {
        <0, 0, 100>
        rgb 0.5
 shadowless
}

Thanks.


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Focus and centering object in the view.
Date: 5 Nov 2013 15:57:28
Message: <52795bb8@news.povray.org>
>     How can I accomplish this?

screen.inc should contain the camera calculations you seek,
even if your use case is not a classic "screen object".


Post a reply to this message

From: Alain
Subject: Re: Focus and centering object in the view.
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.