在代码中调用下面这个方法,传入自己所要平滑的曲线的点的List列表,BezierCheck()会计算出每2个点之间需要补充多少个贝塞尔补间的点。
private static Vector3 pos1;private static Vector3 pos2;private static Vector3 pos3;private static Vector3 new_pos1;private static Vector3 new_pos2;private static Vector3 new_pos3;#region 贝塞尔曲线优化检测/// <summary>/// 贝塞尔曲线优化检测/// </summary>public static void BezierCheck(List<Vector3> bezierList){if (bezierList.Count > 2){pos1 = bezierList[bezierList.Count - 3];pos2 = bezierList[bezierList.Count - 2];pos3 = bezierList[bezierList.Count - 1];float count = (pos3 - pos1).magnitude / 0.25f;if (count < 1){return;}float pice = 1f / count;new_pos1 = Bezier(pos1, pos2, pos3, 0f);new_pos2 = Bezier(pos1, pos2, pos3, pice);new_pos3 = Bezier(pos1, pos2, pos3, 2 * pice);bezierList[bezierList.Count - 1] = new_pos3;bezierList[bezierList.Count - 2] = new_pos2;bezierList[bezierList.Count - 3] = new_pos1;for (float i = 3f; i * pice < 1; i++){bezierList.Add(Bezier(pos1, pos2, pos3, i * pice));}}}#endregion
上面那个方法里会调用到下面这个方法,这个方法的意义是计算出补间的贝塞尔点的坐标
private static Vector3 p0p1;private static Vector3 p1p2;private static Vector3 result;#region 三点求贝塞尔曲线/// <summary>///三点求贝塞尔曲线/// </summary>/// <returns>The bezier.</returns>/// <param name="p0">P0.</param>/// <param name="p1">P1.</param>/// <param name="p2">P2.</param>/// <param name="t">T.</param>public static Vector3 Bezier(Vector3 p0, Vector3 p1, Vector3 p2, float t){p0p1 = (1 - t) * p0 + t * p1;p1p2 = (1 - t) * p1 + t * p2;result = (1 - t) * p0p1 + t * p1p2;return result;}#endregion
本文发布于:2024-01-30 14:06:31,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170659479520535.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |