# 【自定义曲线】
使用贝塞尔曲线转成任意想要的曲线,并且生成OpenGL代码用于使用。
用于实验效果使用,正式输出还是需要直接使用公式,会更加顺滑,性能更好。
拷贝到剪贴板的的OpenGL代码例子:
// opengl es 3.0 version
float getCCY(float x)
{
float[30] ss = float[30](0.02033,0.02366,0.07578,0.11677,0.23732,0.34333,0.12819,0.06174,0.04054,0.03412,0.03344,0.03474,0.03654,0.03837,0.04006,0.04156,0.04292,0.04412,0.04518,0.04614,0.047,0.04777,0.04847,0.04912,0.0497,0.05024,0.05073,0.0512,0.05161,0.06667);
float[31] y = float[31](1.0,1.0,0.98023,0.91218,0.80027,0.5653,0.22359,0.09981,0.04784,0.02477,0.01749,0.02026,0.03004,0.04502,0.06402,0.08623,0.11106,0.1381,0.16699,0.19749,0.2294,0.26253,0.29675,0.33194,0.36801,0.40488,0.44247,0.48071,0.51957,0.55898,0.55898);
int c = 30;float val = 1.99736 * x;float t = 0.0;float s = 0.0;
for (int i = 0; i < c; i++) {float e = s + ss[i];t = (val - s) / (e - s);if (t >= 0.0 && t <= 1.0) {return (1.0 - t) * y[i] + t * y[i + 1];}s = e;}
return y[c];
}
// opengl es 2.0 version
float getCCY(float x)
{
float v = 1.99736 * x;
float t0 = v / 0.02033;
if(t0 >= 0.0 && t0 <= 1.0){return (1.0 - t0) * 1.0 + t0 * 1.0;}
float t1 = (v - 0.02033) / (0.04399 - 0.02033);
if(t1 >= 0.0 && t1 <= 1.0){return (1.0 - t1) * 1.0 + t1 * 0.98023;}
float t2 = (v - 0.04399) / (0.11977 - 0.04399);
if(t2 >= 0.0 && t2 <= 1.0){return (1.0 - t2) * 0.98023 + t2 * 0.91218;}
float t3 = (v - 0.11977) / (0.23654 - 0.11977);
if(t3 >= 0.0 && t3 <= 1.0){return (1.0 - t3) * 0.91218 + t3 * 0.80027;}
float t4 = (v - 0.23654) / (0.47386 - 0.23654);
if(t4 >= 0.0 && t4 <= 1.0){return (1.0 - t4) * 0.80027 + t4 * 0.5653;}
float t5 = (v - 0.47386) / (0.81719 - 0.47386);
if(t5 >= 0.0 && t5 <= 1.0){return (1.0 - t5) * 0.5653 + t5 * 0.22359;}
float t6 = (v - 0.81719) / (0.94538 - 0.81719);
if(t6 >= 0.0 && t6 <= 1.0){return (1.0 - t6) * 0.22359 + t6 * 0.09981;}
float t7 = (v - 0.94538) / (1.00712 - 0.94538);
if(t7 >= 0.0 && t7 <= 1.0){return (1.0 - t7) * 0.09981 + t7 * 0.04784;}
float t8 = (v - 1.00712) / (1.04766 - 1.00712);
if(t8 >= 0.0 && t8 <= 1.0){return (1.0 - t8) * 0.04784 + t8 * 0.02477;}
float t9 = (v - 1.04766) / (1.08178 - 1.04766);
if(t9 >= 0.0 && t9 <= 1.0){return (1.0 - t9) * 0.02477 + t9 * 0.01749;}
float t10 = (v - 1.08178) / (1.11522 - 1.08178);
if(t10 >= 0.0 && t10 <= 1.0){return (1.0 - t10) * 0.01749 + t10 * 0.02026;}
float t11 = (v - 1.11522) / (1.14996 - 1.11522);
if(t11 >= 0.0 && t11 <= 1.0){return (1.0 - t11) * 0.02026 + t11 * 0.03004;}
float t12 = (v - 1.14996) / (1.18650 - 1.14996);
if(t12 >= 0.0 && t12 <= 1.0){return (1.0 - t12) * 0.03004 + t12 * 0.04502;}
float t13 = (v - 1.18650) / (1.22487 - 1.18650);
if(t13 >= 0.0 && t13 <= 1.0){return (1.0 - t13) * 0.04502 + t13 * 0.06402;}
float t14 = (v - 1.22487) / (1.26493 - 1.22487);
if(t14 >= 0.0 && t14 <= 1.0){return (1.0 - t14) * 0.06402 + t14 * 0.08623;}
float t15 = (v - 1.26493) / (1.30649 - 1.26493);
if(t15 >= 0.0 && t15 <= 1.0){return (1.0 - t15) * 0.08623 + t15 * 0.11106;}
float t16 = (v - 1.30649) / (1.34941 - 1.30649);
if(t16 >= 0.0 && t16 <= 1.0){return (1.0 - t16) * 0.11106 + t16 * 0.1381;}
float t17 = (v - 1.34941) / (1.39353 - 1.34941);
if(t17 >= 0.0 && t17 <= 1.0){return (1.0 - t17) * 0.1381 + t17 * 0.16699;}
float t18 = (v - 1.39353) / (1.43871 - 1.39353);
if(t18 >= 0.0 && t18 <= 1.0){return (1.0 - t18) * 0.16699 + t18 * 0.19749;}
float t19 = (v - 1.43871) / (1.48485 - 1.43871);
if(t19 >= 0.0 && t19 <= 1.0){return (1.0 - t19) * 0.19749 + t19 * 0.2294;}
float t20 = (v - 1.48485) / (1.53185 - 1.48485);
if(t20 >= 0.0 && t20 <= 1.0){return (1.0 - t20) * 0.2294 + t20 * 0.26253;}
float t21 = (v - 1.53185) / (1.57962 - 1.53185);
if(t21 >= 0.0 && t21 <= 1.0){return (1.0 - t21) * 0.26253 + t21 * 0.29675;}
float t22 = (v - 1.57962) / (1.62809 - 1.57962);
if(t22 >= 0.0 && t22 <= 1.0){return (1.0 - t22) * 0.29675 + t22 * 0.33194;}
float t23 = (v - 1.62809) / (1.67721 - 1.62809);
if(t23 >= 0.0 && t23 <= 1.0){return (1.0 - t23) * 0.33194 + t23 * 0.36801;}
float t24 = (v - 1.67721) / (1.72691 - 1.67721);
if(t24 >= 0.0 && t24 <= 1.0){return (1.0 - t24) * 0.36801 + t24 * 0.40488;}
float t25 = (v - 1.72691) / (1.77715 - 1.72691);
if(t25 >= 0.0 && t25 <= 1.0){return (1.0 - t25) * 0.40488 + t25 * 0.44247;}
float t26 = (v - 1.77715) / (1.82788 - 1.77715);
if(t26 >= 0.0 && t26 <= 1.0){return (1.0 - t26) * 0.44247 + t26 * 0.48071;}
float t27 = (v - 1.82788) / (1.87908 - 1.82788);
if(t27 >= 0.0 && t27 <= 1.0){return (1.0 - t27) * 0.48071 + t27 * 0.51957;}
float t28 = (v - 1.87908) / (1.93069 - 1.87908);
if(t28 >= 0.0 && t28 <= 1.0){return (1.0 - t28) * 0.51957 + t28 * 0.55898;}
float t29 = (v - 1.93069) / (1.99736 - 1.93069);
if(t29 >= 0.0 && t29 <= 1.0){return (1.0 - t29) * 0.55898 + t29 * 0.55898;}
return 0.55898;
}
← 【程序化动画の震动】 【常用曲线参考】 →