Unity 三点生成一段贝塞尔曲线脚本
来源:互联网 发布:最新网络语言 编辑:程序博客网 时间:2024/06/12 21:20
using UnityEngine;using System.Collections;//using Vectrosity;using System.Collections.Generic; public class DrawCurveTest : MonoBehaviour{ public Material lineMat; public int segment=20; //VectorLine line; public Transform[] poss = new Transform[3]; List m_points3; public GameObject cubePrefab; public LineRenderer lineRenderer; public Color c1 = Color.yellow; public Color c2 = Color.red; // Use this for initialization void Start() { lineRenderer = GetComponent(); lineRenderer.material = lineMat; lineRenderer.SetColors(c1, c2); lineRenderer.SetWidth(0.5F, 0.5F); lineRenderer.SetVertexCount(segment); } void CmakeCurve(Vector3 anchor1, Vector3 control1, Vector3 anchor2, Vector3 control2, int segments) { m_points3 = new List(segment); for (int i = 0; i < segment; i++) { Vector3 pp= GetBezierPoint3D(ref anchor1, ref control1, ref anchor2, ref control2, (float)i / segments, cubePrefab); m_points3.Add(pp); } } private static Vector3 GetBezierPoint3D(ref Vector3 anchor1, ref Vector3 control1, ref Vector3 anchor2, ref Vector3 control2, float t,GameObject go) { float cx = 3 * (control1.x - anchor1.x); float bx = 3 * (control2.x - control1.x) - cx; float ax = anchor2.x - anchor1.x - cx - bx; float cy = 3 * (control1.y - anchor1.y); float by = 3 * (control2.y - control1.y) - cy; float ay = anchor2.y - anchor1.y - cy - by; float cz = 3 * (control1.z - anchor1.z); float bz = 3 * (control2.z - control1.z) - cz; float az = anchor2.z - anchor1.z - cz - bz; // Vector3 pop=new Vector3((ax * (t * t * t)) + (bx * (t * t)) + (cx * t) + anchor1.x, // (ay * (t * t * t)) + (by * (t * t)) + (cy * t) + anchor1.y, // (az * (t * t * t)) + (bz * (t * t)) + (cz * t) + anchor1.z); // Instantiate(go, pop, Quaternion.identity); //return pop; return new Vector3((ax * (t * t * t)) + (bx * (t * t)) + (cx * t) + anchor1.x, (ay * (t * t * t)) + (by * (t * t)) + (cy * t) + anchor1.y, (az * (t * t * t)) + (bz * (t * t)) + (cz * t) + anchor1.z); } // Update is called once per frame void Update() { CmakeCurve(poss[0].position, poss[1].position, poss[2].position, poss[2].position, segment); int i = 0; while (i < m_points3.Count) { //Vector3 pos = new Vector3(i * 0.5F, Mathf.Sin(i + Time.time), 0); lineRenderer.SetPosition(i, m_points3[i]); i++; } }}
0 0
- Unity 三点生成一段贝塞尔曲线脚本
- VC 三点 划 曲线
- unity使用贝塞尔曲线
- Unity使用贝塞尔曲线
- Unity绘制贝塞尔曲线
- [Unity基础]贝塞尔曲线
- Unity 贝塞尔曲线
- 贝塞尔曲线 unity
- 【Unity】贝塞尔曲线关于点、长度、切线计算在 Unity中的C#实现
- Unity脚本生成图片
- 过三点的二次贝塞尔曲线及其升阶
- 一段生成linux passwd的perl脚本
- 给定4个关键点(一个起点,两个控制点,一个终点),如何生成贝塞尔曲线?
- 贝塞尔曲线生成算法
- 贝塞尔曲线生成算法
- Unity中使用贝塞尔曲线
- unity中使用贝塞尔曲线
- unity 贝塞尔曲线的制作
- CentOS7通过omnibus安装包搭建GitLab环境
- Android之Handler子线程的简单使用(二)
- nginx+uwsgi python应用
- 【matlab】预分配内存提高运行效率以及时间比较
- 解决Failed to execute goal org.apache.maven.plugins
- Unity 三点生成一段贝塞尔曲线脚本
- Little's Law(利特尔法则)的简要证明和重要应用(2012年某公司实习生招聘笔试试题)
- APUE[ "apue.h" ]
- 技术成长四个阶段需要的架构知识
- 关于${pageContext.request.contextPath }对于工程中的那个目录
- Unity 中子弹弓箭射击脚本
- lua 随机数-转
- 不曾走过,怎会懂得
- 如何成为一名数据科学家