Proper quat12 handing
[dormin.git] / reeng / animations.txt
blob89dd05bf261ee15e41d88aa2f9d84d45b0b3c574
1 What defines an animation in SOTC
2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 File with animation contains:
5 16 bit count - number of poses? (M)
6 32 bit count - number of bones  (N)
8 There's an array of per bone flags, each flag is 8 bit and can take
9 following values: 0,3,4,5,6,12,13 (at least only those has been
10 observed in .anb files)
12 Every bone has associated data whose length/interpretation depends on
13 the value of the flag.
15 ----------------------------------------------------------------------
16 When flag is 0:
17  Data contains: 4 floating point numbers (unit quaternion).
19 ----------------------------------------------------------------------
20 When flag is 3,4,5,6:
21  Data contains: 8 floating point numbers and an array of M 32 bit
22  values.
24  Floating points are 4 pairs actually, for first 3 pairs following
25  holds:
26    first pair member is in [-1, 1]
27    second                  [ 0, 1)
29  For last(4th) pair:
30    first pair member is in [-0.018651, 0.016117]
31    second                  [ 0.000000, 0.044226]
33  Depending on the flag the value from 32bit array[M] is broken down
34  like this:
35                               I    J    K    S (signed N bit vars)
36    flag 3                  5bit 9bit 9bit 9bit
37         4                  9bit 5bit 9bit 9bit
38         5                  9bit 9bit 5bit 9bit
39         6                  9bit 9bit 9bit 5bit
41  From these one can obtain quaternion like this:
42    float i, j, k, s;
43    switch (flag) {
44    case 3:
45      j = madd(J / 256.0, pairs[0].first, pairs[0].second);
46      k = madd(K / 256.0, pairs[1].first, pairs[1].second);
47      s = madd(S / 256.0, pairs[2].first, pairs[2].second);
48      i = sqrt(1 - magnitude(j, k, s));
49      if (I & 16) i = -i;
50      break;
51    case 4:
52      i = madd(I / 256.0, pairs[0].first, pairs[0].second);
53      k = madd(K / 256.0, pairs[1].first, pairs[1].second);
54      s = madd(S / 256.0, pairs[2].first, pairs[2].second);
55      j = sqrt(1 - magnitude(i, k, s));
56      if (J & 16) j = -j;
57      break;
58    ... and so on
59    }
61    quat q = (i, j, k, s);
63  (It's evident that last 4 bits of 5bit value are unaccounted for,
64   likewise the third pair)
66 ----------------------------------------------------------------------
67 When flag is 12:
68  Data contains: 6 floating point numbers and an array of M 48 bit
69  values.
71  Floating pints form 3 pairs, constraint:
72   first pair member (-1, 1)
73   second            [ 0, 1)
75  Each 48 bit value is a tuple of 3 signed 16 bit fields (I,J,K),
76  quaternion is obtained like this:
78  i = madd (I / 32768.0, pairs[0].first, pairs[0].second);
79  j = madd (J / 32768.0, pairs[1].first, pairs[1].second);
80  k = madd (K / 32768.0, pairs[2].first, pairs[2].second);
81  s = sqrt (1 - magnitude (i, j, k));
82  if (i & 1) s = -s;
83  quat q = (i, j, k, s) 
85 ----------------------------------------------------------------------
86 When flag is 13:
87  Data contains: 5 floating point numbers and an array of M signed 16
88  bit values.
90  Floats:
91   [0]    - [0.024525, 6.266401]
92   [1]    - [0.003143, 1.655432]
93   [2..4] - axis
95  From these one can obtain quaternion like this:
96   float radians = madd(16bitint / 32767.0, float[1], float[0])
97   quat q = from_axis_angle(axis, radians);