这个你得先去看一下bezier曲线的基础知识.
代码就是通过点数的不同,进行插值运算.获得曲线.
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
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
优质解答
我来回答
类似推荐
猜你喜欢
- 1尽吾志也而不能至者,可以无悔矣,其孰能讥之乎说明了什么道理
- 2如下图,大正方形内有一个最大的圆,圆内有一个最大的正方形算一算最大正方形的面积和小正方形比是多少、
- 3he told me that ……是什么从句啊?是宾语从句吗
- 4有7个数由大到小依次排列,其平均数是38,已知这组数的前4个数的平均数是33,后4个数的平均数是42,求这7个数的中位数.
- 51.三角形的三条中位线的长分别是3,4,5,这个三角形的周长是( ).2 一直等腰梯形的上,下底分别为4cm
- 61.5 1.2 1 寸焊管每米重量是什么?
- 7关于x的方程(k+1)x的平方+3(k-2)x+k的平方-42=0的一次项系数为0,则方程的常数项为
- 8“_ 最美 ”
- 9x^3-3X-10>0的不等式解集
- 10用数列极限的定义证明 lim (2+1/n) =2(用到∈和N)