Descriptions and Examples for the POV-Ray Raytracer by Friedrich A. Lohmüller
    Conditional Statements -
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(..) ...
          #range(..) ... #end
    > selection by tables

  Check for Existence
    #ifdef(...) #ifndef(...)
    - Check in 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
                                       

Selection by tables by multiple branching

Sample for the use of a multiple branching by #switch for selecting texture sets for objects in scene:

#macro Car_Body_Texture_Set(Texture_Number)
#switch(Texture_Number)
#case (1)
 #declare Car_Body_Texture =
 texture{ pigment{ color rgb<1,0.96,0.94>*0.7}
  finish{ phong 1 reflection{.35,metallic .5}}
        } // end of texture
 #declare Car_Top_Texture =
 texture{ pigment{ color  rgb<1,1,1>*1.2}
          finish { phong 0.6}
        } // end of texture
 #declare Car_Seat_Texture =
 texture{ pigment{ color rgb<1,0.90,0.85>*1.3}
        } // end of texture
 #declare Car_Inside_Texture=
 texture{ Car_Seat_Texture }
 #declare Bumper_Metal_Texture =
 texture{ Car_Body_Texture }
#break //---------------------------------
#case (2)
 #declare Car_Body_Texture =
 texture{ pigment{ color rgb<0.9,0.7,1>*1.2}
  finish{ phong 1 reflection{.35,metallic .5}}
        } // end of texture
 #declare Car_Top_Texture =

  // ... snip!

 #declare Bumper_Metal_Texture =
 texture{ Car_Body_Texture }
#break //---------------------------------
#else // all other numbers
 #declare Car_Body_Texture =
 texture{ pigment{ color rgb<1,1,1>*1.2}
  finish{ phong 1 reflection{.35,metallic .5}}
        } // end of texture
 #declare Car_Top_Texture =

  // ... snip!

 #declare Bumper_Metal_Texture =
 texture{ Polished_Chrome }
 #break //---------------------------------
#end // end of switch
#end // end of macro -------------------------
//--------------------------------------------
// Aufrufe
Car_Body_Texture_Set(0)
#include "Car_01.inc"
object{ Car_01(-10, //Front_Wheel_Angle,
                0,//Coupe_ON:0=hardtop;1=coupé
                Car_Body_Texture, //
                Car_Top_Texture, //
                Car_Seat_Texture, //
                Car_Inside_Texture, //
                Wheel_Rubber_Texture, //
                Wheel_Metal_Texture, //
                Bumper_Metal_Texture, //
                Chassis_Inside_Texture //
              ) //----------------------
        rotate<0, 90,0>
        translate<-4.3,0,3>}
//--------------------------------------------
Car_Body_Texture_Set(1)
#include "Car_01.inc"
object{ Car_01(-10, //Front_Wheel_Angle,
                1,//Coupe_ON:0=hardtop;1=coupé
                Car_Body_Texture, //
 // ... snip!
              ) //----------------------
        rotate<0,70,0>
        translate<0,0,3>}
//--------------------------------------------
Car_Body_Texture_Set(2)
#include "Car_01.inc"
object{ Car_01(-10, //Front_Wheel_Angle,
                1,//Coupe_ON:0=hardtop;1=coupé
                Car_Body_Texture, //
 // ... snip!
              ) //-------------------------
        rotate<0,65,0>
        translate<4,0,3>}
//----------------------------------------
#if ... #else ... #end

top

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