00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "cLerpInterval.h"
00016 #include "string_utils.h"
00017
00018 TypeHandle CLerpInterval::_type_handle;
00019
00020
00021
00022
00023
00024
00025
00026
00027 CLerpInterval::BlendType CLerpInterval::
00028 string_blend_type(const string &blend_type) {
00029 if (blend_type == "easeIn") {
00030 return BT_ease_in;
00031 } else if (blend_type == "easeOut") {
00032 return BT_ease_out;
00033 } else if (blend_type == "easeInOut") {
00034 return BT_ease_in_out;
00035 } else if (blend_type == "noBlend") {
00036 return BT_no_blend;
00037 } else {
00038 return BT_invalid;
00039 }
00040 }
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 double CLerpInterval::
00051 compute_delta(double t) const {
00052 double duration = get_duration();
00053 if (duration == 0.0) {
00054
00055
00056 return 1.0;
00057 }
00058 t /= duration;
00059 t = min(max(t, 0.0), 1.0);
00060
00061 switch (_blend_type) {
00062 case BT_ease_in:
00063 {
00064 double t2 = t * t;
00065 return ((3.0 * t2) - (t2 * t)) * 0.5;
00066 }
00067
00068 case BT_ease_out:
00069 {
00070 double t2 = t * t;
00071 return ((3.0 * t) - (t2 * t)) * 0.5;
00072 }
00073
00074 case BT_ease_in_out:
00075 {
00076 double t2 = t * t;
00077 return (3.0 * t2) - (2.0 * t * t2);
00078 }
00079
00080 default:
00081 return t;
00082 }
00083 }