00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "lib3ds_impl.h"
00019
00020
00021 float
00022 lib3ds_math_ease(float fp, float fc, float fn, float ease_from, float ease_to) {
00023 double s, step;
00024 double tofrom;
00025 double a;
00026
00027 s = step = (float)(fc - fp) / (fn - fp);
00028 tofrom = ease_to + ease_from;
00029 if (tofrom != 0.0) {
00030 if (tofrom > 1.0) {
00031 ease_to = (float)(ease_to / tofrom);
00032 ease_from = (float)(ease_from / tofrom);
00033 }
00034 a = 1.0 / (2.0 - (ease_to + ease_from));
00035
00036 if (step < ease_from) s = a / ease_from * step * step;
00037 else {
00038 if ((1.0 - ease_to) <= step) {
00039 step = 1.0 - step;
00040 s = 1.0 - a / ease_to * step * step;
00041 } else {
00042 s = ((2.0 * step) - ease_from) * a;
00043 }
00044 }
00045 }
00046 return((float)s);
00047 }
00048
00049
00050 void
00051 lib3ds_math_cubic_interp(float *v, float *a, float *p, float *q, float *b, int n, float t) {
00052 float x, y, z, w;
00053 int i;
00054
00055 x = 2 * t * t * t - 3 * t * t + 1;
00056 y = -2 * t * t * t + 3 * t * t;
00057 z = t * t * t - 2 * t * t + t;
00058 w = t * t * t - t * t;
00059 for (i = 0; i < n; ++i) {
00060 v[i] = x * a[i] + y * b[i] + z * p[i] + w * q[i];
00061 }
00062 }