POV-Ray : Newsgroups : povray.general : Aligning objects programatically Server Time
2 Aug 2024 18:10:41 EDT (-0400)
  Aligning objects programatically (Message 1 to 4 of 4)  
From: Bill
Subject: Aligning objects programatically
Date: 28 Jul 2004 18:47:17
Message: <opsbvdk8oq1d91cn@personal.bc.hsia.telus.net>
I'm trying to get a text object to align relative to the center of a  

sphere. The sphere is at <0,0,0>.  Since text initially sits with the  

front-bottom-left corner at <0,0,0>, I've translated it to be just in  

front of the sphere.

The challenge is to get the correct x-coordinate fot the text object so 
it  

is centered relative to the sphere.  So far, all I know how to do is  

adjust the x coordinate by trial-and-error.  Is there some way to obtain
  

the size of the text programatically and set it's location using an  

expression?

Thanks,
Bill

-- 

Using Opera's revolutionary e-mail client: http://www.opera.com/m2/


Post a reply to this message

From: Dave VanHorn
Subject: Re: Aligning objects programatically
Date: 28 Jul 2004 19:53:45
Message: <41083c89$1@news.povray.org>
The challenge is to get the correct x-coordinate fot the text object so it
is centered relative to the sphere.  So far, all I know how to do is
adjust the x coordinate by trial-and-error.  Is there some way to obtain
the size of the text programatically and set it's location using an
expression?

This is a bit of a peeve of mine, with how the primitives in pov are done.

Spheres have their centers at 0,0,0.
Cubes start with one corner at 0,0,0, and go to the opposite corner at 1,1,1
so the natural center is at 0.5, 0.5, 0.5

You have to think ahead, and locate the center of the object where it makes
sense.
For some things, it's the geometric center, others it will be the center of
"mass", or some other point, depending on how it's used in the scene. and
combined with other objects.

If you defined a washer (as in hardware store) you'd probably want one face
to sit at 0,0,0, and the other at 0,(0+Washer_Thickness), 0  so that you
could put it at 0,0+Cube_High,0 and have it sitting on top of the cube,
rather than IN the cube, or just above the cube.


Post a reply to this message

From: Mike Williams
Subject: Re: Aligning objects programatically
Date: 28 Jul 2004 20:27:38
Message: <QjxXHBAyRECBFwPX@econym.demon.co.uk>
Wasn't it Bill who wrote:
>I'm trying to get a text object to align relative to the center of a  
>sphere. The sphere is at <0,0,0>.  Since text initially sits with the  
>front-bottom-left corner at <0,0,0>, I've translated it to be just in  
>front of the sphere.
>
>The challenge is to get the correct x-coordinate fot the text object so it  
>is centered relative to the sphere.  So far, all I know how to do is  
>adjust the x coordinate by trial-and-error.  Is there some way to obtain  
>the size of the text programatically and set it's location using an  
>expression?

You can centre text, or any other type of object, in one dimension with
Center_Object().

#declare T = text { ttf  "crystal.ttf", "POV-Ray", 2, 0 pigment {rgb x}}
#include "shapes.inc"
Center_Object(T,x)


You can centre text, or any other type of object, in three dimensions
like this:

#declare T = text { ttf  "crystal.ttf", "POV-Ray", 2, 0 pigment {rgb x}}
object {T translate -(min_extent(T) + max_extent(T))/2}


There's also Text_Space() and Text_Width() in "shapes.inc" that perform
the (max_extent(T).x-min_extent(T).x) calculation for you.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From:
Subject: Re: Aligning objects programatically
Date: 28 Jul 2004 21:19:58
Message: <410850be@news.povray.org>
// Hi Bill,
//
// min_extent and max_extent will help centering text;
// this whole post is a demo scene -- render with
// -F +W512 +H384 +A0.1
//
// Replace "/2*x" by
//   "/2*<1,1,0>" to center along x and y
//   "/2"         to center along all axes
//   "*-1"        to right-justify
//   "*<1,.5,0>   to right-justify and center along y
//   etc. (and change the macro's name accordingly!)
//
//  Sputnik


// macros to center an object along the x-axis
// (more precisely: to center the bounding box of
// the object; this works well for text objects)

#macro Simple_center_along_x (Obj)
    object { Obj translate -(max_extent(Obj)-min_extent(Obj))/2*x }
    #end//macro Simple_center_along_x

#macro Center_along_x (Obj)
    object { Obj translate -(max_extent(Obj)-min_extent(Obj))/2*x
    // "}" omitted to allow modifiers without object{...}
    #end//macro Center_along_x


// a text object

#declare TextObject = text { ttf "timrom.ttf" "[---Text---]" 0.1, 0
    pigment { color rgb 1 }
    }


// put centered text into scene

Simple_center_along_x ( TextObject ) // that's all!

object { Simple_center_along_x ( TextObject )
    translate -z
    }

Center_along_x ( TextObject ) // {
    translate -2*z
    }


// origin, z-axis, x-z-plane, light and camera

union {
    sphere { 0, 0.1 }
    cylinder { -3*z, 3*z, 0.02 }
    cone { 3*z, 0.1, 3.5*z, 0 }
    pigment { color green 1 }
    finish { ambient .3 diffuse .7 }
    }

plane { y, 0
    pigment { checker rgbt <1, .7, 0, .4> rgbt <1, 1, 0, .4> }
    finish { ambient .3 diffuse .7 }
    }

light_source { <-1, 3, -2>*100, rgb 1 }

camera { location -4.5*z look_at 0 rotate <40, 20, 0> translate -z }


// END


Post a reply to this message

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