62
Chapter 4: Scene Graph Nodes
Using Tokens to Set and Get Single-Value Fields
To use tokens to set or get single-value fields, you
1. Get a handle to the field specified by the token.
2. Use the handle to set or get the field.
For example:
F = mtl->getField(SHININESS);
F->set(ShininessValue);
ShininessValue = F->get();
F->get(c);
ShininessValue is a float. The first line of code returns a handle, F, to the shininess field.
The second line then sets the value of that field.
The third line returns an atomic, single value. Since there is only one value, it does not
need to be specified in the argument. The last line returns a composite, single value, F.
Using set() and get() Methods to Set and Get Multiple-Value Fields
Multiple-value fields are arrays of variables. For example, the csMaterial field has a
number of values, including
sfFloat Shininess;
sfVec DiffuseColor;
To get or set a value in a csMaterial field, you must specify which of the values in the
field you are retrieving or setting, for example:
csGroup *g;
g->addChild(child);
child = g->getChild(1);
Child nodes of a group node are numbered, starting with zero. To retrieve the specific
child in the csGroup, you must specify in the argument of getChild() which child you
want returned; in this example, it is child number one.