Descriptions and Examples for the POV-Ray Raytracer by Friedrich A. Lohmüller
    Conditional Statements - examples of use -
Deutsch Deutsch

Home
- POV-Ray Tutorial

  - Conditional
    Statements

  Branching
    #if(...)... #else ... #end
    - in loops
    - in macros
    - in animations
    - turning on/off of parts
    #switch(...) #case .. #end
    - selection by tables

  Check for Existence
    #ifdef(...) #ifndef(...)
    - Check for include files
    >Defaults in include files

  Loops
 Prechecked, Postchecked,
 Count-controlled, Early-Exit
    #while(...)... #end
    #for(...)... #end
    - Samples:
    - Loops with POV-Ray
    - Loops, Sine, Cosine
    - Random with POV-Ray
                                       

Setting of Defaults in Include Files

With "#ifndef" we can define default values in include files which can be overwritten before including the include file.
Sample: In an include file for a street with middle stripes we want to have default textures for the texture of the street and also for the texture of the middle lines. But it must be possible to overwrite both textures if necessary.

To get undeclared variables for a new call of an include file with the default values we can use "#undef (Variable)" to destroy eventualy previous declarations of a variable with the same name.

Include file of a street with middle line:
//include file "Street_0.inc"
// ------------------------------------
#macro Street_0(  Street_Width,  //
                  Street_Length, //
                  Stripes_Width, //
                  Stripes_Len
                ) //-------------------
//-------------------------------------
#ifndef( Stripes_Texture )
#declare Stripes_Texture =
texture{ pigment{ color rgb<1,1,1>*1.1}
         finish { diffuse 0.9 phong 0.5}
       } // end of texture
#end //--------------------------------
#ifndef( Street_Texture )
#declare Street_Texture =
texture{ pigment{ color rgb<1,1,1>*.3}
         normal { bumps 0.5 scale 0.005}
         finish { diffuse 0.9 phong 0.1}
       } // end of texture
#end //--------------------------------
#local D = 0.001;
//-------------------------------------
union{
box{ <-Street_Width/2, 0, 0>,
     < Street_Width/2, D, Street_Len>
     texture{Street_Texture}
   } // end of box --------------------
 #local Number_of_Stripes =
   int(Street_Length/(2*Stripes_Len));
 #local Nr = 0; //start
 #local EndNr=Number_of_Stripes;//end
 #while (Nr< EndNr)
 box{ <-Stripes_Width/2,   0, 0>,
      < Stripes_Width/2,2*D,Stripes_Len>
      texture{ Stripes_Texture}
      translate<0,0,Nr*2*Stripes_Len>
    } // end of box
 #local Nr = Nr + 1;  // next Nr
 #end // -------- end of loop
} // end of union
#end//-------------------- end of macro
//----------------- end of include file
Reading the include file with the default values:
#include "Street_0.inc"
//------------------------------------
object{ Street_0 (   6, // Width,
                   500, // Length,
                  0.10, // Stripes_W,
                  1.00, // Stripes_Len
                 ) //-----------------
        translate<0,0,-5.00>}
//------------------------------------
Background

Reading the include file with changed textures:
#declare Street_Texture =
texture{ pigment{ color rgb<1,1,1>*0.4}
         normal { bumps 0.75 scale 0.015}
         finish { diffuse 0.9 phong 0.1}
       } // end of texture
#declare Stripes_Texture =
texture{ pigment{ color rgb<1,0.75,0>*1.1}
         finish { diffuse 0.9 phong 0.5}
       } // end of texture
#include "Street_0.inc"
//------------------------------------
object{ Street_0 (   6, // Width,
                   500, // Length,
                  0.10, // Stripes_W,
                  1.00, // Stripes_Len
                 ) //-----------------
        translate<0,0,-5.00>}
//------------------------------------
Background

top
© Friedrich A. Lohmüller, 2010
homepage:www.f-lohmueller.de