-
Notifications
You must be signed in to change notification settings - Fork 0
/
Common.cpp
44 lines (40 loc) · 1.05 KB
/
Common.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "Common.h"
#include <functional>
#include "Vector3.h"
#include "Texture.h"
#include <vector>
#include <memory>
#include "Material.h"
int search(const std::vector<double> &t,double o){
int st=0,en=t.size()-1,mid=0;
for(;st<en;){
mid=(st+en)>>1;
if(fabs(t[mid]-o)<DBL_EPSILON)
return mid;
if(t[mid]>o)
en=mid;
else
st=mid+1;
}
return en;
}
DynamicVector3Type operator*(DynamicVector3Type func1,DynamicVector3Type func2){
return [func1,func2](const Vector3 &orig,double time){
Vector3 temp=func1(orig,time);
return func2(temp,time);
};
}
DynamicVector3Type zeroAnimation=[](const Vector3 &_orig,double _time){return Vector3(_orig);};
DynamicVector3Type timeInterpolate(const std::vector<Vector3> &v,const std::vector<double> &t){
return [v,t](const Vector3 &_orig,double _time){
if(_time<t[0])
return Vector3(_orig);
if(_time>t[t.size()])
return Vector3(v[v.size()]);
int i=search(t,_time);
if(fabs(t[i]-_time)<DBL_EPSILON)
return Vector3(v[i]);
double c=(t[i]-_time)/(t[i]-t[i-1]);
return v[i-1]*c+v[i]*(1-c);
};
}