28
Chapter 2: Creating Geometries
Indexing Attributes
An indexed csGeoSet object uses a list of unsigned short integers to index an attribute
array. Four set...() methods in csGeoSet specify these indices:
void setCoordIndices(csIndexSet* coordIndices);
void setNormalIndices(csIndexSet* normalIndices);
void setColorIndices(csIndexSet* colorIndices);
void setTexCoordIndices(csIndexSet* texCoordIndices);
There is a corresponding set of get...() methods that retrieve the index settings for the
coordinates, normals, colors, and texture coordinates, respectively.
coordIndices is an array of coordinate indices. Each index points to a member in the
coordinate attribute array, as shown in Figure 2-3.
normalIndices is an array of normal indices. colorIndices is an array of color indices.
texCoordIndices is an array of texture coordinate indices.
Setting Attributes Example
Example 2-1 shows how to set attributes and their bindings.
Example 2-1 Setting Attributes
// Create a csGeoSet object
csTriStripSet *gset = new csTriStripSet;
// Allocate the attribute arrays
csCoordSet3f *vset = new csCoordSet3f(NumRings*RingVerts);
csNormalSet3f *nset = new csNormalSet3f(NumRings*RingVerts);
csIndexSet *iset = new csIndexSet((NumRings-1) *
2 * (RingVerts + 1));
csColorSet4f *cset = new csColorSet4f(NumRings-1);
csIndexSet *lengths = new csIndexSet(NumRings-1);
// Set the attributes
gset->setCoords(vset);
gset->setNormals(nset);
gset->setColors(cset);
// Set the attribute indices
gset->setCoordIndices(iset);
gset->setNormalIndices(iset);
gset->setPrimCount(NumRings-1);