unity3d 貌似是bezier曲线的一个函数,

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
其他人气:709 ℃时间:2020-06-27 10:29:37
优质解答
这个你得先去看一下bezier曲线的基础知识.
代码就是通过点数的不同,进行插值运算.获得曲线.
我来回答
类似推荐
请使用1024x768 IE6.0或更高版本浏览器浏览本站点,以保证最佳阅读效果。本页提供作业小助手,一起搜作业以及作业好帮手最新版!
版权所有 CopyRight © 2012-2024 作业小助手 All Rights Reserved. 手机版