unity3d 貌似是bezier曲线的一个函数,public Vector3 Interp(Vector3[] pts,float t){int numSections = pts.Length - 3;int currPt = Mathf.Min(Mathf.FloorToInt(t * (float)numSections),numSections - 1);float u = t * (float)numSections - (float)curr
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/16 08:51:32
unity3d 貌似是bezier曲线的一个函数,public Vector3 Interp(Vector3[] pts,float t){int numSections = pts.Length - 3;int currPt = Mathf.Min(Mathf.FloorToInt(t * (float)numSections),numSections - 1);float u = t * (float)numSections - (float)curr
unity3d 貌似是bezier曲线的一个函数,
public Vector3 Interp(Vector3[] pts,float t)
{
int numSections = pts.Length - 3;
int currPt = Mathf.Min(Mathf.FloorToInt(t * (float)numSections),numSections - 1);
float u = t * (float)numSections - (float)currPt;
Vector3 a = pts[currPt];
Vector3 b = pts[currPt + 1];
Vector3 c = pts[currPt + 2];
Vector3 d = pts[currPt + 3];
return .5f * (
(-a + 3f * b - 3f * c + d) * (u * u * u)
+ (2f * a - 5f * b + 4f * c - d) * (u * u)
+ (-a + c) * u
+ 2f * b
);
}
这是一个建公路的插件里面的,就是能创建路径点,通过拖拉路径点可以改变公路的形状.
Vector3 prevPt = Interp(vector3s,0);
int SmoothAmount = path.Length * SmoothSens; //path里装的应该是路径点,smoothsens是调整公路平滑的.
for (int i = 1; i
unity3d 貌似是bezier曲线的一个函数,public Vector3 Interp(Vector3[] pts,float t){int numSections = pts.Length - 3;int currPt = Mathf.Min(Mathf.FloorToInt(t * (float)numSections),numSections - 1);float u = t * (float)numSections - (float)curr
这个你得先去看一下bezier曲线的基础知识.
代码就是通过点数的不同,进行插值运算.获得曲线.