Esempio n. 1
0
        /// <summary>
        /// 添加节点
        /// </summary>
        /// <param name="newNode"></param>
        public void AddNode(Vector3 pos, float c)
        {
            Node node;

            if (nodeList.Count < 1)
            {
                node = new Node(pos);
            }
            else
            {
                node = new Node(pos, nodeList[nodeList.Count - 1]);
            }
            nodeList.Add(node);


            if (nodeList.Count > 1)
            {
                CurveSegement a = new CurveSegement(endNode, node, this);
                a.c = c;
                segmentList.Add(a);
                CaculateTangents(segmentList.Count - 1);               // 计算新加入的曲线段起始切线
            }
            else // 加入第一个节点
            {
                startNode = node;
            }
            endNode = node;
        }
Esempio n. 2
0
        /// <summary>
        /// 计算曲线段首尾切线
        /// </summary>
        /// <param name="index"></param>
        private void CaculateTangents(int index)
        {
            CurveSegement segement = segmentList[index];

            if (index == 0)
            {
                segement.startTangents = segement.endNode.pos - segement.endNode.pos;
                segement.endTangents   = segement.endNode.pos - segement.startNode.pos;
                return;
            }

            CurveSegement preSegement = segmentList[index - 1];

            segement.startTangents  = 0.5f * (1 - segement.c) * (segement.endNode.pos - preSegement.endNode.pos);
            segement.endTangents    = segement.endNode.pos - segement.startNode.pos;
            preSegement.endTangents = segement.startTangents;
        }