Esempio n. 1
0
        // ============================================= Curve related
        //this is very slow
        public static void Split(BGCurvePoint @from, BGCurvePoint to, int parts, Action <Vector3, Vector3> action)
        {
            var noControls = @from.ControlType == BGCurvePoint.ControlTypeEnum.Absent && to.ControlType == BGCurvePoint.ControlTypeEnum.Absent;

            if (noControls)
            {
                action(@from.PositionWorld, to.PositionWorld);
            }
            else
            {
                var fromPos      = @from.PositionWorld;
                var toPos        = to.PositionWorld;
                var control1     = @from.ControlSecondWorld;
                var control2     = to.ControlFirstWorld;
                var bothControls = @from.ControlType != BGCurvePoint.ControlTypeEnum.Absent && to.ControlType != BGCurvePoint.ControlTypeEnum.Absent;
                if (!bothControls && @from.ControlType == BGCurvePoint.ControlTypeEnum.Absent)
                {
                    control1 = control2;
                }


                var prev = fromPos;
                for (var i = 1; i < parts + 1; i++)
                {
                    var ratio = i / (float)parts;

                    var currentPosition = bothControls
                        ? BGCurveFormulas.BezierCubic(ratio, fromPos, control1, control2, toPos)
                        : BGCurveFormulas.BezierQuadratic(ratio, fromPos, control1, toPos);
                    action(prev, currentPosition);
                    prev = currentPosition;
                }
            }
        }
Esempio n. 2
0
        //copy paste from math, not sure how to refactor it
        public static Vector3 CalculatePosition(BGCurvePoint @from, BGCurvePoint to, float t)
        {
            if (@from.ControlType == BGCurvePoint.ControlTypeEnum.Absent && to.ControlType == BGCurvePoint.ControlTypeEnum.Absent)
            {
                return(Vector3.Lerp(@from.PositionWorld, to.PositionWorld, t));
            }
            if (@from.ControlType != BGCurvePoint.ControlTypeEnum.Absent && to.ControlType != BGCurvePoint.ControlTypeEnum.Absent)
            {
                return(BGCurveFormulas.BezierCubic(t, @from.PositionWorld, @from.ControlSecondWorld, to.ControlFirstWorld, to.PositionWorld));
            }

            return(BGCurveFormulas.BezierQuadratic(t, @from.PositionWorld, @from.ControlType == BGCurvePoint.ControlTypeEnum.Absent ? to.ControlFirstWorld : @from.ControlSecondWorld,
                                                   to.PositionWorld));
        }