Setting Attributes
29
// Set the attribute bindings
gset->setNormalBind(csGeoSet::PER_VERTEX_NORMS);
gset->setColorBind(csGeoSet::PER_PRIM_COLORS);
// Prepare to fill the Attribute and Indices arrays
csVec3f *coords = vset->coords()->edit();
csVec3f *norms = nset->normals()->edit();
int *indices = iset->indices()->edit();
Editing Attribute Arrays
Cosmo 3D allows you to modify the values in arrays using the csNormalSet3f::edit() and
csNormalSet3f::editDone() methods. Although you can modify the values, you cannot
change the number of values in the array.
edit() returns a pointer to the attribute array. editDone() notifies any engines or sensors
connected to this field that the array has changed.
It is illegal to call any other editing methods between edit() and editDone().
Example 2-2 shows an example of editing attribute arrays.
Example 2-2 Editing Attribute Arrays
// cube normals
csNormalSet3f *nset = new csNormalSet3f(numCubeNorms);
nset->vector()->edit();
#if 0
for (i=0; i<numCubeNorms; i++)
nset->vector()->set(i,
csVec3f(cubeNorms[i][0], cubeNorms[i][1], cubeNorms[i][2]));
#else
nset->vector()->setRange(0, numCubeNorms, (csVec3f *)cubeNorms);
#endif
nset->vector()->editDone();
gset->setNormalSet(nset);