POV-Ray : Newsgroups : povray.text.scene-files : packed variables : packed variables Server Time
7 Jul 2022 02:37:19 EDT (-0400)
  packed variables  
From: jr
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)

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