POV-Ray : Newsgroups : povray.newusers : object variables for rending similar objects differently Server Time
24 Nov 2024 02:27:42 EST (-0500)
  object variables for rending similar objects differently (Message 1 to 3 of 3)  
From: nip
Subject: object variables for rending similar objects differently
Date: 1 Nov 2010 07:20:01
Message: <web.4ccea11b6541604eb52264400@news.povray.org>
Hello!

I'm wondering if there's a way to supply variables\values to a union object to
alter the way it is rendered. I'm not sure if I've worded that correctly, so
consider the code below. I'm trying to rotate the top box on the second figure,
but leave the first figure as-is. Is something like this possible or would I
need completely separate declarations for each "pose".

Thanks for any help you can offer.
-nip



Sample code:

#include "colors.inc"

#declare Tilted = 0.0;

#declare Figure = union {
    box {
        <0, 0, 0>, <1, 1, 1>
        pigment { Green }
    }

    box {
        <0, 0, 0>, <1, 1, 1>
        pigment { Blue }

        #if (Tilted > 0)
            rotate z*15
        #end

        translate y*1
    }
}

object { Figure }

object {
    #declare Tilted = 1; //this does not make the right blue box rotate
    Figure
    translate <2, 0, 0>
}


camera {
    location <5, 1, -5>
    look_at <0, 1, 3>
}


light_source {
    <5, 1, -5>
    color rgb <1, 1, 1>
}


Post a reply to this message

From: Jim Holsenback
Subject: Re: object variables for rending similar objects differently
Date: 1 Nov 2010 07:45:46
Message: <4ccea86a$1@news.povray.org>
On 11/01/2010 08:14 AM, nip wrote:
> Hello!
> 
> I'm wondering if there's a way to supply variables\values to a union object to
> alter the way it is rendered. I'm not sure if I've worded that correctly, so
> consider the code below. I'm trying to rotate the top box on the second figure,
> but leave the first figure as-is. Is something like this possible or would I
> need completely separate declarations for each "pose".
> 
> Thanks for any help you can offer.
> -nip
> 
> 
> 
> Sample code:
> 
> #include "colors.inc"
> 
> #declare Tilted = 0.0;
> 
> #declare Figure = union {
>     box {
>         <0, 0, 0>, <1, 1, 1>
>         pigment { Green }
>     }
> 
>     box {
>         <0, 0, 0>, <1, 1, 1>
>         pigment { Blue }
> 
>         #if (Tilted > 0)
>             rotate z*15
>         #end
> 
>         translate y*1
>     }
> }
> 
> object { Figure }
> 
> object {
>     #declare Tilted = 1; //this does not make the right blue box rotate
>     Figure
>     translate <2, 0, 0>
> }
> 
> 
> camera {
>     location <5, 1, -5>
>     look_at <0, 1, 3>
> }
> 
> 
> light_source {
>     <5, 1, -5>
>     color rgb <1, 1, 1>
> }
> 
> 
> 

a macro is what you need:
http://wiki.povray.org/content/Documentation:Reference_Section_2.6#The_.23macro_Directive

you problem is a simple one so I'll get you started, give this a whirl:
#macro Figure (Tilted)
union {
    box {
        <0, 0, 0>, <1, 1, 1>
        pigment { Green }
    }

    box {
        <0, 0, 0>, <1, 1, 1>
        pigment { Blue }

        #if (Tilted > 0)
            rotate z*15
        #end

        translate y*1
    }
}
#end

object { Figure (0)  }
object { Figure (1) translate <2,0,0> }


Post a reply to this message

From: nip
Subject: Re: object variables for rending similar objects differently
Date: 1 Nov 2010 16:45:01
Message: <web.4ccf263dc5b54ea8b52264400@news.povray.org>
Jim Holsenback <jho### [at] povrayorg> wrote:
> On 11/01/2010 08:14 AM, nip wrote:
> > Hello!
> >
> > I'm wondering if there's a way to supply variables\values to a union object to
> > alter the way it is rendered. I'm not sure if I've worded that correctly, so
> > consider the code below. I'm trying to rotate the top box on the second figure,
> > but leave the first figure as-is. Is something like this possible or would I
> > need completely separate declarations for each "pose".
> >
> > Thanks for any help you can offer.
> > -nip
> >
> >
> >
> > Sample code:
> >
> > #include "colors.inc"
> >
> > #declare Tilted = 0.0;
> >
> > #declare Figure = union {
> >     box {
> >         <0, 0, 0>, <1, 1, 1>
> >         pigment { Green }
> >     }
> >
> >     box {
> >         <0, 0, 0>, <1, 1, 1>
> >         pigment { Blue }
> >
> >         #if (Tilted > 0)
> >             rotate z*15
> >         #end
> >
> >         translate y*1
> >     }
> > }
> >
> > object { Figure }
> >
> > object {
> >     #declare Tilted = 1; //this does not make the right blue box rotate
> >     Figure
> >     translate <2, 0, 0>
> > }
> >
> >
> > camera {
> >     location <5, 1, -5>
> >     look_at <0, 1, 3>
> > }
> >
> >
> > light_source {
> >     <5, 1, -5>
> >     color rgb <1, 1, 1>
> > }
> >
> >
> >
>
> a macro is what you need:
>
http://wiki.povray.org/content/Documentation:Reference_Section_2.6#The_.23macro_Directive
>
> you problem is a simple one so I'll get you started, give this a whirl:
> #macro Figure (Tilted)
> union {
>     box {
>         <0, 0, 0>, <1, 1, 1>
>         pigment { Green }
>     }
>
>     box {
>         <0, 0, 0>, <1, 1, 1>
>         pigment { Blue }
>
>         #if (Tilted > 0)
>             rotate z*15
>         #end
>
>         translate y*1
>     }
> }
> #end
>
> object { Figure (0)  }
> object { Figure (1) translate <2,0,0> }

Excellent! Macros look pretty powerful. Thanks


Post a reply to this message

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