Пример #1
0
 // 重置数据
 private void ResetData()
 {
     // 点集合
     _pointLists.Clear();
     // 线段总长度
     _totalLength = _currentRunTime = 0;
     // 初始位置
     _prevPos = new BVector3(this.pointArr[0], 0, 0);
 }
Пример #2
0
        public void ComputeBezier(float dt, float runTime)
        {
            // 把时间从 [0,runTime] 映射到 [0,1] 之间
            float t = this._currentRunTime / runTime;

            float x = 0, y = 0, z = 0;
            //控制点数组
            float n = this.pointArr.Length - 1;

            for (int i = 0; i < this.pointArr.Length; i++)
            {
                Vector3 item = pointArr[i];
                if (i == 0)
                {
                    x += item.x * (float)(Math.Pow((1 - t), n - i) * Math.Pow(t, i));
                    y += item.y * (float)(Math.Pow((1 - t), n - i) * Math.Pow(t, i));
                    z += item.z * (float)(Math.Pow((1 - t), n - i) * Math.Pow(t, i));
                }
                else
                {
                    //factorial为阶乘函数
                    x += Factorial(n) / Factorial(i) / Factorial(n - i) * item.x * (float)Math.Pow((1 - t), n - i) * (float)Math.Pow(t, i);
                    y += Factorial(n) / Factorial(i) / Factorial(n - i) * item.y * (float)Math.Pow((1 - t), n - i) * (float)Math.Pow(t, i);
                    z += Factorial(n) / Factorial(i) / Factorial(n - i) * item.z * (float)Math.Pow((1 - t), n - i) * (float)Math.Pow(t, i);
                }
            }

            // 计算两点距离
            float    length = (float)(Math.Sqrt(Math.Pow(this._prevPos.pos.x - x, 2) + Math.Pow(this._prevPos.pos.y - y, 2) + Math.Pow(this._prevPos.pos.z - z, 2)));
            BVector3 v3     = new BVector3(new Vector3(x, y, z), length, 0);

            // 存储当前节点z
            this._pointLists.Add(v3);
            this._prevPos = v3;
            // 累计长度
            this._totalLength += length;
            // 累计时间
            this._currentRunTime += dt;
        }
Пример #3
0
        public BVector3 ComputeBezierPoint(float curTime, float runTime)
        {
            // 把时间从 [0,runTime] 映射到 [0,1] 之间
            float t = Evaluate(ease, curTime, runTime);

            float x = 0, y = 0, z = 0;
            //控制点数组
            float n = pointArr.Length - 1;

            for (int i = 0; i < pointArr.Length; i++)
            {
                Vector3 item = pointArr[i];
                if (i == 0)
                {
                    x += item.x * (float)(Math.Pow((1 - t), n - i) * Math.Pow(t, i));
                    y += item.y * (float)(Math.Pow((1 - t), n - i) * Math.Pow(t, i));
                    z += item.z * (float)(Math.Pow((1 - t), n - i) * Math.Pow(t, i));
                }
                else
                {
                    //factorial为阶乘函数
                    x += Factorial(n) / Factorial(i) / Factorial(n - i) * item.x * (float)Math.Pow((1 - t), n - i) * (float)Math.Pow(t, i);
                    y += Factorial(n) / Factorial(i) / Factorial(n - i) * item.y * (float)Math.Pow((1 - t), n - i) * (float)Math.Pow(t, i);
                    z += Factorial(n) / Factorial(i) / Factorial(n - i) * item.z * (float)Math.Pow((1 - t), n - i) * (float)Math.Pow(t, i);
                }
            }

            // 计算两点距离
            float    length = (float)(Math.Sqrt(Math.Pow(_prevPos.pos.x - x, 2) + Math.Pow(_prevPos.pos.y - y, 2) + Math.Pow(_prevPos.pos.z - z, 2)));
            BVector3 v3     = new BVector3(new Vector3(x, y, z), length, 0);

            // 存储当前节点z
            _pointLists.Add(v3);
            _prevPos = v3;
            // 累计长度
            _totalLength += length;
            return(v3);
        }