Engines That Change Shapes
119
Example 10-1 Building a Morph Engine: the Worm
// Build morph engine
MorphCoords = new csMorphEng3f;
// “Neutral” is non-indexed and always has weight of 1
MorphCoords->input()->setRange(0, NumRings*RingVerts, coords);
MorphCoords->count()->set(0, NumRings*RingVerts);
MorphCoords->weight()->set(0, 1.0f);
// build the coordinate vectors for the rings on the worm
for (k=0,i=0; i<NumRings; i++)
{
for (j=0; j<RingVerts; j++,k++)
{
csVec3f v(coords[k]);
v.scale(.5f, v);
// Set displacement vectors for “target” i
MorphCoords->input()->set(k+NumRings*RingVerts, v);
MorphCoords->index()->set(k, k);
}
// targets are indexed
MorphCoords->counts()->set(i+1, -RingVerts);
}
MorphCoords->connectOutput(csMorphVec3f::OUTPUT,
SkelCoords, csTransformEng3F::INPUT);
This engine moves the rings in the worm.
csTransformEng
csTransformEng is a csEngine that translates attribute sets consisting of points or
vectors. The csTransformEng output is a single array which may be used as a csGeoSet
attribute list, for example, csCoordSet3f, csNormalSet3f.
Any number of variably-sized attribute sets can be packed into the input field.
csTransformEng is an abstract class. Subclasses in Cosmo 3D include csTransformEng3f.
csTransformEng3f input and output values are csMFVec3fs.