Game Development Reference
In-Depth Information
this total. Now to calculate the placement of a vertex we sum the products
of target level and current vertex for each target with a level greater than
zero. In the current example, only morphitems 2 ('Sad') and morphitems
3 ('Angry') have a level greater than zero, so the final placement of a
vertex is given by:
pts[i]•x = morphitem[2].pts[i]•x * morphitem[2].level +
morphitem[3].pts[i]•x * morphitem[3].level
pts[i]•y = morphitem[2].pts[i]•y * morphitem[2].level +
morphitem[3].pts[i]•y * morphitem[3].level
pts[i]•z = morphitem[2].pts[i]•z * morphitem[2].level +
morphitem[3].pts[i]•z * morphitem[3].level
The function used to execute the blending is called 'Transform'.
BOOL CMorph::Transform()
{
if (!basepts || !morphitem ) return FALSE;
int i, j, n = 0;
VECTOR *pts = basepts;
double morphlevel[MAX_MORPH_TARGETS], totallevel = 0.0;
for (i=1; i<objcount; i++){
totallevel += morphitem[i].level;
}
if (totallevel>1.0){
//No influence from base object
morphlevel[0] = 0.0;
for (i=1;i<objcount;i++){
morphlevel[i] = morphitem[i].level/totallevel;
}
}else{
//Influence of base object
morphlevel[0] = 1.0-totallevel;
for (i=1; i<objcount; i++){
morphlevel[i] = morphitem[i].level;
}
}
//Amend with objcount morph objects
//basepts is a pointer to the vertices that will be rendered