Game Development Reference
In-Depth Information
a 2-byte integer, this gives a range of ±32 767. The aim is to create a scale
value for a channel; using this scale value we will adjust each key value
so that instead of using floating-point values we can use integers. The
scale factor is found using the absolute maximum of the two values we
have temporarily stored. For example, if the minimum value for a channel
is -123.8 and the maximum value is 32.98, then the absolute maximum is
123.6. We need to scale 123.6 up to 32 767. This is done by taking
32 767/123.6 = 265.105
If the maximum and minimum were 124 932 and -234 578 respectively,
then the absolute maximum is 234 578 and the scale factor would be
32 767/234 578 = 0.14
We save the channel scales as floats at the start of the file. Although
saving channel scale values takes 36 bytes, each key value uses 18 bytes
rather than 36. A motion file with just three keyframes is already smaller
than one stored as straight floats.
When restoring the values we divide each integer value by the scale
value for the channel to get the correct world size for that channel as a
floating-point value.
Since the motion channels are stored as TCB curves, we need to save
the tension, continuity and bias. For most applications, restricting these
values to between -127 and +128 will give sufficient accuracy. This is
easily achieved by multiplying the values which range between +1 and -1
by 128.
if (obj->keytotal < 128){
byt = (BYTE)obj->keytotal;
ar.Write(&byt, sizeof(BYTE));
sht = ((obj->keytotal & 0xFF)<<8) | 0x80 | (obj->keytotal>>8);
ar.Write(&byt, sizeof(USHORT));
key = obj->keys;
for (i=0;i<obj->keytotal;i++){
//Write minimum keyframe data
//int frame mapped to USHORT, top level bit sets linear key
//double x, y, z mapped to short
//doubleh, p, b mapped to short
Search Nedrilad ::

Custom Search