POV-Ray : Newsgroups : povray.newusers : Sub-Routines Server Time
4 Nov 2024 17:46:48 EST (-0500)
  Sub-Routines (Message 1 to 5 of 5)  
From: Martin
Subject: Sub-Routines
Date: 29 Nov 2001 14:48:53
Message: <3C0691E3.A477B1CC@radiok2r.de>
Hello!

I need to draw some csg-union-objects a lot of times in different places
in my povray-script. Whats the best way to do it? Functions? Macros? Any
other thing I just didn't see?

Martin


Post a reply to this message

From: Warp
Subject: Re: Sub-Routines
Date: 29 Nov 2001 16:05:02
Message: <3c06a2fd@news.povray.org>
Martin <mar### [at] radiok2rde> wrote:
: I need to draw some csg-union-objects a lot of times in different places
: in my povray-script. Whats the best way to do it? Functions? Macros? Any
: other thing I just didn't see?

  This could perhaps be called "advanced feature blindness". That is, people
only see highly advanced features and are blind to the simplest control
structures.
  You just make an identifier from your union:

#declare MyUnion =
  union
  { whatever
  }

  Then you can make copies of that:

object { MyUnion translate <1,2,3> }
object { MyUnion translate <-3,-2,-1> }
and so on.

  If you want to place them in a regular pattern (eg a straight line), you
can use a #while-loop.

-- 
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

From: Martin Thoma
Subject: Re: Sub-Routines
Date: 30 Nov 2001 07:45:08
Message: <3C077F11.3339D552@radiok2r.de>
Thanx, but how can I give soemthing like paramters to it? For example, I have a
complex object, which sometime has a part of it drawn and sometimes not. Is it
possible to make this in one define?!

Martin


Post a reply to this message

From: Trevor Quayle
Subject: Re: Sub-Routines
Date: 30 Nov 2001 07:54:43
Message: <3c078193$1@news.povray.org>
I like using macros for objects with variable parameters

Bonus example:
Bendable nail

#macro Nail (Dia,Len,Bend,BLen,Dirn)
  union{
    union{
      cylinder{<0,1,0> <0,0,0> 1.5*Dia}
      cylinder{<0,0,0> <0,-(Len-BLen-1.5*Dia*pi*Bend/360),0> Dia/2}
      torus{0.25 Dia/2 scale<1,0.2,1> translate <0,-2,0>}
      torus{0.25 Dia/2 scale<1,0.2,1> translate <0,-3,0>}
      torus{0.25 Dia/2 scale<1,0.2,1> translate <0,-4,0>}
      translate <-1.5*Dia,Len-BLen-1.5*Dia*pi*Bend/360,0>
      rotate<0,0,-Bend>
      translate <1.5*Dia,BLen,0>
    }
    #if (mod(Bend,360)>0)
      difference{
        torus{1.5*Dia Dia/2 rotate<90,0,0>}
        plane{y 0}
        plane{-y 0 rotate<0,0,-Bend>}
        translate <1.5*Dia,BLen,0>
      }
    #end
    cylinder{<0,3*Dia,0> <0,BLen,0> Dia/2}
    difference{
      cylinder{<0,0,0> <0,3*Dia,0> Dia/2}
      plane{-z 0 rotate <12,  0,0>}
      plane{-z 0 rotate <10, 90,0>}
      plane{-z 0 rotate <12,180,0>}
      plane{-z 0 rotate <10,270,0>}
    }
    rotate 90*<Dirn.z+Dirn.y-abs(Dirn.y),0,-Dirn.x>
  }
#end


-tgq


"Martin Thoma" <mar### [at] radiok2rde> wrote in message
news:3C077F11.3339D552@radiok2r.de...
> Thanx, but how can I give soemthing like paramters to it? For example, I
have a
> complex object, which sometime has a part of it drawn and sometimes not.
Is it
> possible to make this in one define?!
>
> Martin
>
>
>


Post a reply to this message

From: Martin Thoma
Subject: Re: Sub-Routines
Date: 30 Nov 2001 08:59:17
Message: <3C079071.DABBC76F@radiok2r.de>
Thanx, that looks like what I need ;-)


Post a reply to this message

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