Game Development Reference
In-Depth Information
follow are copied on the end. The final alternative for adding keyframes is
to insert the key at the end of the current array. Here again memory is
allocated for all the existing keyframes plus one extra. All the existing
keyframes are copied to the new array and the new data are inserted on
the end.
Suppose there are existing keyframes at frames 0, 20, 52, 64 and 78.
If the function is called with frame value 20, then the existing keyframe
that has a frame value of 20 is adjusted. If the function is called with the
value 34 then it must be inserted between the keyframes at 0 and 20 and
the keyframes at 52, 64 and 78. First, we allocate an array of six
MORPHKEY values. The first two MORPHKEYS in the existing array are
copied to the new array. Then the new data are assigned to MORPH-
KEY[2]. Finally, the remaining MORPHKEYS are copied into the new
array. The new array has keyframes at 0, 20, 34, 52, 64 and 78.
If the function is called with a frame value of 89, then the new keyframe
must be added to the end of the array. Again, an array of six
MORPHKEYS is created. This time, all the existing array is copied across
and the new data are assigned to the last member of the array. The new
array has keyframes at 0, 20, 52, 64, 78 and 89. The code for this function
is as follows:
MORPHKEY *CMorph::CreateKey(int frame)
{
if (keytotal==0){
keys = new MORPHKEY;
if (!keys){
TRACE(”CMorph::CreateKey>>Problem creating key zero\n”);
return NULL;
}
keytotal = 1;
for (int i=0; i<objcount; i++) keys->level[i] = 0.0;
//There must be a key at frame zero
keys->time = 0.0f;
keys->linear = 0;
keys->tn = 0.0;
keys->bs = 0.0;
keys->ct = 0.0;
}
//Does the object have a key for this frame?
MORPHKEY *key = keys,*ikey = NULL;
int i;
Search Nedrilad ::




Custom Search