POV-Ray : Newsgroups : povray.advanced-users : structures with povray : structures with povray Server Time
25 Apr 2024 10:43:26 EDT (-0400)
  structures with povray  
From:
Date: 8 Nov 2001 06:34:29
Message: <6lpkut0vdh0h6gljr7u2v4mip6olddkmel@4ax.com>
(NOTE: I work on POV 3.5, I'm not sure how it works with previous versions)

I found a simple way to store structures in POVRay. Perhaps it isn't new thing
but I never meet this. Simple structure for example looks like (notation differs
from language to language):

var Workers:array[100] of structure
  Name:String;
  Age: Integer;
  Representation: Object3D;
end.

so now it is simple to write Workers[33].Name="Smith". All workers, one worker
and field of worker is simply to refer.

But there is no such element within POVRAY. I want present simple way to achive
this with POVRAY. Main key is to use array of arrays (not miltidimensional
array). This example should be selfexplaining.

#declare NAME=0;
#declare AGE=1;
#declare SHOW=2;
#declare NUMBER_OF_FIELDS=3;
#declare NUMBER_OF_WORKERS=100;

#macro Init_Structure(Fields,Size)
  #local Struct=array[Fields];
  #local C=0;
  #while(C<Fields)
    #local Struct[C]=array[Size];
    #local C=C+1;
  #end
  Struct
#end

#declare STRUCT=Init_Structure(NUMBER_OF_FIELDS,NUMBER_OF_WORKERS);
#declare SmithID=0;
#declare STRUCT[NAME][SmithID]="Smith";
#declare STRUCT[AGE][SmithID]=33;
#declare STRUCT[SHOW][SmithID]=sphere{0,1 pigment{rgb 1}};

As you see only difference beetwen POV and other languages is field selector
passed before id not after. And now whole structures can be passed to macros.
Only limitation I found is checking for defined values. It not work when you
just write #ifdef(STRUCT[WORKER3D][SmithID]). Instead of this you have to write

#ifdef(STRUCT[NAME])
  #local Temp=STRUCT[NAME];
  #ifdef(Temp[SmithID])
    // content parsed when field defined
  #end
#end

Of course there is more ways to store structures but I found this simplest and
flexible to use. What's more when one field of this structure is array of
structures builded the same way then it is simple way to achive tree with
POV-Ray. Currently I use it to create some system.

ABX
--
#declare _=function(a,b,x){((a^2)+(b^2))^.5-x}#default {pigment{color rgb 1}}
union{plane{y,-3}plane{-x,-3}finish{reflection 1 ambient 0}}isosurface{ //ABX
function{_(x-2,y,1)|_((x+y)*.7,z,.1)|_((x+y+2)*.7,z,.1)|_(x/2+y*.8+1.5,z,.1)}
contained_by{box{<0,-3,-.1>,<3,0,.1>}}translate z*15finish{ambient 1}}//POV35


Post a reply to this message

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