POV-Ray : Newsgroups : povray.newusers : Declare : Re: Declare Server Time
6 Sep 2024 14:15:13 EDT (-0400)
  Re: Declare  
From: Nieminen Mika
Date: 8 Feb 1970 14:21:08
Message: <34de05a4.0@news.povray.org>
Mark Wright (ren### [at] myhousenet) wrote:
: Could you explain the declare statement to me?
: The help docs are great, but the declare examples they give
: don't seem to work for me. A simple sample of some source code
: would help alot.

  Someone explained something already, but I will try to help too...

  Unlike #define in C, #declare in povray doesn't just define text replacing
strings. You can define thinks like float values, vectors, textures,
objects, etc. For example:
#declare MyValue=10
says that the string 'MyValue' has the value 10. So, if you have for
example "rotate <MyValue,1,2>", this is the same thing as "rotate <10,1,2>".
#declare MyVector=<10,1,2>
defines a vector. Now you can type for example "rotate MyVector" and it
will be the same as "rotate <10,1,2>".
  These work just like the text replacing #define in C, but textures,
objects, etc work a bit different.
  Suppose you want to define a texture. You type for example:
#declare MyTexture=texture { pigment { rgb <1,0,0> } normal { bumps .2 } }
  When you want to use this texture in an object, you type:
  texture { MyTexture }
  You can also define pigments, normals, etc, like:
#declare MyPigment=
pigment
{ color rgbf <1,.5,0,.5>
}
#declare MyNormal=
normal
{ bumps .1 scale 2
}
  and then you can use them like this:

sphere
{ 0,1
  pigment { MyPigment }
  normal { MyNormal }
}

  You can also define an object or CSG:
#define MyObject=sphere{ 0,1 scale <.5,.4,1> }
#define MyCSG=
union
{ sphere { 0,2 }
  box { -1,1 }
}

  When you want to use these object, you use the 'object' directive like this:

object
{ MyObject
  scale 5
}
object
{ MyCSG
  translate x*5
}

  or for example:

difference
{ object { MyObject }
  object { MyCSG }
  texture { MyTexture }
}

--
                                                              - Warp. -


Post a reply to this message

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