|
Prisms Development Toolkit Documentation
Side Effects Software Inc. 1997
|
Custom SOPs
Adding Local Variables
Local variables are variables which are local to the SOP, but which the
animator can access and use. The most frequently seen example is $PT
in the Point SOP, but there are many others.
Usually, this is a value which is meaningful within the SOP, but which
a user may want to base his SOP parameters on. In the following example,
the local variable $COOK is defined and used. This variable contains the
number of times the SOP has been cooked since the last reset.
Source Listing
#include <custom.h> /* you must have this! */
static char *sopHelp[] =
{
" This SOP has a bunch of gadgets in it and will print their",
"status when cooked. It takes one input source, which it scales",
"by half and copies to its output.",
" ",
"Local Variables:",
" COOK - The number of times the SOP has been cooked",
0
};
.
. ommitted SOP code
.
/*
* Define the amount of space used by the sop data and name the fields
*/
typedef struct sop_data
{
SOP_EXPR Single;
SOP_EXPR Double[2];
SOP_EXPR Triple[3];
/*
* You can stick any private data you want after the declaration
* of the SOP_EXPR fields. Here, we keep track of the number of
* times the SOP has been cooked (for the $COOK local variable)
*/
int cookCount;
} SOP_DATA;
/*
* Declaring local variables:
* The names of the structures below are important.
* localVars is the actual structure used to store the data
* localSyms contains the identifier for the local variable.
*
* For convenience, we declare a macro for the one variable (COOKVAR)
* The Variable keeps track of the number of times the SOP has
* been cooked since it was initialized.
* It is initialized in sopDefaults, and incremented in sopCook.
*
* In sopCook EVALUATELV is used instead of EVALUATE in order that the
* variable's value be taken into account.
*/
#define COOKVAR localVars[0]
#define NVARS 1
static LOCALVARDATA localVars[NVARS];
static LOCALSYMBOL localSyms[] =
{
{ "COOK", 0 },
/* if more variables, they go here. Finish with 0 (NULL) entry */
0
};
/*
* This function is used when creating a new sop. It sets up the
* initial values of the sop.
*/
static void
sopDefaults(SOP *sop) /* Put in default values */
{
SOP_DATA *sb;
COOKVAR.fval = 0; /* initialize local var */
if (sop->special) free(sop->special);
sb = (SOP_DATA *)Calloc(sizeof(SOP_DATA), "Sample sopDefaults");
sop->special = (char *)sb;
InitSopExpr(&sb->Single, "$COOK");
/*
* Now we initialize any "private" data
*/
sb->cookCount = 0;
}
static void
sopCook(SOP *sop)
{
SOP_DATA *sb;
OBJECT *obp;
char *expanded;
int idx;
PolyDetail *sourcePdp;
PolyPointPointer tmppt;
int npts;
sb = (SOP_DATA *)sop->special;
sb->cookCount++; /* update local variable */
COOKVAR.fval = sb->cookCount; /* assign to user variable */
if (sop->pdp) FreePolyDetail(sop->pdp);
sop->pdp = 0;
/*
* calling EVALUATE scans the expression, evaluates variables, etc
* and puts the resulting value in the Expression's .value.fval
* field.
* EVALUATELV should be called if the sop has local variables.
* Since we have one defined, we use EVALUATELV in this example.
*/
EVALUATELV(sop, sb->Single);
printf("Single : %g\n", sb->Single.value.fval);
}
For More Detailed Information:
The sopDefault routine
Tookit Overview
Expression Functions |
User Functions |
Custom SOPs
Prisms Internal Format |
Programmer's Reference
Compiling SOPs |
Using sopbuild |
SOP Routine Reference
Dynamic SOPs |
Prisms Types |
Macros
Math Routines |
Data Routines |
Polygon Routines |
Winged-edge Routines
Copyright © 1997 Side Effects Software Inc.
477 Richmond Street West, Toronto, Ontario, Canada M5V 3E7