POV-Ray : Newsgroups : povray.text.scene-files : packed variables Server Time
31 Oct 2024 20:38:11 EDT (-0400)
  packed variables (Message 1 to 3 of 3)  
From: jr
Subject: packed variables
Date: 27 Mar 2022 19:20:00
Message: <web.6240f04ba0fd3d85fc0c8de6cde94f1@news.povray.org>
hi,

the aim of 'pvars.inc' is to provide a way to reduce the number of global
variables used in one's POV-Ray scenes, and to have to hand a convenient "type"
much like a small 'array mixed', for related variables.

the "idea" came about from a (not infrequent) need to keep two index and one
boolean variable, for each of many objects.  also perhaps influenced by BC's
"PROOF" threads, that is thinking about "abstractions" and such, and about one's
"footprint" in the global namespace.

a "packed variable" is simply a 4-vector where the four components can be
treated as individual variables/elements, addressed via a zero-based index.

the include file contains a small number of macros which make up the
"interface".  visible (global) identifiers in the file are prefixed 'pv'.
POV-Ray's vector operands and functions will work as expected.

the "documentation" consists of a brief description of the macros in the include
file's header, and example usage in the scene code I will post in p.b.a. "Ulam
Spiral Fun" next.

as an example, say I want to animate a number of objects/shapes, and in each
frame need to calculate the new point where each object will be.  my packed
variable might then be '<x,y,z,i>', where 'i' is an index for the 'shapes'
array.  and to update the point, likely, I'd use a small macro, something like:

  #macro calcPoint(pv_,clock_)
    #local (x_,y_,z_,i_) = pvUnpack(pv_);
    /* calc new x,y,z.
     * can, of course, still use 'pv_.x' etc directly.
     */
    #local pv_ = pvPack(x_,y_,z_,i_);
  #end

and then pass the variable to some other macro to place the object, etc.

as always, comments, feedback, criticisms, all (equally) welcome.


enjoy, jr.


Post a reply to this message


Attachments:
Download 'pvars.inc.txt' (5 KB)

From: Thomas de Groot
Subject: Re: packed variables
Date: 29 Mar 2022 02:45:21
Message: <6242ab01$1@news.povray.org>
Op 28/03/2022 om 01:16 schreef jr:
> hi,
> 
> the aim of 'pvars.inc' is to provide a way to reduce the number of global
> variables used in one's POV-Ray scenes, and to have to hand a convenient "type"
> much like a small 'array mixed', for related variables.
> 

Interesting stuff. I need to study this carefully as it could help me to 
plant trees (or other objects) in a more streamlined way than what I do now.

-- 
Thomas


Post a reply to this message

From: jr
Subject: Re: packed variables
Date: 29 Mar 2022 09:45:00
Message: <web.62430c4a46a69439fc0c8de6cde94f1@news.povray.org>
hi,

Thomas de Groot <tho### [at] degrootorg> wrote:
> Op 28/03/2022 om 01:16 schreef jr:
> > the aim of 'pvars.inc' is ...
>
> Interesting stuff. I need to study this carefully as it could help me to
> plant trees (or other objects) in a more streamlined way than what I do now.

thanks v much for looking it over, hope the code will simply .. slot in.

attached is version 2.  there was one typo (boolean misspelled) and the wrong
file name in the '#debug' (an oversight when renaming from "working title");
also took the opportunity to reformat 'pvClear()'.


regards, jr.


Post a reply to this message


Attachments:
Download 'pvars.inc.txt' (5 KB)

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