1
0

SPLINE.C 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /******************************************************************************
  2. Plush Version 1.2
  3. spline.c
  4. n-th Dimensional Spline Interpolator
  5. Copyright (c) 1996-2000, Justin Frankel
  6. ******************************************************************************/
  7. #include "plush.h"
  8. void plSplineGetPoint(pl_Spline *s, pl_Float frame, pl_Float *out) {
  9. pl_sInt32 i, i_1, i0, i1, i2;
  10. pl_Float time1,time2,time3;
  11. pl_Float t1,t2,t3,t4,u1,u2,u3,u4,v1,v2,v3;
  12. pl_Float a,b,c,d;
  13. pl_Float *keys = s->keys;
  14. a = (1-s->tens)*(1+s->cont)*(1+s->bias);
  15. b = (1-s->tens)*(1-s->cont)*(1-s->bias);
  16. c = (1-s->tens)*(1-s->cont)*(1+s->bias);
  17. d = (1-s->tens)*(1+s->cont)*(1-s->bias);
  18. v1 = t1 = -a / 2.0; u1 = a;
  19. u2 = (-6-2*a+2*b+c)/2.0; v2 = (a-b)/2.0; t2 = (4+a-b-c) / 2.0;
  20. t3 = (-4+b+c-d) / 2.0;
  21. u3 = (6-2*b-c+d)/2.0;
  22. v3 = b/2.0;
  23. t4 = d/2.0; u4 = -t4;
  24. i0 = (pl_uInt) frame;
  25. i_1 = i0 - 1;
  26. while (i_1 < 0) i_1 += s->numKeys;
  27. i1 = i0 + 1;
  28. while (i1 >= s->numKeys) i1 -= s->numKeys;
  29. i2 = i0 + 2;
  30. while (i2 >= s->numKeys) i2 -= s->numKeys;
  31. time1 = frame - (pl_Float) ((pl_uInt) frame);
  32. time2 = time1*time1;
  33. time3 = time2*time1;
  34. i0 *= s->keyWidth;
  35. i1 *= s->keyWidth;
  36. i2 *= s->keyWidth;
  37. i_1 *= s->keyWidth;
  38. for (i = 0; i < s->keyWidth; i ++) {
  39. a = t1*keys[i+i_1]+t2*keys[i+i0]+t3*keys[i+i1]+t4*keys[i+i2];
  40. b = u1*keys[i+i_1]+u2*keys[i+i0]+u3*keys[i+i1]+u4*keys[i+i2];
  41. c = v1*keys[i+i_1]+v2*keys[i+i0]+v3*keys[i+i1];
  42. *out++ = a*time3 + b*time2 + c*time1 + keys[i+i0];
  43. }
  44. }