POV-Ray : Newsgroups : povray.general : centering an object for the camera Server Time
2 Nov 2024 11:23:26 EDT (-0400)
  centering an object for the camera (Message 1 to 4 of 4)  
From: Eric Medlin
Subject: centering an object for the camera
Date: 14 Apr 2004 14:13:27
Message: <eric.medlin-4FE5FD.14132614042004@news.povray.org>
I would like to be able to have code in my scene.pov file that will 
center objects and move the camera or object so that the model will fill 
most of the scene.  So far I have found this.
object{
   model // defined as a mesh2 object in another file
   Center_Trans(model, x+y+z)
}
This will move the object so that the center of it's bounding box is at 
0,0,0.  For my objects the center of the bounding box works fine for 
centering.  Now how can I move the object and camera closer or farther 
apart in povray so that it will fill up the scene.  Right now I have the 
camera hard coded to allow the largest object to fit in the scene, but 
some of my smaller objects appear to small.  I was thing I might could 
get the bounding box's height and width and use them to determine how 
far apart the camera and object need to be, but so far I have not been 
able to find out how to get it.


Post a reply to this message

From: Florian Brucker
Subject: Re: centering an object for the camera
Date: 15 Apr 2004 17:27:59
Message: <407efe5f$1@news.povray.org>
I'd try it the other way round:

Set up a scene with some dummy boxes and adjust the camera in a way that 
it fits your needs. Later replace the dummy boxes by your real objects 
and scale them to fit the dimensions of the old dummies. This can be 
done pretty easy using min_extent and max_extent. And it is really 
easier than calculate new camera parameters.

HTH,
Florian


Post a reply to this message

From: Eric Medlin
Subject: Re: centering an object for the camera
Date: 16 Apr 2004 10:27:11
Message: <eric.medlin-EAF253.10271016042004@news.povray.org>
In article <407efe5f$1@news.povray.org>,
 Florian Brucker <tor### [at] torfboldcom> wrote:

> I'd try it the other way round:
> 
> Set up a scene with some dummy boxes and adjust the camera in a way that 
> it fits your needs. Later replace the dummy boxes by your real objects 
> and scale them to fit the dimensions of the old dummies. This can be 
> done pretty easy using min_extent and max_extent. And it is really 
> easier than calculate new camera parameters.
> 
> HTH,
> Florian
> 

Well I am doing the follow now.
#declare scaledContainer =
object{
   #local objMax = max_extent(container);
   #local objMin = min_extent(container);
   #local objdim = objMax-objMin;
   #if (objDim.x > objDim.y)
      #local objScale = 0.75/objDim.x;
   #else
      #local objScale = 0.75/objDim.y;
   #end
   container
   scale objScale
}
Screen_Object(scaledContainer, <0.5, 0.5>, <0, 0>, true, 1.0)
This seems similar to what you are talking about.  This seems to work 
pretty good on the models I have tried it on.  I thought Screen_Object() 
would do everything for me when I found that macro but it doesn't seem 
to be able to scale the object to make it fit the screen only move it in 
front of the camera, still helpful though.  Any suggestions on improving 
this or know of something that could break its centering ablity?


Post a reply to this message

From: Florian Brucker
Subject: Re: centering an object for the camera
Date: 18 Apr 2004 11:31:34
Message: <40829f56@news.povray.org>
> Any suggestions on improving 
> this or know of something that could break its centering ablity?

The only thing I can imagine which would break this method would be bad 
bounding boxes like

sphere {
	0,1
	bounded_by { box { -<100,1,1>,1 } }
}

(not as a result of manual bounding as shown here, but as a result of 
complex CSG). But I don't know a method which would not fail in that 
case (aside from scanning the whole bounding box via trace...). And I 
don't think it'll happen too often.

To make your code just that bit more handy, I'd shorten it into one 
single macro a la:

#macro Scaled_Screen_Object()

which would rescale a given object and pass it to Screen_Object. This 
would make your code more reusable. And of course

    #local objMax = max_extent(container);
    #local objMin = min_extent(container);
    #local objdim = objMax-objMin;

could be shortened to

	#local objdim = max_extent(container) - min_extent(container);

but that's not really necessary.

HTH,
Florian


Post a reply to this message

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