POV-Ray : Newsgroups : povray.advanced-users : structures with povray Server Time
25 Nov 2024 23:36:27 EST (-0500)
  structures with povray (Message 1 to 5 of 5)  
From:
Subject: structures with povray
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

From: Rune
Subject: Re: structures with povray
Date: 8 Nov 2001 08:07:31
Message: <3bea8393@news.povray.org>

> I found a simple way to store structures in POVRay.
> Perhaps it isn't new thing but I never meet this.
> Main key is to use array of arrays.

It's not new. I've been using it for some time and I know that Chris Colefax
has been using it for years. However, I too have never met any documents on
it. I've actually been thinking of writing a small tutorial about it, as I
find it to be very practical.

As I don't know other languages than POV-Script, I have no knowledge of
"structures". I've just been thinking of like it's a special kind of arrays
where the rows can have different lengths and contain different data types.

Rune
--
3D images and anims, include files, tutorials and more:
Rune's World:    http://rsj.mobilixnet.dk (updated Nov 5)
POV-Ray Users:   http://rsj.mobilixnet.dk/povrayusers/
POV-Ray Webring: http://webring.povray.co.uk


Post a reply to this message

From: Warp
Subject: Re: structures with povray
Date: 8 Nov 2001 10:55:22
Message: <3beaaaea@news.povray.org>
This would be specially useful if the structure could have a pointer to
a structure of the same type and if instances of these structures could be
created dynamically.
  This way you could make linked lists, binary trees and so on.

-- 
#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: Redbeard
Subject: Re: structures with povray
Date: 8 Nov 2001 11:10:01
Message: <3beaae59$1@news.povray.org>

news:6lpkut0vdh0h6gljr7u2v4mip6olddkmel@4ax.com...
>
> 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):
>
I've been working with something like this with an animation system I've been
working with on and off.  It works quite well.

Michael

--
#macro M(D,J)text{ttf"cyrvetic.ttf"D 1,0translate-J}#end#macro N(E,K)#local A=
M(E,K)light_source{-z*30rgb 1projected_through{A}}#end N("Michael"<1.6,-.2,5>)
N("Johnson"<1.9.8,5>)sphere{z*9,4pigment{gradient x+y scale 10color_map{[0 rgb
x][1rgb x+y]}sine_wave}} // (c)2001 Michael D Johnson red### [at] wvadelphianet


Post a reply to this message

From: s1631001
Subject: Re: structures with povray
Date: 10 Dec 2001 06:51:28
Message: <3C14A14C.F097D1B1@namtar.qub.ac.uk>
Once again, my question is answered before it is even asked. This will
make my life a *lot* easier...

-- 
signature{
  "Grey Knight"
  contact{ email "gre### [at] yahoocom" }
  site_of_week{ url "http://enphilistor.users4.50megs.com/" }
}


Post a reply to this message

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