POV-Ray : Newsgroups : povray.general : Center of OBJECT Server Time
1 Aug 2024 10:12:46 EDT (-0400)
  Center of OBJECT (Message 1 to 3 of 3)  
From: Andrej
Subject: Center of OBJECT
Date: 21 Nov 2005 08:53:47
Message: <4381d16b@news.povray.org>
I have a offset problem with object balls. With box, it's ok. If I change 
the Wi and Hi, the box will remain in center but the balls wouldn't.



//Offset problems

global_settings { assumed_gamma 2.2 }

camera
{
 location  <0, 0, -20>
 direction <0, 0, 1>
 look_at   <0, 0, 0>
}

light_source { <-10, 3, -20> color red 1 green 1 blue 1 }

sphere
{ <0, 0, 0>, 1
 pigment {color rgbt <1, 1, 1, 0.5>}
}


#declare balls = union
{
 #declare Hi=4;
 #declare Wi=6;
 #local CountX=0;
 #declare OffsetY=-Hi/2; // Ouch...
 #declare OffsetX=-2.5;  //Wi=2:0.5, 3:1, 4:1.5, 5:2, 6:2.5
 #while (CountX < Wi)
  #local CountY=0;
  #while (CountY < Hi)
   sphere { <CountX, CountY, 0>, 0.25
    pigment { color rgb <1, 1, 1>}
   }
   #local CountY=CountY+1;
  #end
  #local CountX=CountX+1;
 #end
}
object {balls translate <OffsetX, OffsetY, 0>}


#declare Box = union
{
 box{<0,0,0>,<Wi,Hi,1>
  pigment { color rgbt <1, 1, 1, 0.5>}
 }
}
object {Box translate <-Wi/2, -Hi/2, 0>}


Post a reply to this message

From: Chris B
Subject: Re: Center of OBJECT
Date: 21 Nov 2005 10:16:40
Message: <4381e4d8$1@news.povray.org>
"Andrej" <and### [at] emailwithoutspamsi> wrote in message 
news:4381d16b@news.povray.org...
>I have a offset problem with object balls. With box, it's ok. If I change 
>the Wi and Hi, the box will remain in center but the balls wouldn't.
>   ... snip ... #declare Hi=4;
>   ... snip ...
> #declare OffsetY=-Hi/2; // Ouch...
>   ... snip ...
>  #while (CountY < Hi)
>   ... snip ...
> object {balls translate <OffsetX, OffsetY, 0>}
>

Hi,

Your 'while' loop continues while CountY is less than Hi. ie. from CountY = 
0 to CountY = 3, so you draw a sphere from 0 to 3, then you offset the array 
of spheres by -2, so it won't be centred.
You probably want to use:  #while (CountY <= Hi)

Regards,
Chris B.


Post a reply to this message

From: Andrej
Subject: Re: Center of OBJECT
Date: 22 Nov 2005 05:00:08
Message: <4382ec28@news.povray.org>
> You probably want to use:  #while (CountY <= Hi)

Also valid for CounX. Thank you for the answer.


Post a reply to this message

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