A SERVICE OF

logo

62
Chapter 4: Scene Graph Nodes
Using Tokens to Set and Get Single-Value Fields
To use tokens to set or get single-value elds, you
1. Get a handle to the eld specied by the token.
2. Use the handle to set or get the eld.
For example:
F = mtl->getField(SHININESS);
F->set(ShininessValue);
ShininessValue = F->get();
F->get(c);
ShininessValue is a oat. The rst line of code returns a handle, F, to the shininess eld.
The second line then sets the value of that eld.
The third line returns an atomic, single value. Since there is only one value, it does not
need to be specied 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 elds are arrays of variables. For example, the csMaterial eld has a
number of values, including
sfFloat Shininess;
sfVec DiffuseColor;
To get or set a value in a csMaterial eld, you must specify which of the values in the
eld 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 specic
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.