POV-Ray : Newsgroups : povray.newusers : centering an object and making it fit the output screen Server Time
26 Nov 2024 12:31:55 EST (-0500)
  centering an object and making it fit the output screen (Message 1 to 1 of 1)  
From: nomail
Subject: centering an object and making it fit the output screen
Date: 15 Jun 2004 12:20:01
Message: <web.40cf218750b0549c871b0a600@news.povray.org>
I imported a tree I made in xfrog and I can make it fit (more or less...) by
scaling the object and adjusting the camera position. What I'd really like
is a way do this based on the object's size. I searched this site, found
several posts about this topic and I can get the code to work but it doesn't
center the camera properly.

Currently I'm using this code to center and scale the tree:

//start code

#include "screen.inc"
#include "transforms.inc"

#declare Tree=union{
    object{ P_trunk }
    object{ P_b1 }
    object{ P_b2 }
    object{ P_b3 }
    object{ P_b4 }
    object{ P_b401 }
    object{ P_b402 }
    object{ P_b403 }
    object{ P_b404 }
    object{ P_leaves }
    object{ P_leaves01 }
    object{ P_leaves02 }
    object{ P_leaves03 }
    hollow
    rotate x*-90
    }

object {Tree Center_Trans(Tree, x+y+z)}    //line to center object, this one
is
                                            giving me trouble

#declare MinY = min_extent(Tree).y;       //Get minimum y value of object
#declare MaxY = max_extent(Tree).y;       //Get maximum y value of object
#declare SizeY= abs(MaxY)+abs(MinY);      //Calculate size in y direction
#declare MinX = min_extent(Tree).x;       //Get minimum x value of object
#declare MaxX = max_extent(Tree).x;       //Get maximum x value of object
#declare SizeX= abs(MaxX)+abs(MinX);      //Calculate size in x direction

#declare ScaledTree =
object{
   #if (SizeX > SizeY)
      #local objScale = 0.99/SizeX;
   #else
      #local objScale = 0.99/SizeY;
   #end
   Tree
   scale objScale
}

Screen_Object (ScaledTree, <0.5,0.5>, 0, true, 1.0)

//end code

If I use this code as shown above it renders just a part of the tree
(presumably the center) and it doesn't fit in the window at all. If I leave
out the line
with "object {Tree Center_Trans(Tree, x+y+z)}" it renders the complete
tree, but the camera is "looking down" on the tree.

Could someone please point out what I'm doing wrong?

Peter Geraedts


Post a reply to this message

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