예제 #1
0
 /*public void Update()
 {
     //Ease ease = new Ease( Interpolate.Ease(easeType) );
     position.y = Interpolate.EaseInOutSine(startValue, endValue, elapsedTime, duration);
     elapsedTime += Time.deltaTime;
 }*/
 ////////////////////////////////////////////////////////////////
 public static void AddMovingBanner(string text, float fontSize, Vector3 position, float scale, Interpolate.EaseType easeType, float[] introAction, float[] outroAction, float delay, BannerColor color)
 {
     var banner = new Banner( text, fontSize, position, scale, easeType,  introAction, outroAction, delay, color);
     bannerList.Add(banner);
     banner.moving = true;
     banner.scaling = false;
 }
예제 #2
0
	public static void MoveTo(GameObject obj, Vector3 destination, float duration, Interpolate.EaseType easingFunction, Action<GameObject> onComplete = null, bool world = false)
	{
		Tweening tweening = obj.GetComponent<Tweening>();
		if (!tweening)
			tweening = obj.AddComponent<Tweening>();

		tweening.MoveTo(destination, duration, easingFunction, onComplete, world);
	}
예제 #3
0
 public void ColorTo(Color destination, float duration, Interpolate.EaseType easingFunction)
 {
     colorInitial = GetComponent<Renderer>().material.color;
     colorDisplacement = destination - colorInitial;
     colorFunc = Interpolate.Ease(easingFunction);
     colorDurationTotal = duration;
     colorDuration = 0;
 }
예제 #4
0
 public void MoveTo(Vector3 destination, float duration, Interpolate.EaseType easingFunction)
 {
     positionInitial = transform.localPosition;
     positionDisplacement = destination - positionInitial;
     positionFunc = Interpolate.Ease(easingFunction);
     positionDurationTotal = duration;
     positionDuration = 0;
 }
예제 #5
0
    public static void ScaleTo(GameObject obj, Vector3 destination, float duration, Interpolate.EaseType easingFunction, Action<GameObject> onComplete = null)
	{
		Tweening tweening = obj.GetComponent<Tweening>();
		if (!tweening)
			tweening = obj.AddComponent<Tweening>();

        tweening.ScaleTo(destination, duration, easingFunction, onComplete);
	}
예제 #6
0
    public static void ColorTo(GameObject obj, Color destination, float duration, Interpolate.EaseType easingFunction)
    {
        Tweening tweening = obj.GetComponent<Tweening>();
        if (!tweening)
            tweening = obj.AddComponent<Tweening>();

        tweening.ColorTo(destination, duration, easingFunction);
    }
예제 #7
0
	public void ScaleTo(Vector3 destination, float duration, Interpolate.EaseType easingFunction, Action<GameObject> onComplete)
	{
		scaleInitial = transform.localScale;
		scaleDisplacement = destination - scaleInitial;
		scaleFunc = Interpolate.Ease(easingFunction);
	    scaleOnComplete = onComplete;
		scaleDurationTotal = duration;
		scaleDuration = 0;
	}
예제 #8
0
    public void MoveTo(Vector3 destination, float duration, Interpolate.EaseType easingFunction, Action<GameObject> onComplete, bool world)
	{
        positionWorld = world;
        positionInitial = positionWorld ? transform.position : transform.localPosition;
		positionDisplacement = destination - positionInitial;
		positionFunc = Interpolate.Ease(easingFunction);
	    positionOnComplete = onComplete;
		positionDurationTotal = duration;
		positionDuration = 0;
	}
예제 #9
0
 /*public Banner(string text, Vector3 position, Interpolate.EaseType easeType, float startValue, float endValue, float duration)
 {
     this.text = text;
     this.position = position;
     this.easeType = easeType;
     this.startValue = startValue;
     this.endValue = endValue;
     this.duration = duration;
 }*/
 public Banner(string text, float fontSize, Vector3 position, float scale, Interpolate.EaseType easeType, float[] introAction, float[] outroAction, float delay, BannerColor color)
 {
     this.text = text;
     this.position = position;
     this.easeType = easeType;
     this.introAction = introAction;
     this.outroAction = outroAction;
     this.delay = delay;
     this.scale = scale;
     this.fontSize = fontSize;
     this.color = color;
 }
예제 #10
0
파일: Utils.cs 프로젝트: ZNCatlaw/LD33
        public static IEnumerator FadeAudio(AudioSource audio, float duration, Fade fadeType, Interpolate.EaseType easeType = Interpolate.EaseType.EaseOutExpo)
        {
            float start = fadeType == Fade.In ? 0.0f : 1.0f;
            float distance = fadeType == Fade.In ? 1.0f : -1.0f;
            float t = 0.0f;
            var easeFunction = Interpolate.Ease(easeType);

            while (t <= duration)
            {
                audio.volume = easeFunction(start, distance, t, duration);
                t += Time.deltaTime;
                yield return null;
            }
        }
예제 #11
0
    public void RotateTo(Vector3 destination, float duration, Interpolate.EaseType easingFunction, Action<GameObject> onComplete, bool world)
	{
        rotationWorld = world;
        rotationInitial = rotationWorld ? transform.rotation.eulerAngles : transform.localRotation.eulerAngles;

		rotationDisplacement = destination - rotationInitial;		
		var rotX = rotationDisplacement.x; // check the other way around the circle
		var rotY = rotationDisplacement.y; // for each component
		var rotZ = rotationDisplacement.z;
		var rotX2 = (rotationDisplacement.x + 360) % 360;
		var rotY2 = (rotationDisplacement.y + 360) % 360;
		var rotZ2 = (rotationDisplacement.z + 360) % 360;
		if (Mathf.Abs(rotX2) < Mathf.Abs(rotX)) rotX = rotX2;
		if (Mathf.Abs(rotY2) < Mathf.Abs(rotY)) rotY = rotY2;
		if (Mathf.Abs(rotZ2) < Mathf.Abs(rotZ)) rotZ = rotZ2;
		rotationDisplacement = new Vector3(rotX, rotY, rotZ);

		rotationFunc = Interpolate.Ease(easingFunction);
        rotationOnComplete = onComplete;
		rotationDurationTotal = duration;
		rotationDuration = 0;
	}
예제 #12
0
    /**
     * Instead of easing based on time, generate n interpolated points (slices)
     * between the start and end positions.
     */
    public static IEnumerator NewEase(Function ease, Vector3 start, Vector3 end, int slices)
    {
        IEnumerable <float> counter = Interpolate.NewCounter(0, slices + 1, 1);

        return(NewEase(ease, start, end, slices + 1, counter));
    }
예제 #13
0
 public void setDOMInterpolate(Interpolate interpolate)
 {
     DOMInter = interpolate;
 }
예제 #14
0
	public void ColorTo(Color destination, float duration, Interpolate.EaseType easingFunction, Action<GameObject> onComplete)
	{
		colorInitial = renderer.material.color;
		colorDisplacement = destination - colorInitial;
		colorFunc = Interpolate.Ease(easingFunction);
	    colorOnComplete = onComplete;
		colorDurationTotal = duration;
		colorDuration = 0;
	}
    void Update()
    {
        if (!_use)
        {
            return;
        }

        if (_emit && _emitTime != 0)
        {
            _emitTime -= Time.deltaTime;
            if (_emitTime == 0)
            {
                _emitTime = -1;
            }
            if (_emitTime < 0)
            {
                _emit = false;
            }
        }

        if (!_emit && _points.Count == 0 && _autoDestruct)
        {
            Destroy(_trailObject);
            Destroy(gameObject);
        }

        // early out if there is no camera
        if (!Camera.main)
        {
            return;
        }

        // if we have moved enough, create a new vertex and make sure we rebuild the mesh
        float theDistanceSqr = (_lastPosition - transform.position).sqrMagnitude;

        if (_emit)
        {
            if (theDistanceSqr > _minVertexDistanceSqr)
            {
                bool make = false;
                if (_points.Count < 3)
                {
                    make = true;
                }
                else
                {
                    //Vector3 l1 = _points[_points.Count - 2].basePosition - _points[_points.Count - 3].basePosition;
                    //Vector3 l2 = _points[_points.Count - 1].basePosition - _points[_points.Count - 2].basePosition;
                    Vector3 l1 = _points[_points.Count - 2].tipPosition - _points[_points.Count - 3].tipPosition;
                    Vector3 l2 = _points[_points.Count - 1].tipPosition - _points[_points.Count - 2].tipPosition;
                    if (Vector3.Angle(l1, l2) > _maxAngle || theDistanceSqr > _maxVertexDistanceSqr)
                    {
                        make = true;
                    }
                }

                if (make)
                {
                    Point p = new Point();
                    p.basePosition = _base.position;
                    p.tipPosition  = _tip.position;
                    p.timeCreated  = Time.time;
                    _points.Add(p);
                    _lastPosition = transform.position;


#if USE_INTERPOLATION
                    if (_points.Count == 1)
                    {
                        _smoothedPoints.Add(p);
                    }
                    else if (_points.Count > 1)
                    {
                        // add 1+subdivisions for every possible pair in the _points
                        for (int n = 0; n < 1 + subdivisions; ++n)
                        {
                            _smoothedPoints.Add(p);
                        }
                    }

                    // we use 4 control points for the smoothing
                    if (_points.Count >= 4)
                    {
                        Vector3[] tipPoints = new Vector3[4];
                        tipPoints[0] = _points[_points.Count - 4].tipPosition;
                        tipPoints[1] = _points[_points.Count - 3].tipPosition;
                        tipPoints[2] = _points[_points.Count - 2].tipPosition;
                        tipPoints[3] = _points[_points.Count - 1].tipPosition;

                        //IEnumerable<Vector3> smoothTip = Interpolate.NewBezier(Interpolate.Ease(Interpolate.EaseType.Linear), tipPoints, subdivisions);
                        IEnumerable <Vector3> smoothTip = Interpolate.NewCatmullRom(tipPoints, subdivisions, false);

                        Vector3[] basePoints = new Vector3[4];
                        basePoints[0] = _points[_points.Count - 4].basePosition;
                        basePoints[1] = _points[_points.Count - 3].basePosition;
                        basePoints[2] = _points[_points.Count - 2].basePosition;
                        basePoints[3] = _points[_points.Count - 1].basePosition;

                        //IEnumerable<Vector3> smoothBase = Interpolate.NewBezier(Interpolate.Ease(Interpolate.EaseType.Linear), basePoints, subdivisions);
                        IEnumerable <Vector3> smoothBase = Interpolate.NewCatmullRom(basePoints, subdivisions, false);

                        List <Vector3> smoothTipList  = new List <Vector3>(smoothTip);
                        List <Vector3> smoothBaseList = new List <Vector3>(smoothBase);

                        float firstTime  = _points[_points.Count - 4].timeCreated;
                        float secondTime = _points[_points.Count - 1].timeCreated;

                        //Debug.Log(" smoothTipList.Count: " + smoothTipList.Count);

                        for (int n = 0; n < smoothTipList.Count; ++n)
                        {
                            int idx = _smoothedPoints.Count - (smoothTipList.Count - n);
                            // there are moments when the _smoothedPoints are lesser
                            // than what is required, when elements from it are removed
                            if (idx > -1 && idx < _smoothedPoints.Count)
                            {
                                Point sp = new Point();
                                sp.basePosition      = smoothBaseList[n];
                                sp.tipPosition       = smoothTipList[n];
                                sp.timeCreated       = Mathf.Lerp(firstTime, secondTime, (float)n / smoothTipList.Count);
                                _smoothedPoints[idx] = sp;
                            }
                            //else
                            //{
                            //	Debug.LogError(idx + "/" + _smoothedPoints.Count);
                            //}
                        }
                    }
#endif
                }
                else
                {
                    _points[_points.Count - 1].basePosition = _base.position;
                    _points[_points.Count - 1].tipPosition  = _tip.position;
                    //_points[_points.Count - 1].timeCreated = Time.time;

#if USE_INTERPOLATION
                    _smoothedPoints[_smoothedPoints.Count - 1].basePosition = _base.position;
                    _smoothedPoints[_smoothedPoints.Count - 1].tipPosition  = _tip.position;
#endif
                }
            }
            else
            {
                if (_points.Count > 0)
                {
                    _points[_points.Count - 1].basePosition = _base.position;
                    _points[_points.Count - 1].tipPosition  = _tip.position;
                    //_points[_points.Count - 1].timeCreated = Time.time;
                }

#if USE_INTERPOLATION
                if (_smoothedPoints.Count > 0)
                {
                    _smoothedPoints[_smoothedPoints.Count - 1].basePosition = _base.position;
                    _smoothedPoints[_smoothedPoints.Count - 1].tipPosition  = _tip.position;
                }
#endif
            }
        }



        RemoveOldPoints(_points);
        if (_points.Count == 0)
        {
            _trailMesh.Clear();
        }

#if USE_INTERPOLATION
        RemoveOldPoints(_smoothedPoints);
        if (_smoothedPoints.Count == 0)
        {
            _trailMesh.Clear();
        }
#endif


#if USE_INTERPOLATION
        List <Point> pointsToUse = _smoothedPoints;
#else
        List <Point> pointsToUse = _points;
#endif


        // find the total length of the tip and base for proper UV Mapping
        float   totalTipLength  = 0;
        float   totalBaseLength = 0;
        float[] tipLengths      = new float[pointsToUse.Count];
        float[] baseLengths     = new float[pointsToUse.Count];

        for (int i = 0; i < pointsToUse.Count; i++)
        {
            if (i > 0)
            {
                Vector3 differenceTip  = pointsToUse[i].tipPosition - pointsToUse[i - 1].tipPosition;
                Vector3 differenceBase = pointsToUse[i].basePosition - pointsToUse[i - 1].basePosition;

                tipLengths[i]  = differenceTip.magnitude;
                baseLengths[i] = differenceBase.magnitude;

                totalTipLength  += differenceTip.magnitude;
                totalBaseLength += differenceBase.magnitude;
            }
            else
            {
                tipLengths[i]  = 0;
                baseLengths[i] = 0;
            }
        }

        if (pointsToUse.Count > 1)
        {
            Vector3[] newVertices  = new Vector3[pointsToUse.Count * 2];
            Vector2[] newUV        = new Vector2[pointsToUse.Count * 2];
            int[]     newTriangles = new int[(pointsToUse.Count - 1) * 6];
            Color[]   newColors    = new Color[pointsToUse.Count * 2];

            float totalTipTemp  = 0;
            float totalBaseTemp = 0;

            for (int n = 0; n < pointsToUse.Count; ++n)
            {
                Point p    = pointsToUse[n];
                float time = (Time.time - p.timeCreated) / _lifeTime;

                Color color = Color.Lerp(Color.white, Color.clear, time);
                if (_colors != null && _colors.Length > 0)
                {
                    float colorTime = time * (_colors.Length - 1);
                    float min       = Mathf.Floor(colorTime);
                    float max       = Mathf.Clamp(Mathf.Ceil(colorTime), 1, _colors.Length - 1);
                    float lerp      = Mathf.InverseLerp(min, max, colorTime);
                    if (min >= _colors.Length)
                    {
                        min = _colors.Length - 1;
                    }
                    if (min < 0)
                    {
                        min = 0;
                    }
                    if (max >= _colors.Length)
                    {
                        max = _colors.Length - 1;
                    }
                    if (max < 0)
                    {
                        max = 0;
                    }
                    color = Color.Lerp(_colors[(int)min], _colors[(int)max], lerp);
                }

                float size = 0f;
                if (_sizes != null && _sizes.Length > 0)
                {
                    float sizeTime = time * (_sizes.Length - 1);
                    float min      = Mathf.Floor(sizeTime);
                    float max      = Mathf.Clamp(Mathf.Ceil(sizeTime), 1, _sizes.Length - 1);
                    float lerp     = Mathf.InverseLerp(min, max, sizeTime);
                    if (min >= _sizes.Length)
                    {
                        min = _sizes.Length - 1;
                    }
                    if (min < 0)
                    {
                        min = 0;
                    }
                    if (max >= _sizes.Length)
                    {
                        max = _sizes.Length - 1;
                    }
                    if (max < 0)
                    {
                        max = 0;
                    }
                    size = Mathf.Lerp(_sizes[(int)min], _sizes[(int)max], lerp);
                }

                Vector3 lineDirection = p.tipPosition - p.basePosition;

                newVertices[n * 2]       = p.basePosition - (lineDirection * (size * 0.5f));
                newVertices[(n * 2) + 1] = p.tipPosition + (lineDirection * (size * 0.5f));

                newColors[n * 2] = newColors[(n * 2) + 1] = color;

                totalTipTemp  += tipLengths[n];
                totalBaseTemp += baseLengths[n];

                float uvRatioTip  = totalTipTemp / totalTipLength;
                float uvRatioBase = totalBaseTemp / totalBaseLength;
                newUV[n * 2]       = new Vector2(uvRatioTip, 0);
                newUV[(n * 2) + 1] = new Vector2(uvRatioBase, 1);

                if (n > 0)
                {
                    newTriangles[(n - 1) * 6]       = (n * 2) - 2;
                    newTriangles[((n - 1) * 6) + 1] = (n * 2) - 1;
                    newTriangles[((n - 1) * 6) + 2] = n * 2;

                    newTriangles[((n - 1) * 6) + 3] = (n * 2) + 1;
                    newTriangles[((n - 1) * 6) + 4] = n * 2;
                    newTriangles[((n - 1) * 6) + 5] = (n * 2) - 1;
                }
            }

            _trailMesh.Clear();
            _trailMesh.vertices  = newVertices;
            _trailMesh.colors    = newColors;
            _trailMesh.uv        = newUV;
            _trailMesh.triangles = newTriangles;
        }
    }
예제 #16
0
 public virtual Vector3 Calculate(float elapsedTime, float Duration)
 {
     _CurrentTime = elapsedTime;
     return(Interpolate.Ease(Interpolate.Ease(Interpolate.EaseType.Linear), this.OriginPosition, this.TargetPosition - this.OriginPosition, CurrentTime, this.TimeToFinish));
 }
예제 #17
0
 public NetSync()
 {
     this.method = string.Empty;
     this.callers = NetworkCallers.Everyone;
     this.interpolate = Interpolate.True;
 }
예제 #18
0
    public List <Vector3> createPath(Direction direction, float curveLevel, float difficulty, Vector3 ballPostion)
    {
        float          ballDistance = new Vector2(Mathf.Abs(ballPostion.x), Mathf.Abs(ballPostion.z)).magnitude;
        int            slide        = this.slideTest;
        List <Vector3> listTemp     = new List <Vector3>();

        Vector3 pointEnd    = Vector3.zero;                             // diem dich' den'
        Vector3 pointMiddle = Vector3.zero;
        Vector3 pointStart  = ballPostion;                              // diem bat dau

        if (direction == Direction.Both)
        {
            direction = (Direction)Random.Range(0, 2);
        }



        // *********************** Tinh yMid va yEnd ************************
        float yMidMin = 0.145f;
        float yMidMax = 4.3f;
        float yEnd_Min_When_Mid_Min = 0f, yEnd_Max_When_Mid_Min = 0f;
        float yEnd_Min_When_Mid_Max = 0f, yEnd_Max_When_Mid_Max = 0f;
        float yMid = 0f;
        float yEnd = 0f;

        bool found = false;

        // y nghia: tu thuc nghiem ta thu duoc ket wa khi sut banh o khoang cach' tu` 35m ve` 16.5m
        // moi ket wa gom cac thong so:
        // distance : khoang cach
        // yMidMin : yMin cua pointMiddle
        // yEnd_Min_When_Mid_Min	: yMin cua pointEnd khi yMiddle dat minimum
        // yEnd_Max_When_Mid_Min	: yMax cua pointEnd khi yMiddle dat minimum
        // yMidMax : yMax cua diem middle
        // yEnd_Min_When_Mid_Min	: yMin cua pointEnd khi yMiddle dat maximum
        // yEnd_Max_When_Mid_Min	: yMax cua pointEnd khi yMiddle dat maximum

        //	Cach su dung:
        // co' vi tri dat banh, tinh duoc distance dat banh den goc toa do.
        // tu distance se suy ra duoc no' nam trong Range nao`. Duyet mang~ de lay ra cai' Range do'
        // Co' Range roi` tinh' t roi Lerp de ra duoc cac' thong so' nhu tren ung' voi khoang cach dat banh.
        // Co thong so roi` thi random de tinh yMid, roi tu yMid se tinh duoc yEndMin va yEndMax va roi la yEnd


        for (int i = 1; i < dataShootAI.Length; ++i)                    // dataShootAI la mang du~ lieu thu duoc tu` thuc nghiem
        {
            DataShootAI data = dataShootAI[i];
            if (ballDistance <= data._distance)                                 // check xem khoang cach fu hop de xet chua
            {
                found = true;
                DataShootAI preMadeData = dataShootAI[i - 1];

                float t = (ballDistance - preMadeData._distance) / (data._distance - preMadeData._distance);

                yMidMin = Mathf.Lerp(preMadeData._yMid_Min, data._yMid_Min, t);
                yMidMax = Mathf.Lerp(preMadeData._yMid_Max, data._yMid_Max, t);
                yEnd_Min_When_Mid_Min = Mathf.Lerp(preMadeData._yEnd_Min_When_Mid_Min, data._yEnd_Min_When_Mid_Min, t);
                yEnd_Max_When_Mid_Min = Mathf.Lerp(preMadeData._yEnd_Max_When_Mid_Min, data._yEnd_Max_When_Mid_Min, t);
                yEnd_Min_When_Mid_Max = Mathf.Lerp(preMadeData._yEnd_Min_When_Mid_Max, data._yEnd_Min_When_Mid_Max, t);
                yEnd_Max_When_Mid_Max = Mathf.Lerp(preMadeData._yEnd_Max_When_Mid_Max, data._yEnd_Max_When_Mid_Max, t);

                yMid = Random.Range(yMidMin, yMidMax);

                t = Mathf.Abs(yMid - yMidMin) / Mathf.Abs(yMidMax - yMidMin);
                float yEndMin = Mathf.Lerp(yEnd_Min_When_Mid_Min, yEnd_Min_When_Mid_Max, t);
                float yEndMax = Mathf.Lerp(yEnd_Max_When_Mid_Min, yEnd_Max_When_Mid_Max, t);

                yEnd = Random.Range(yEndMin, yEndMax);

                break;
            }
        }

        if (found == false)                                         // neu for loop o tren ma ko thoa du chi 1 lan co' nghia~ la vi tri' da' banh >= 35m, nhu vay lay du lieu cua 35m ra doi` dung` lien`, ko can fai lerp nhu tren
        {
            DataShootAI data = dataShootAI[dataShootAI.Length - 1]; // dataShootAI.Length - 1 la vi tri du~ lieu khi sut banh o vi tri 35m
            yMid = Random.Range(data._yMid_Min, data._yMid_Max);    // random ra yMid

            float t       = Mathf.Abs(yMid - data._yMid_Min) / Mathf.Abs(data._yMid_Max - data._yMid_Min);
            float yEndMin = Mathf.Lerp(data._yEnd_Min_When_Mid_Min, data._yEnd_Min_When_Mid_Max, t); // co yMid roi se tinh duoc yEndMin
            float yEndMax = Mathf.Lerp(data._yEnd_Max_When_Mid_Min, data._yEnd_Max_When_Mid_Max, t); // co yMid roi se tinh duoc yEndMax

            yEnd = Random.Range(yEndMin, yEndMax);                                                   // random ra y end
        }
        // ***********************************************


        // *********************** Point End ************************
        float xTemp;
        float xMin = Mathf.Lerp(0, 3.3f, difficulty);
//		float xMax = Mathf.Lerp(3.6f, 3.5f, (ballDistance - 16f) / (22f - 16f));		// banh cang gan 16m thi cho xmax cang ra xa, tai vi cuoi ham nay` minh se fai remove nhung diem co' z gan` khung thanh 3m hoac nho hon
        float xMax = 3.45f;

        if (direction == Direction.Right)
        {
            xTemp = Random.Range(xMin, xMax);
        }
        else
        {
            xTemp = Random.Range(-xMax, -xMin);
        }

        pointEnd = new Vector3(xTemp, yEnd, 0f);                        // diem dau tien duoc add vo List cung la diem cuoi' cung se duoc lay ra
//		pointEnd.y = yEnd;
//		pointEnd.x = xEnd;
        // ***********************************************


        // ********************** Tim x la do be~ cong  *************************
        float x = (pointEnd.x + pointStart.x) / 2f;

        if (Mathf.Abs(pointStart.z) <= 32f)
        {
            // khi sut ra 2 goc' 2 ben cot doc thi fai co' gioi' han ve` do xoay' ra ngoai`. Do xoay' trong thi ko can care vi = 3 van an toan, banh ko bi vang ra ngoai
            // do xoay' ngoai duoc gioi' han lai theo cong thuc duoi' day khi z cua banh cach khung thanh <= 30m, > 30m thi do xoay' ngoai co' the bang maximum va van an toan, banh bao dam xoay' dzo goal
            // y tuong cua cong thuc la wa thuc nghiem ta biet duoc do xoay' ngoai an toan khi sut banh ra 2 goc (x = 3.4f hay = -3.4f) o khoang cach 30m la 3m, 16.5m la 0m. Ta se dung Mathf.Lerp de noi suy
            // khi sut banh gan` vi tri giua~ thi do xoay' ngoai` di~ nhien se duoc tang len cao hon ma ko so banh xoay' ra ngoai khung thanh, do' la ly' do tai sao co' 2 dong Lerp o duoi'

            float maxCurve = Mathf.Lerp(0, 3.5f, _animationCurve.Evaluate((Mathf.Abs(pointStart.z) - 16.5f) / (32f - 16.5f)));             // maxcurve la do xoay ngoai` toi' da khi da' vao` diem~ co' x = 3.4 hoac -3.4
            _maxRight = Mathf.Lerp(3.5f, maxCurve, pointEnd.x / (3.4f));
            _maxLeft  = Mathf.Lerp(-3.5f, -maxCurve, pointEnd.x / (-3.4f));
        }
        else
        {
            _maxLeft  = -3.5f;
            _maxRight = 3.5f;
        }

        float curveFactor = Mathf.Lerp(0f, 0.95f, curveLevel);                          // do kho cua xoay'
        float a           = Random.Range(_maxLeft, _maxLeft * curveFactor);             // random xoay ben fai
        float b           = Random.Range(_maxRight * curveFactor, _maxRight);           // random xoay ben trai
        float xCurve      = (((int)Random.Range(0, 2)) == 0) ? a : b;                   // random chon xoay ben fai hay ben trai

//		float xCurve = Mathf.Lerp(_maxLeft, _maxRight, curveLevel);					// do be cong duong di cua banh

        EventChangeCurveRange(xCurve);
        x += xCurve;                    // lam cho x cua diem giua~ bi lech se duoc ket qua la lam cho duong banh bi be cong xoay'
        // ***********************************************


        listTemp.Clear();
        if (pointStart.z >= -22f)                               // neu nhu diem dat banh cach' khung thanh 22m do~ lai thi tinh diem middle thuc su
        {
            pointMiddle.x = x;
            pointMiddle.y = yMid;
            pointMiddle.z = (pointEnd.z + pointStart.z) / 2f;
        }
        else                                    // neu nhu diem dat banh cach' khung thanh > 22m thi coi diem dat hang rao la diem middle, ket qua~ cug~ ok ko sao.
        {
            pointMiddle.z = pointStart.z + 11f; // z tai cho dat hang rao
            pointMiddle.x = x;
            pointMiddle.y = yMid;
        }

        // cac buoc tren la ap dung cho khi co' hang rao, neu' ko co' hang rao thi` chi can dzo if nay la ok, moi thu van dung. ko can chia 2 truong hop cho cac buoc tren
        if (Wall.share != null && !Wall.share.IsWall)                   // ko co hang rao
        {
            pointEnd.y    = Random.Range(0.145f, 2.8f);
            pointMiddle.y = Random.Range(0.145f, 4.3f);
            pointMiddle.z = (pointEnd.z + pointStart.z) / 2f;
        }

        listTemp.Clear();
        listTemp.Add(pointEnd);
        listTemp.Add(pointMiddle);
        listTemp.Add(pointStart);

        // ******************* tim diem cach khung thanh mot khoang cach mindistance *********************
        Vector3 closestPointToGoal = findPointInPathAtZ(Interpolate.Ease(easeType), listTemp.ToArray(), slide, -_ballControlLimit);
        // ****************************************


        // ******************** Final path ********************
        List <Vector3>        retVal = new List <Vector3>();
        IEnumerator <Vector3> nodes  = Interpolate.NewBezier(Interpolate.Ease(easeType), listTemp.ToArray(), slide).GetEnumerator();                    // tao ra path gom cac diem

        _debugPath.Clear();

        while (nodes.MoveNext())                                // lay cac diem cua path ra
        {
            _debugPath.Add(nodes.Current);

            //if(nodes.Current.z < -3f)
            if (nodes.Current.z < -_ballControlLimit)
            {
                retVal.Add(nodes.Current);
            }
        }
        retVal.Insert(0, closestPointToGoal);
        retVal.RemoveAt(retVal.Count - 1);

        //if( Vector3.Distance(retVal[0], retVal[1]) <= 4f)
        //    retVal.RemoveAt(1);
        // ****************************************


        return(retVal);
    }
예제 #19
0
    // Token: 0x06000473 RID: 1139 RVA: 0x000236A4 File Offset: 0x000218A4
    private void FixedUpdate()
    {
        if (!this._use)
        {
            return;
        }
        if (this._emit && this._emitTime != 0f)
        {
            this._emitTime -= Time.fixedDeltaTime;
            if (this._emitTime == 0f)
            {
                this._emitTime = -1f;
            }
            if (this._emitTime < 0f)
            {
                this._emit = false;
            }
        }
        if (!this._emit && this._points.Count == 0 && this._autoDestruct)
        {
            UnityEngine.Object.Destroy(this._trailObject);
            UnityEngine.Object.Destroy(base.gameObject);
        }
        if (Utils.GetMainCamera() == null)
        {
            return;
        }
        float sqrMagnitude = (this._lastPosition - base.transform.position).sqrMagnitude;

        if (this._emit)
        {
            if (sqrMagnitude > this._minVertexDistanceSqr)
            {
                bool flag = false;
                if (this._points.Count < 3)
                {
                    flag = true;
                }
                else
                {
                    Vector3 from = this._points[this._points.Count - 2].tipPosition - this._points[this._points.Count - 3].tipPosition;
                    Vector3 to   = this._points[this._points.Count - 1].tipPosition - this._points[this._points.Count - 2].tipPosition;
                    if (Vector3.Angle(from, to) > this._maxAngle || sqrMagnitude > this._maxVertexDistanceSqr)
                    {
                        flag = true;
                    }
                }
                if (flag)
                {
                    MeleeWeaponTrail.Point point = new MeleeWeaponTrail.Point();
                    point.basePosition = this._base.position;
                    point.tipPosition  = this._tip.position;
                    point.timeCreated  = Time.time;
                    this._points.Add(point);
                    this._lastPosition = base.transform.position;
                    if (this._points.Count == 1)
                    {
                        this._smoothedPoints.Add(point);
                    }
                    else if (this._points.Count > 1)
                    {
                        for (int i = 0; i < 1 + this.subdivisions; i++)
                        {
                            this._smoothedPoints.Add(point);
                        }
                    }
                    if (this._points.Count >= 4)
                    {
                        IEnumerable <Vector3> collection = Interpolate.NewCatmullRom(new Vector3[]
                        {
                            this._points[this._points.Count - 4].tipPosition,
                            this._points[this._points.Count - 3].tipPosition,
                            this._points[this._points.Count - 2].tipPosition,
                            this._points[this._points.Count - 1].tipPosition
                        }, this.subdivisions, false);
                        IEnumerable <Vector3> collection2 = Interpolate.NewCatmullRom(new Vector3[]
                        {
                            this._points[this._points.Count - 4].basePosition,
                            this._points[this._points.Count - 3].basePosition,
                            this._points[this._points.Count - 2].basePosition,
                            this._points[this._points.Count - 1].basePosition
                        }, this.subdivisions, false);
                        List <Vector3> list         = new List <Vector3>(collection);
                        List <Vector3> list2        = new List <Vector3>(collection2);
                        float          timeCreated  = this._points[this._points.Count - 4].timeCreated;
                        float          timeCreated2 = this._points[this._points.Count - 1].timeCreated;
                        for (int j = 0; j < list.Count; j++)
                        {
                            int num = this._smoothedPoints.Count - (list.Count - j);
                            if (num > -1 && num < this._smoothedPoints.Count)
                            {
                                MeleeWeaponTrail.Point point2 = new MeleeWeaponTrail.Point();
                                point2.basePosition       = list2[j];
                                point2.tipPosition        = list[j];
                                point2.timeCreated        = Mathf.Lerp(timeCreated, timeCreated2, (float)j / (float)list.Count);
                                this._smoothedPoints[num] = point2;
                            }
                        }
                    }
                }
                else
                {
                    this._points[this._points.Count - 1].basePosition = this._base.position;
                    this._points[this._points.Count - 1].tipPosition  = this._tip.position;
                    this._smoothedPoints[this._smoothedPoints.Count - 1].basePosition = this._base.position;
                    this._smoothedPoints[this._smoothedPoints.Count - 1].tipPosition  = this._tip.position;
                }
            }
            else
            {
                if (this._points.Count > 0)
                {
                    this._points[this._points.Count - 1].basePosition = this._base.position;
                    this._points[this._points.Count - 1].tipPosition  = this._tip.position;
                }
                if (this._smoothedPoints.Count > 0)
                {
                    this._smoothedPoints[this._smoothedPoints.Count - 1].basePosition = this._base.position;
                    this._smoothedPoints[this._smoothedPoints.Count - 1].tipPosition  = this._tip.position;
                }
            }
        }
        this.RemoveOldPoints(this._points);
        if (this._points.Count == 0)
        {
            this._trailMesh.Clear();
        }
        this.RemoveOldPoints(this._smoothedPoints);
        if (this._smoothedPoints.Count == 0)
        {
            this._trailMesh.Clear();
        }
        List <MeleeWeaponTrail.Point> smoothedPoints = this._smoothedPoints;

        if (smoothedPoints.Count > 1)
        {
            Vector3[] array  = new Vector3[smoothedPoints.Count * 2];
            Vector2[] array2 = new Vector2[smoothedPoints.Count * 2];
            int[]     array3 = new int[(smoothedPoints.Count - 1) * 6];
            Color[]   array4 = new Color[smoothedPoints.Count * 2];
            for (int k = 0; k < smoothedPoints.Count; k++)
            {
                MeleeWeaponTrail.Point point3 = smoothedPoints[k];
                float num2  = (Time.time - point3.timeCreated) / this._lifeTime;
                Color color = Color.Lerp(Color.white, Color.clear, num2);
                if (this._colors != null && this._colors.Length != 0)
                {
                    float num3 = num2 * (float)(this._colors.Length - 1);
                    float num4 = Mathf.Floor(num3);
                    float num5 = Mathf.Clamp(Mathf.Ceil(num3), 1f, (float)(this._colors.Length - 1));
                    float t    = Mathf.InverseLerp(num4, num5, num3);
                    if (num4 >= (float)this._colors.Length)
                    {
                        num4 = (float)(this._colors.Length - 1);
                    }
                    if (num4 < 0f)
                    {
                        num4 = 0f;
                    }
                    if (num5 >= (float)this._colors.Length)
                    {
                        num5 = (float)(this._colors.Length - 1);
                    }
                    if (num5 < 0f)
                    {
                        num5 = 0f;
                    }
                    color = Color.Lerp(this._colors[(int)num4], this._colors[(int)num5], t);
                }
                float num6 = 0f;
                if (this._sizes != null && this._sizes.Length != 0)
                {
                    float num7 = num2 * (float)(this._sizes.Length - 1);
                    float num8 = Mathf.Floor(num7);
                    float num9 = Mathf.Clamp(Mathf.Ceil(num7), 1f, (float)(this._sizes.Length - 1));
                    float t2   = Mathf.InverseLerp(num8, num9, num7);
                    if (num8 >= (float)this._sizes.Length)
                    {
                        num8 = (float)(this._sizes.Length - 1);
                    }
                    if (num8 < 0f)
                    {
                        num8 = 0f;
                    }
                    if (num9 >= (float)this._sizes.Length)
                    {
                        num9 = (float)(this._sizes.Length - 1);
                    }
                    if (num9 < 0f)
                    {
                        num9 = 0f;
                    }
                    num6 = Mathf.Lerp(this._sizes[(int)num8], this._sizes[(int)num9], t2);
                }
                Vector3 a = point3.tipPosition - point3.basePosition;
                array[k * 2]     = point3.basePosition - a * (num6 * 0.5f);
                array[k * 2 + 1] = point3.tipPosition + a * (num6 * 0.5f);
                array4[k * 2]    = (array4[k * 2 + 1] = color);
                float x = (float)k / (float)smoothedPoints.Count;
                array2[k * 2]     = new Vector2(x, 0f);
                array2[k * 2 + 1] = new Vector2(x, 1f);
                if (k > 0)
                {
                    array3[(k - 1) * 6]     = k * 2 - 2;
                    array3[(k - 1) * 6 + 1] = k * 2 - 1;
                    array3[(k - 1) * 6 + 2] = k * 2;
                    array3[(k - 1) * 6 + 3] = k * 2 + 1;
                    array3[(k - 1) * 6 + 4] = k * 2;
                    array3[(k - 1) * 6 + 5] = k * 2 - 1;
                }
            }
            this._trailMesh.Clear();
            this._trailMesh.vertices  = array;
            this._trailMesh.colors    = array4;
            this._trailMesh.uv        = array2;
            this._trailMesh.triangles = array3;
        }
    }
예제 #20
0
        internal Vector2 InterpolatedMouseLocation(float partialStep)
        {
            Vector2 vector = Interpolate.Vector(CurrentInput.MouseLocation, LastInput.MouseLocation, partialStep);

            return(vector);
        }
예제 #21
0
파일: Kneedle.cs 프로젝트: dc0d32/Kneedle
        /**
         * <summary>
         * <para>
         * Calculates knee points using the Kneedle algorithm. Returns the x value corresponding to the knee
         * point when successful, null otherwise.
         * </para>
         * <para>
         * Reference:
         *      Finding a ‘kneedle’in a haystack: Detecting knee points in system behavior.
         *      Satopaa, V and Albrecht, J and Irwin, D and Raghavan, B
         *      <see cref="https://raghavan.usc.edu/papers/kneedle-simplex11.pdf"/>
         * </para>
         *
         *  <list type="bullet">
         *  <param name="x">x: X axis values of the points. Points must be sorted in ascending order w.r.t. X axis.</param>
         *  <param name="y">y: Y axis values of the points.</param>
         *  <param name="direction">direction: If the curve is increasing or decreasing. Make sure to set this value according to the input curve.</param>
         *  <param name="concavity">concavity: Whether the curve has positive or negative curvature. In other words, concave or convex. Whether the tangent rotates clockwise or counterclockwise. Make sure to set this value according to the input curve.</param>
         *  <param name="sensitivity">sensitivity: Adjusts the knee detection threshold. Defaults to 1 as per the paper.</param>
         *  <param name="forceLinearInterpolation">forceLinearInterpolation: Interpolation is done using robust cubic splines. For some inputs, spline can overshoot. This param forces linear interpolation instead of cubic spline.</param>
         *  </list>
         *
         * Can return null when the algorithm fails to identify a knee/elbow for various reasons:
         *      - the number of data points is too small
         *      - there are no local maxima on the diffs, which means either the curve is a line, or the
         *        parameters provided are incompatible with the curve
         *
         *  <list type="bullet">
         *  2019-01-08: rename curvature enum to be easy to interpret and remember (Prashant Borole)
         *  2019-01-07: initial version (Prashant Borole)
         *  </list>
         *  </summary>
         */
        public static double?CalculateKneePoints(double[] x, double[] y, CurveDirection direction, Curvature concavity, double sensitivity = 1, bool forceLinearInterpolation = true)
        {
            if (x == null || y == null || x.Length != y.Length || x.Length < 2)
            {
                return(null);
            }

            var numPoints = x.Length;

            MathNet.Numerics.Interpolation.IInterpolation interpolator = null;
            if (numPoints > 5 && !forceLinearInterpolation)
            {
                interpolator = Interpolate.CubicSplineRobust(x, y);
            }
            else
            {
                interpolator = Interpolate.Linear(x, y);
            }
            var x_spaced = Generate.LinearSpaced(numPoints, x.Min(), x.Max());
            var y_spaced = Generate.Map(x_spaced, interpolator.Interpolate);

            var x_norm = MinMaxNormalize(x_spaced);
            var y_norm = MinMaxNormalize(y_spaced);

            var x_diff = x_norm;
            var y_diff = new double[numPoints];

            if (direction == CurveDirection.Decreasing)
            {
                for (int i = 0; i < numPoints; i++)
                {
                    y_diff[i] = x_norm[i] + y_norm[i];
                }
                if (concavity == Curvature.Counterclockwise)
                {
                    for (int i = 0; i < numPoints; i++)
                    {
                        y_diff[i] = 1 - y_diff[i];
                    }
                }
            }
            else
            {
                // increasing
                for (int i = 0; i < numPoints; i++)
                {
                    y_diff[i] = y_norm[i] - x_norm[i];
                }
                if (concavity == Curvature.Counterclockwise)
                {
                    for (int i = 0; i < numPoints; i++)
                    {
                        y_diff[i] = Math.Abs(y_diff[i]);
                    }
                }
            }


            // find local maxima
            var xmx_idxs = FindLocalExtrema(y_diff, true);

            if (xmx_idxs.Count == 0)
            {
                return(null);
            }
            var xmx = xmx_idxs.Select(idx => x_diff[idx]).ToArray();
            var ymx = xmx_idxs.Select(idx => y_diff[idx]).ToArray();

            // minima
            var xmn_idxs = FindLocalExtrema(y_diff, false);
            var xmn      = xmn_idxs.Select(idx => x_diff[idx]).ToArray();
            var ymn      = xmn_idxs.Select(idx => y_diff[idx]).ToArray();

            var tmx = Threshold(ymx, x_norm, sensitivity);

            // now find the knee point between each of the local maxima
            var    curMaximaIdx = 0;
            var    xmn_idxs_set = new HashSet <int>(xmn_idxs);
            double?knee         = null;

            for (int x_i = xmx_idxs[0] + 1; x_i < x.Length; x_i++)
            {
                if (curMaximaIdx < xmx_idxs.Count - 1 && x_i == xmx_idxs[curMaximaIdx + 1])
                {
                    curMaximaIdx++;
                    x_i++;
                    continue;
                }

                if (xmn_idxs_set.Contains(x_i))
                {
                    if (x_i < x.Length - 1 && y_diff[x_i + 1] > y_diff[x_i])
                    {
                        tmx[curMaximaIdx] = 0;
                    }
                }

                if (y_diff[x_i] < tmx[curMaximaIdx] || tmx[curMaximaIdx] < 0)
                {
                    knee = x[xmx_idxs[curMaximaIdx]];
                }
            }

            return(knee);
        }
예제 #22
0
    IEnumerator Move_co()
    {
        float time = 0;

        Vector3    oldPos = m_TargetPos;
        Quaternion oldRol = transform.rotation;

        if (m_hommingType == HOMMING_TYPE.AUTO)
        {
            List <Vector3> nodes = new List <Vector3>();
            nodes.Add(transform.position);

            for (int i = 0; i < m_ShotNodePos.Count; ++i)
            {
                nodes.Add(m_ShotNodePos[i]);
            }

            nodes.Add(m_TargetPos);
            IEnumerable <Vector3> res    = Interpolate.NewCatmullRom(nodes.ToArray(), detail, false);
            List <Vector3>        crPath = new List <Vector3>();
            int count = 0;

            IEnumerator iter = res.GetEnumerator();
            while (true == iter.MoveNext())
            {
                crPath.Add((Vector3)iter.Current);
            }

            count = crPath.Count;
            float startMovetime = m_ShotStartTime / (detail * m_ShotNodePos.Count + 1);
            float checkTime     = 0;
            checkTime += Time.deltaTime;
            for (int i = 0; i < (int)(detail * 1.1f);)
            {
                float value    = checkTime / startMovetime;
                int   nowIndex = (int)(value);
                value -= nowIndex;
                Vector3 nowP  = crPath[nowIndex];
                Vector3 nextP = crPath[nowIndex + 1];

                transform.position = Vector3.Lerp(nowP, nextP, value);
                transform.LookAt(nextP);
                i = nowIndex;
                yield return(Yielders.EndOfFrame);
            }
        }

        if (gameObject.GetComponent <Rigidbody>() == null)
        {
            Rigidbody rd = gameObject.AddComponent <Rigidbody>();
            rd.useGravity = false;
        }

        time = 0;
        Vector3 lockTarget = m_TargetPos;

        while (true)
        {
            float dTime = Time.deltaTime;
            transform.position += (transform.forward * m_HommingSpeed * dTime);
            time += dTime;

            if (time > m_LifeTimes)
            {
                break;
            }

            if (m_Target == null && m_ActiveTargetFind)
            {
                float dis = 0;

                // OPT : NearEnemy find function 통일
                m_Target = GameManager.GameWorkerInstance.NearEnemy(BulletFrom, ref dis);
                if (m_Target != null)
                {
                    float targetDis = Vector3.SqrMagnitude(m_Target.position - transform.position);
                    if (targetDis > m_FindRange * m_FindRange)
                    {
                        m_Target = null;
                    }
                }
            }

            if (m_Target != null)
            {
                lockTarget = m_Target.position + new Vector3(0, m_TargetPositonHeight, 0);
            }

            oldRol = transform.rotation;
            transform.LookAt(lockTarget);
            transform.rotation = Quaternion.Lerp(oldRol, transform.rotation, m_RolLevel);
            yield return(Yielders.EndOfFrame);
        }

        Destroy(gameObject);
    }
예제 #23
0
 private void Awake()
 {
     IEnumerable <Vector3> nodes = Interpolate.NewCatmullRom(path, betweenNodeCount, loop);
 }
예제 #24
0
    void Update()
    {
        if (_transforms.Length < 2)
        {
            return;
        }

        if (_emit && _emitTime != 0)
        {
            _emitTime -= Time.deltaTime;
            if (_emitTime == 0)
            {
                _emitTime = -1;
            }
            if (_emitTime < 0)
            {
                _emit = false;
            }
        }

        if (!_emit && _points.Count == 0 && _autoDestruct)
        {
            Destroy(_trailObject);
            Destroy(gameObject);
        }

        // early out if there is no camera
        if (!Camera.main)
        {
            return;
        }

        // if we have moved enough, create a new vertex and make sure we rebuild the mesh
        float theDistanceSqr = (_lastPosition - transform.position).sqrMagnitude;

        if (_emit)
        {
            if (theDistanceSqr > _minVertexDistanceSqr)
            {
                bool make = false;
                if (_points.Count < 3)
                {
                    make = true;
                }
                else
                {
                    //Vector3 l1 = _points[_points.Count - 2].basePosition - _points[_points.Count - 3].basePosition;
                    //Vector3 l2 = _points[_points.Count - 1].basePosition - _points[_points.Count - 2].basePosition;
                    Vector3 l1 = _points[_points.Count - 2].allVectors[0] - _points[_points.Count - 3].allVectors[0];
                    Vector3 l2 = _points[_points.Count - 1].allVectors[0] - _points[_points.Count - 2].allVectors[0];
                    if (Vector3.Angle(l1, l2) > _maxAngle || theDistanceSqr > _maxVertexDistanceSqr)
                    {
                        make = true;
                    }
                }

                if (make)
                {
                    Point p = new Point();
                    //p.allVectors.Clear();
                    for (int i = 0; i < _transforms.Length; ++i)
                    {
                        p.allVectors.Add(_transforms[i].position);
                    }
                    p.timeCreated = Time.time;
                    _points.Add(p);
                    _lastPosition = transform.position;

#if USE_INTERPOLATION
                    if (_points.Count == 1)
                    {
                        _smoothedPoints.Add(p);
                    }
                    else if (_points.Count > 1)
                    {
                        // add 1+subdivisions for every possible pair in the _points
                        for (int n = 0; n < 1 + subdivisions; ++n)
                        {
                            _smoothedPoints.Add(p);
                        }
                    }

                    // we use 4 control points for the smoothing
                    if (_points.Count >= 4)
                    {
                        List <List <Vector3> > vecsmooths = new List <List <Vector3> >();
                        int transformsSize     = _points[_points.Count - 4].allVectors.Count;
                        int smoothTipListCount = 0;
                        for (int i = 0; i < transformsSize; ++i)
                        {
                            //Debug.LogError( "transformsSize" + transformsSize );
                            Vector3[] tipPoints = new Vector3[4];
                            tipPoints[0] = _points[_points.Count - 4].allVectors[i];
                            tipPoints[1] = _points[_points.Count - 3].allVectors[i];
                            tipPoints[2] = _points[_points.Count - 2].allVectors[i];
                            tipPoints[3] = _points[_points.Count - 1].allVectors[i];

                            /// donot use Bezier  HelloHuan;
                            //IEnumerable<Vector3> smoothTip = Interpolate.NewBezier(Interpolate.Ease(Interpolate.EaseType.Linear), tipPoints, subdivisions);
                            IEnumerable <Vector3> smoothTip = Interpolate.NewCatmullRom(tipPoints, subdivisions, false);

                            List <Vector3> Tmp = new List <Vector3>(smoothTip);
                            smoothTipListCount = Tmp.Count;
                            //Debug.LogError( "smoothTipListCount\t\t" + smoothTipListCount );
                            vecsmooths.Add(Tmp);
                        }

                        float firstTime  = _points[_points.Count - 4].timeCreated;
                        float secondTime = _points[_points.Count - 1].timeCreated;

                        //Debug.Log(" smoothTipList.Count: " + smoothTipList.Count);
                        for (int n = 0; n < smoothTipListCount; ++n)
                        {
                            int idx = _smoothedPoints.Count - (smoothTipListCount - n);
                            // there are moments when the _smoothedPoints are lesser
                            // than what is required, when elements from it are removed
                            if (idx > -1 && idx < _smoothedPoints.Count)
                            {
                                Point sp = new Point();

                                for (int i = 0; i < transformsSize; ++i)
                                {
                                    sp.allVectors.Add(vecsmooths[i][n]);
                                }
                                sp.timeCreated       = Mathf.Lerp(firstTime, secondTime, (float)n / smoothTipListCount);
                                _smoothedPoints[idx] = sp;
                            }
                            //else
                            //{
                            //	Debug.LogError(idx + "/" + _smoothedPoints.Count);
                            //}
                        }
                    }
#endif
                }
                else
                {
                    if (_points[_points.Count - 1].allVectors.Count == _transforms.Length)
                    {
                        for (int i = 0; i < _transforms.Length; ++i)
                        {
                            _points[_points.Count - 1].allVectors[i] = (_transforms[i].position);
                        }
                    }
                    else
                    {
                        _points[_points.Count - 1].RemoveVectors();
                        for (int i = 0; i < _transforms.Length; ++i)
                        {
                            _points[_points.Count - 1].allVectors.Add(_transforms[i].position);
                        }
                    }

                    //_points[_points.Count - 1].timeCreated = Time.time;

#if USE_INTERPOLATION
//					_smoothedPoints[_smoothedPoints.Count - 1].RemoveVectors();
//					for(int i = 0; i < _transforms.Length; ++i)
//					{
//						_smoothedPoints[_smoothedPoints.Count - 1].allVectors.Add(_transforms[i].position);
//					}

                    if (_smoothedPoints[_smoothedPoints.Count - 1].allVectors.Count == _transforms.Length)
                    {
                        for (int i = 0; i < _transforms.Length; ++i)
                        {
                            _smoothedPoints[_smoothedPoints.Count - 1].allVectors[i] = (_transforms[i].position);
                        }
                    }
                    else
                    {
                        _smoothedPoints[_smoothedPoints.Count - 1].RemoveVectors();
                        for (int i = 0; i < _transforms.Length; ++i)
                        {
                            _smoothedPoints[_smoothedPoints.Count - 1].allVectors.Add(_transforms[i].position);
                        }
                    }
                                        #endif
                }
            }
            else
            {
                if (_points.Count > 0)
                {
//					for(int i = 0; i < _transforms.Length; ++i)
//					{
//						_points[_points.Count - 1].allVectors.Add(_transforms[i].position);
//					}
                    if (_points[_points.Count - 1].allVectors.Count == _transforms.Length)
                    {
                        for (int i = 0; i < _transforms.Length; ++i)
                        {
                            _points[_points.Count - 1].allVectors[i] = (_transforms[i].position);
                        }
                    }
                    else
                    {
                        _points[_points.Count - 1].RemoveVectors();
                        for (int i = 0; i < _transforms.Length; ++i)
                        {
                            _points[_points.Count - 1].allVectors.Add(_transforms[i].position);
                        }
                    }
                    //_points[_points.Count - 1].timeCreated = Time.time;
                }

#if USE_INTERPOLATION
                if (_smoothedPoints.Count > 0)
                {
//					for(int i = 0; i < _transforms.Length; ++i)
//					{
//						_smoothedPoints[_smoothedPoints.Count - 1].allVectors.Add(_transforms[i].position);
//					}
                    if (_smoothedPoints[_smoothedPoints.Count - 1].allVectors.Count == _transforms.Length)
                    {
                        for (int i = 0; i < _transforms.Length; ++i)
                        {
                            _smoothedPoints[_smoothedPoints.Count - 1].allVectors[i] = (_transforms[i].position);
                        }
                    }
                    else
                    {
                        _smoothedPoints[_smoothedPoints.Count - 1].RemoveVectors();
                        for (int i = 0; i < _transforms.Length; ++i)
                        {
                            _smoothedPoints[_smoothedPoints.Count - 1].allVectors.Add(_transforms[i].position);
                        }
                    }
                }
#endif
            }
        }

        RemoveOldPoints(_points);
        if (_points.Count == 0)
        {
            _trailMesh.Clear();
        }

#if USE_INTERPOLATION
        RemoveOldPoints(_smoothedPoints);
        if (_smoothedPoints.Count == 0)
        {
            _trailMesh.Clear();
        }
#endif


#if USE_INTERPOLATION
        List <Point> pointsToUse = _smoothedPoints;
#else
        List <Point> pointsToUse = _points;
#endif

        if (pointsToUse.Count > 1)
        {
            int       sectionPointSize = _transforms.Length;
            Vector3[] newVertices      = new Vector3[pointsToUse.Count * sectionPointSize];
            Vector2[] newUV            = new Vector2[pointsToUse.Count * sectionPointSize];
            int[]     newTriangles     = new int[(pointsToUse.Count - 1) * 6 * (sectionPointSize - 1)];
            Color[]   newColors        = new Color[pointsToUse.Count * sectionPointSize];

            for (int n = 0; n < pointsToUse.Count; ++n)
            {
                Point p    = pointsToUse[n];
                float time = (Time.time - p.timeCreated) / _lifeTime;

                Color color = Color.Lerp(Color.white, Color.clear, time);
                if (_colors != null && _colors.Length > 0)
                {
                    float colorTime = time * (_colors.Length - 1);
                    float min       = Mathf.Floor(colorTime);
                    float max       = Mathf.Clamp(Mathf.Ceil(colorTime), 1, _colors.Length - 1);
                    float lerp      = Mathf.InverseLerp(min, max, colorTime);
                    if (min >= _colors.Length)
                    {
                        min = _colors.Length - 1;
                    }
                    if (min < 0)
                    {
                        min = 0;
                    }
                    if (max >= _colors.Length)
                    {
                        max = _colors.Length - 1;
                    }
                    if (max < 0)
                    {
                        max = 0;
                    }
                    color = Color.Lerp(_colors[(int)min], _colors[(int)max], lerp);
                }

                float size = 0f;
                if (_sizes != null && _sizes.Length > 0)
                {
                    float sizeTime = time * (_sizes.Length - 1);
                    float min      = Mathf.Floor(sizeTime);
                    float max      = Mathf.Clamp(Mathf.Ceil(sizeTime), 1, _sizes.Length - 1);
                    float lerp     = Mathf.InverseLerp(min, max, sizeTime);
                    if (min >= _sizes.Length)
                    {
                        min = _sizes.Length - 1;
                    }
                    if (min < 0)
                    {
                        min = 0;
                    }
                    if (max >= _sizes.Length)
                    {
                        max = _sizes.Length - 1;
                    }
                    if (max < 0)
                    {
                        max = 0;
                    }
                    size = Mathf.Lerp(_sizes[(int)min], _sizes[(int)max], lerp);
                }

                Vector3 lineDirection = p.allVectors[sectionPointSize - 1] - p.allVectors[0];
                //newVertices[n * 2] = p.basePosition - (lineDirection * (size * 0.5f));
                //newVertices[(n * 2) + 1] = p.tipPosition + (lineDirection * (size * 0.5f));

                float deltaRatioxx = 1.0F / (sectionPointSize - 1);
                float uvRatio      = (float)n / pointsToUse.Count;
                for (int i = 0; i < sectionPointSize; ++i)
                {
                    newVertices[n * sectionPointSize + i] = p.allVectors[i] + (lineDirection * (size * ((deltaRatioxx * i) - 0.5f)));
                    newColors[(n * sectionPointSize) + i] = color;
                    newUV[(n * sectionPointSize) + i]     = new Vector2(uvRatio, deltaRatioxx * i);
                }
                if (n > 0)
                {
                    int triCount   = (sectionPointSize - 1) * 2;
                    int indexCount = triCount * 3;

                    for (int k = 0; k < sectionPointSize - 1; ++k)
                    {
                        newTriangles[(n - 1) * indexCount + 0 + 6 * k]   = ((n - 1) * sectionPointSize) + k;
                        newTriangles[((n - 1) * indexCount) + 1 + 6 * k] = ((n - 1) * sectionPointSize) + 1 + k;
                        newTriangles[((n - 1) * indexCount) + 2 + 6 * k] = (n * sectionPointSize) + k;

                        newTriangles[((n - 1) * indexCount) + 3 + 6 * k] = (n * sectionPointSize) + 1 + k;
                        newTriangles[((n - 1) * indexCount) + 4 + 6 * k] = (n * sectionPointSize) + 0 + k;
                        newTriangles[((n - 1) * indexCount) + 5 + 6 * k] = ((n - 1) * sectionPointSize) + 1 + k;
                    }
                }
            }

            _trailMesh.Clear();
            _trailMesh.vertices  = newVertices;
            _trailMesh.colors    = newColors;
            _trailMesh.uv        = newUV;
            _trailMesh.triangles = newTriangles;
            _trailObject.GetComponent <Renderer>().material.SetColor("_TintColor", _colors[0]);
            _trailObject.GetComponent <Renderer>().material.SetFloat("_Alpha", 0.5f);
        }
    }
예제 #25
0
    // Token: 0x0600044A RID: 1098 RVA: 0x00022B78 File Offset: 0x00020D78
    public static IEnumerator NewEase(Interpolate.Function ease, Vector3 start, Vector3 end, int slices)
    {
        IEnumerable <float> driver = Interpolate.NewCounter(0, slices + 1, 1);

        return(Interpolate.NewEase(ease, start, end, (float)(slices + 1), driver));
    }
예제 #26
0
 // Token: 0x06000455 RID: 1109 RVA: 0x00022FFF File Offset: 0x000211FF
 public static IEnumerable <Vector3> NewCatmullRom(Vector3[] points, int slices, bool loop)
 {
     return(Interpolate.NewCatmullRom <Vector3>(points, new Interpolate.ToVector3 <Vector3>(Interpolate.Identity), slices, loop));
 }
예제 #27
0
 internal int InterpolatedMouseDeltaY(float partialStep)
 {
     return((int)Interpolate.Scalar(CurrentInput.MouseState.Y, LastInput.MouseState.Y, partialStep));
 }
예제 #28
0
        /// <summary>
        /// Constructor defaulting to linear approximation
        /// </summary>
        /// <param name="pathfile"></param>
        /// <param name="pathname"></param>
        public IridelPath(string pathfile, string pathname)
        {
            mKeyFrameCount = 0;
            mTimeMin = 0;
            mTimeMax = 0;
            mTotalTime = 0;
            mRate = 1;
            // NEW
            parser = new MayaParser(pathfile);
            ReadPathData(parser.getFormattedData(pathname));

            mInterMethod = Interpolate.Linear;

            setAtStart();
        }
예제 #29
0
        public void RunUpdate(float dt)
        {
            if (!_active)
            {
                return;
            }
            //if (_autoDestruct && !CheckEmit(dt)) {
            //       return;
            //}
            if (_holder == null || _holder.Tr == null)
            {
                Setup();
            }
            if (_holder.Tr.parent != transform.root)
            {
                _holder.Tr.SetParentResetPos(transform.root);
            }
            if (!_holder.Renderer.enabled)
            {
                _holder.Renderer.enabled = true;
            }
            // if we have moved enough, create a new vertex and make sure we rebuild the mesh
            float theDistanceSqr = GetDistance();

            if (theDistanceSqr > _minVertexDistanceSqr)
            {
                bool make = false;
                if (_points.Count < 3)
                {
                    make = true;
                }
                else
                {
                    //Vector3 l1 = _points[_points.Count - 2].basePosition - _points[_points.Count - 3].basePosition;
                    //Vector3 l2 = _points[_points.Count - 1].basePosition - _points[_points.Count - 2].basePosition;
                    Vector3 l1 = _points[_points.Count - 2].TipPosition - _points[_points.Count - 3].TipPosition;
                    Vector3 l2 = _points[_points.Count - 1].TipPosition - _points[_points.Count - 2].TipPosition;
                    if (Vector3.Angle(l1, l2) > _maxAngle || theDistanceSqr > _maxVertexDistanceSqr)
                    {
                        make = true;
                    }
                }
                if (make)
                {
                    Point p = CreatePoint();
                    _points.Add(p);
                    SetLastPosition();
                    if (_useInterpolation)
                    {
                        if (_points.Count == 1)
                        {
                            _smoothedPoints.Add(p);
                        }
                        else if (_points.Count > 1)
                        {
                            // add 1+subdivisions for every possible pair in the _points
                            for (int n = 0; n < 1 + _subdivisions; ++n)
                            {
                                _smoothedPoints.Add(p);
                            }
                        }

                        // we use 4 control points for the smoothing
                        if (_points.Count >= 4)
                        {
                            Vector3[] tipPoints = new Vector3[4];
                            tipPoints[0] = _points[_points.Count - 4].TipPosition;
                            tipPoints[1] = _points[_points.Count - 3].TipPosition;
                            tipPoints[2] = _points[_points.Count - 2].TipPosition;
                            tipPoints[3] = _points[_points.Count - 1].TipPosition;

                            //IEnumerable<Vector3> smoothTip = Interpolate.NewBezier(Interpolate.Ease(Interpolate.EaseType.Linear), tipPoints, subdivisions);
                            IEnumerable <Vector3> smoothTip  = Interpolate.NewCatmullRom(tipPoints, _subdivisions, false);
                            Vector3[]             basePoints = new Vector3[4];
                            basePoints[0] = _points[_points.Count - 4].BasePosition;
                            basePoints[1] = _points[_points.Count - 3].BasePosition;
                            basePoints[2] = _points[_points.Count - 2].BasePosition;
                            basePoints[3] = _points[_points.Count - 1].BasePosition;

                            //IEnumerable<Vector3> smoothBase = Interpolate.NewBezier(Interpolate.Ease(Interpolate.EaseType.Linear), basePoints, subdivisions);
                            IEnumerable <Vector3> smoothBase = Interpolate.NewCatmullRom(basePoints, _subdivisions, false);
                            _smoothTipList.Clear();
                            _smoothTipList.AddRange(smoothTip);
                            _smoothBaseList.Clear();
                            _smoothBaseList.AddRange(smoothBase);
                            float firstTime  = _points[_points.Count - 4].TimeCreated;
                            float secondTime = _points[_points.Count - 1].TimeCreated;

                            //Debug.Log(" smoothTipList.Count: " + smoothTipList.Count);
                            for (int n = 0; n < _smoothTipList.Count; ++n)
                            {
                                int idx = _smoothedPoints.Count - (_smoothTipList.Count - n);
                                // there are moments when the _smoothedPoints are lesser
                                // than what is required, when elements from it are removed
                                if (idx > -1 && idx < _smoothedPoints.Count)
                                {
                                    Point sp = new Point(Mathf.Lerp(firstTime, secondTime, (float)n / _smoothTipList.Count), _smoothBaseList[n], _smoothTipList[n]);
                                    _smoothedPoints[idx] = sp;
                                }
                            }
                        }
                    }
                }
                else
                {
                    _points[_points.Count - 1] = CreatePoint(_points[_points.Count - 1]);
                    //_points[_points.Count - 1].timeCreated = Time.time;
                    if (_useInterpolation)
                    {
                        _smoothedPoints[_smoothedPoints.Count - 1] = CreatePoint(_smoothedPoints[_smoothedPoints.Count - 1]);
                    }
                }
            }
            else
            {
                if (_points.Count > 0)
                {
                    _points[_points.Count - 1] = CreatePoint(_points[_points.Count - 1]);
                    //_points[_points.Count - 1].timeCreated = Time.time;
                }
                if (_useInterpolation)
                {
                    if (_smoothedPoints.Count > 0)
                    {
                        _smoothedPoints[_smoothedPoints.Count - 1] = CreatePoint(_smoothedPoints[_smoothedPoints.Count - 1]);
                    }
                }
            }
            RemoveOldPoints(_points);
            if (_points.Count == 0)
            {
                _trailMesh.Clear();
            }

            if (_useInterpolation)
            {
                RemoveOldPoints(_smoothedPoints);
                if (_smoothedPoints.Count == 0)
                {
                    _trailMesh.Clear();
                }
            }

            List <Point> pointsToUse = _useInterpolation ? _smoothedPoints : _points;

            if (pointsToUse.Count > 1)
            {
                Vector3[] newVertices  = new Vector3[pointsToUse.Count * 2];
                Vector2[] newUV        = new Vector2[pointsToUse.Count * 2];
                int[]     newTriangles = new int[(pointsToUse.Count - 1) * 6];
                Color[]   newColors    = new Color[pointsToUse.Count * 2];

                for (int n = 0; n < pointsToUse.Count; ++n)
                {
                    Point p    = pointsToUse[n];
                    float time = (Time.time - p.TimeCreated) / _lifeTime;

                    Color color = Color.Lerp(Color.white, Color.clear, time);
                    if (_colors != null && _colors.Length > 0)
                    {
                        float colorTime = time * (_colors.Length - 1);
                        float min       = Mathf.Floor(colorTime);
                        float max       = Mathf.Clamp(Mathf.Ceil(colorTime), 1, _colors.Length - 1);
                        float lerp      = Mathf.InverseLerp(min, max, colorTime);
                        if (min >= _colors.Length)
                        {
                            min = _colors.Length - 1;
                        }
                        if (min < 0)
                        {
                            min = 0;
                        }
                        if (max >= _colors.Length)
                        {
                            max = _colors.Length - 1;
                        }
                        if (max < 0)
                        {
                            max = 0;
                        }
                        color = Color.Lerp(_colors[(int)min], _colors[(int)max], lerp);
                    }

                    float size = 0f;
                    if (_sizes != null && _sizes.Length > 0)
                    {
                        float sizeTime = time * (_sizes.Length - 1);
                        float min      = Mathf.Floor(sizeTime);
                        float max      = Mathf.Clamp(Mathf.Ceil(sizeTime), 1, _sizes.Length - 1);
                        float lerp     = Mathf.InverseLerp(min, max, sizeTime);
                        if (min >= _sizes.Length)
                        {
                            min = _sizes.Length - 1;
                        }
                        if (min < 0)
                        {
                            min = 0;
                        }
                        if (max >= _sizes.Length)
                        {
                            max = _sizes.Length - 1;
                        }
                        if (max < 0)
                        {
                            max = 0;
                        }
                        size = Mathf.Lerp(_sizes[(int)min], _sizes[(int)max], lerp);
                    }

                    Vector3 lineDirection = p.TipPosition - p.BasePosition;

                    newVertices[n * 2]       = p.BasePosition - (lineDirection * (size * 0.5f));
                    newVertices[(n * 2) + 1] = p.TipPosition + (lineDirection * (size * 0.5f));

                    newColors[n * 2] = newColors[(n * 2) + 1] = color;

                    float uvRatio = (float)n / pointsToUse.Count;
                    newUV[n * 2]       = new Vector2(uvRatio, 0);
                    newUV[(n * 2) + 1] = new Vector2(uvRatio, 1);

                    if (n > 0)
                    {
                        newTriangles[(n - 1) * 6]       = (n * 2) - 2;
                        newTriangles[((n - 1) * 6) + 1] = (n * 2) - 1;
                        newTriangles[((n - 1) * 6) + 2] = n * 2;

                        newTriangles[((n - 1) * 6) + 3] = (n * 2) + 1;
                        newTriangles[((n - 1) * 6) + 4] = n * 2;
                        newTriangles[((n - 1) * 6) + 5] = (n * 2) - 1;
                    }
                }

                _trailMesh.Clear();
                _trailMesh.vertices  = newVertices;
                _trailMesh.colors    = newColors;
                _trailMesh.uv        = newUV;
                _trailMesh.triangles = newTriangles;
            }
        }
예제 #30
0
        /// <summary>
        /// To be used by derived classes for shared particle setup
        /// </summary>
        /// <param name="p">particle to setup</param>
        protected virtual void configureNewParticle(SSParticle p)
        {
            p.life = Interpolate.Lerp(lifeMin, lifeMax, nextFloat());

            p.componentScale.X = Interpolate.Lerp(componentScaleMin.X, componentScaleMax.X, nextFloat());
            p.componentScale.Y = Interpolate.Lerp(componentScaleMin.Y, componentScaleMax.Y, nextFloat());
            p.componentScale.Z = Interpolate.Lerp(componentScaleMin.Z, componentScaleMax.Z, nextFloat());

            if (billboardXY)
            {
                p.billboardXY = true;
            }
            else
            {
                p.orientation.X = Interpolate.Lerp(_orientationMin.X, _orientationMax.X, nextFloat());
                p.orientation.Y = Interpolate.Lerp(_orientationMin.Y, _orientationMax.Y, nextFloat());
            }
            p.orientation.Z = Interpolate.Lerp(_orientationMin.Z, _orientationMax.Z, nextFloat());

            p.angularVelocity.X = Interpolate.Lerp(angularVelocityMin.X, angularVelocityMax.X, nextFloat());
            p.angularVelocity.Y = Interpolate.Lerp(angularVelocityMin.Y, angularVelocityMax.Y, nextFloat());
            p.angularVelocity.Z = Interpolate.Lerp(angularVelocityMin.Z, angularVelocityMax.Z, nextFloat());

            p.vel.X = Interpolate.Lerp(velocityComponentMin.X, velocityComponentMax.X, nextFloat());
            p.vel.Y = Interpolate.Lerp(velocityComponentMin.Y, velocityComponentMax.Y, nextFloat());
            p.vel.Z = Interpolate.Lerp(velocityComponentMin.Z, velocityComponentMax.Z, nextFloat());

            p.masterScale = Interpolate.Lerp(masterScaleMin, masterScaleMax, nextFloat());

            p.mass = Interpolate.Lerp(massMin, massMax, nextFloat());
            p.rotationalInnertia = Interpolate.Lerp(rotationalInnertiaMin, rotationalInnertiaMax, nextFloat());
            p.drag           = Interpolate.Lerp(dragMin, dragMax, nextFloat());
            p.rotationalDrag = Interpolate.Lerp(rotationalDragMin, rotationalDragMax, nextFloat());

            // color presets
            Color4 randPreset;

            if (colorPresets != null && colorPresets.Length > 0)
            {
                randPreset = colorPresets [_rand.Next(0, colorPresets.Length)];
            }
            else
            {
                randPreset = new Color4(0f, 0f, 0f, 0f);
            }

            // color offsets
            Color4 randOffset;

            randOffset.R = Interpolate.Lerp(colorOffsetComponentMin.R, colorOffsetComponentMax.R, nextFloat());
            randOffset.G = Interpolate.Lerp(colorOffsetComponentMin.G, colorOffsetComponentMax.G, nextFloat());
            randOffset.B = Interpolate.Lerp(colorOffsetComponentMin.B, colorOffsetComponentMax.B, nextFloat());
            randOffset.A = Interpolate.Lerp(colorOffsetComponentMin.A, colorOffsetComponentMax.A, nextFloat());

            // color presets + offsets
            p.color = Color4Helper.Add(ref randPreset, ref randOffset);

            //p.SpriteIndex = SpriteIndices [s_rand.Next(0, SpriteIndices.Length)];
            p.spriteRect = spriteRectangles [_rand.Next(0, spriteRectangles.Length)];

            p.effectorMask = effectorMasks [_rand.Next(0, effectorMasks.Length)];
        }
예제 #31
0
 public static void RotateBy(GameObject obj, Vector3 displacement, float duration, Interpolate.EaseType easingFunction)
 {
     Vector3 destination = obj.transform.localRotation.eulerAngles + displacement;
     RotateTo(obj, destination, duration, easingFunction);
 }
예제 #32
0
 private void forceStopBtn_Click(object sender, EventArgs e)
 {
     Interpolate.Cancel("Force stopped by user.");
     BatchProcessing.stopped = true;
 }
예제 #33
0
 public static void ScaleBy(GameObject obj, Vector3 displacement, float duration, Interpolate.EaseType easingFunction)
 {
     Vector3 destination = obj.transform.localScale + displacement;
     ScaleTo(obj, destination, duration, easingFunction);
 }
    // Update is called once per frame
    void Update()
    {
        Vector3 curr = transform.position;
        Vector3 adder;
        float   posX = 0f;
        float   posY = 0f;

#if !UNITY_IOS
        adder = new Vector3(Input.GetAxis("Horizontal") * ((Input.GetKey(KeyCode.LeftShift) | Input.GetKey(KeyCode.RightShift))?1:.3f),
                            Input.GetAxis("Vertical") * ((Input.GetKey(KeyCode.LeftShift) | Input.GetKey(KeyCode.RightShift))?1:.3f));
        posX = (curr + (adder / denominator) * zoomLevel).x;
        posY = (curr + (adder / denominator) * zoomLevel).y;
#else
        if (sbRemote.GetButtonDown(sbRemote.BUTTON_BACK))
        {
            motionControl = !motionControl;
        }
        if (!motionControl)
        {
            adder = new Vector3(sbRemote.GetAxis(sbRemote.JOY_HORIZONTAL),
                                sbRemote.GetAxis(sbRemote.JOY_VERTICAL));
        }
        else
        {
            // Use the remote tilt and roll to handle movement.
            float pitch = 0f;
            if (sbRemote.remoteOrientation.eulerAngles.x > 180)
            {
                pitch = (360f - sbRemote.remoteOrientation.eulerAngles.x);
            }
            else
            {
                pitch = -(sbRemote.remoteOrientation.eulerAngles.x);
            }
            adder = new Vector3((180f - (Mathf.Clamp(sbRemote.remoteOrientation.eulerAngles.z, 90f, 270f))) / 180f,
                                pitch / 180f);
        }

        posX = (curr + (adder / denominator) * zoomLevel).x;
        posY = (curr + (adder / denominator) * zoomLevel).y;
                #endif
        Vector3 newPosition = new Vector3();
        newPosition.x = curr.x;
        newPosition.y = curr.y;
        newPosition.z = curr.z;
        if (posX < 16039.46f && posX > -17743.39f)
        {
            newPosition.x = posX;
        }
        else if (posX > 16039.46)
        {
            newPosition.x = 16039.46f;
        }
        else if (posX < -17743.39f)
        {
            newPosition.x = -17743.39f;
        }

        if (posY < 8800 && posY > -8154.197)
        {
            newPosition.y = posY;
        }
        else if (posY < -8154.197)
        {
            newPosition.y = -8154;
        }
        else if (posY > 8800.0)
        {
            newPosition.y = 8800.0f;
        }
//					newPiority = true

        transform.position = newPosition;
        //ScrollWheel to zoom in and out.
        mousePos   = cameraNormal.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, cameraNormal.transform.position.z));
        dragOrigin = cameraNormal.ScreenToWorldPoint(new Vector3(Screen.width / 2, Screen.height / 2, cameraNormal.transform.position.z));
        if ((cameraLeft.orthographicSize >= .20f && cameraLeft.orthographicSize <= 8500) &&
            (cameraNormal.orthographicSize >= .20f && cameraNormal.orthographicSize <= 8500))
        {
            if (cameraLeft.orthographicSize > .2f)
            {
                if (Input.GetAxis("Mouse ScrollWheel") > 0)
                {
                    cameraLeft.orthographicSize   -= cameraLeft.orthographicSize / 4f;
                    cameraRight.orthographicSize  -= cameraRight.orthographicSize / 4f;
                    cameraNormal.orthographicSize -= cameraNormal.orthographicSize / 4f;
                    newPosition.y = transform.position.y + ((mousePos.y - dragOrigin.y) / (cameraNormal.orthographicSize * 2));
                    newPosition.x = transform.position.x + ((mousePos.x - dragOrigin.x) / (cameraNormal.orthographicSize * 2));
                    newPosition.z = -10;
                }
                else
                {
                    cameraLeft.orthographicSize -= cameraLeft.orthographicSize *
                                                   (sbRemote.GetButton(sbRemote.BUTTON_SELECT) | Input.GetKey(KeyCode.PageDown)?1:0) /
                                                   (20.0f * ((Input.GetKey(KeyCode.LeftShift) | Input.GetKey(KeyCode.RightShift))?1:2));
                    cameraRight.orthographicSize -= cameraRight.orthographicSize *
                                                    (sbRemote.GetButton(sbRemote.BUTTON_SELECT) | Input.GetKey(KeyCode.PageDown)?1:0) /
                                                    (20.0f * ((Input.GetKey(KeyCode.LeftShift) | Input.GetKey(KeyCode.RightShift))?1:2));
                    cameraNormal.orthographicSize -= cameraNormal.orthographicSize *
                                                     (sbRemote.GetButton(sbRemote.BUTTON_SELECT) | Input.GetKey(KeyCode.PageDown)?1:0) /
                                                     (20.0f * ((Input.GetKey(KeyCode.LeftShift) | Input.GetKey(KeyCode.RightShift))?1:2));
                }
            }
            if (cameraLeft.orthographicSize < 8500)
            {
                if (Input.GetAxis("Mouse ScrollWheel") < 0)
                {
                    cameraLeft.orthographicSize   += cameraLeft.orthographicSize / 4f;
                    cameraRight.orthographicSize  += cameraRight.orthographicSize / 4f;
                    cameraNormal.orthographicSize += cameraNormal.orthographicSize / 4f;
                    newPosition.y = transform.position.y - ((mousePos.y - dragOrigin.y) / (cameraNormal.orthographicSize * 2));
                    newPosition.x = transform.position.x - ((mousePos.x - dragOrigin.x) / (cameraNormal.orthographicSize * 2));
                    mousePos      = cameraNormal.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0 - cameraNormal.transform.position.z));
                    dragOrigin    = cameraNormal.transform.position;
                }
                else
                {
                    cameraLeft.orthographicSize += cameraLeft.orthographicSize *
                                                   (sbRemote.GetButton(sbRemote.BUTTON_OPTION) | Input.GetKey(KeyCode.PageUp)?1:0) /
                                                   (20.0f * ((Input.GetKey(KeyCode.LeftShift) | Input.GetKey(KeyCode.RightShift))?1:2));
                    cameraRight.orthographicSize += cameraRight.orthographicSize *
                                                    (sbRemote.GetButton(sbRemote.BUTTON_OPTION) | Input.GetKey(KeyCode.PageUp)?1:0) /
                                                    (20.0f * ((Input.GetKey(KeyCode.LeftShift) | Input.GetKey(KeyCode.RightShift))?1:2));
                    cameraNormal.orthographicSize += cameraNormal.orthographicSize *
                                                     (sbRemote.GetButton(sbRemote.BUTTON_OPTION) | Input.GetKey(KeyCode.PageUp)?1:0) /
                                                     (20.0f * ((Input.GetKey(KeyCode.LeftShift) | Input.GetKey(KeyCode.RightShift))?1:2));
                }
            }
            transform.position = newPosition;
            zoomLevel          = cameraRight.orthographicSize;
        }
        else if (cameraLeft.orthographicSize < .2f)
        {
            cameraLeft.orthographicSize   = .2f;
            cameraRight.orthographicSize  = .2f;
            cameraNormal.orthographicSize = .2f;
        }
        else if (cameraLeft.orthographicSize >= 8500 || Input.GetKey(KeyCode.PageUp) || Input.GetAxis("Mouse ScrollWheel") < 0)
        {
            warpToCorrespondingObject(outerObject, warpSprite);
        }
        // Detect if we are within a warp zone
        if (zoomLevel < warpSprite.bounds.extents.y &&
            transform.position.x > warpSprite.transform.position.x - warpSprite.bounds.extents.x - .5 &&
            transform.position.x < warpSprite.transform.position.x + warpSprite.bounds.extents.x + .5 &&
            transform.position.y > warpSprite.transform.position.y - warpSprite.bounds.extents.y - .5 &&
            transform.position.y < warpSprite.transform.position.y + warpSprite.bounds.extents.y + .5)
        {
            warpToCorrespondingObject(warpSprite, outerObject);
        }
        if (Input.GetKeyDown(KeyCode.Home))
        {
            animating = false;
            goToPosition(startPos);
        }
        else if (Input.GetKeyDown(KeyCode.Space) || sbRemote.GetButton(sbRemote.BUTTON_TRIGGER))
        {
            animating = false;
            nextScene();
        }
        else if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.Z))
        {
            animateToPosition(warpSprite.bounds);
            animating = false;
        }
        else if (Input.GetKeyDown(KeyCode.V))
        {
            animating = false;
            goToPosition(outerObject);
        }
        else if (Input.GetKeyDown(KeyCode.Backspace))
        {
            animating = false;
            Debug.Log(printPosition());
        }
        if (animating)
        {
            elapsed += Time.deltaTime;
//			lastTime=Time.time;
//			float fracJourney = distCovered / journeyLength;

            curPosition.x      = Interpolate.Ease(Interpolate.EaseType.EaseInOutQuad)(start_x, dist_x, elapsed, tourLength);
            curPosition.y      = Interpolate.Ease(Interpolate.EaseType.EaseInOutQuad)(start_y, dist_y, elapsed, tourLength);
            transform.position = curPosition;
            if (elapsed <= 7.5f)
            {
                zoomLevel = Interpolate.Ease(Interpolate.EaseType.EaseInOutQuad)(startZoom, endZoom - startZoom, elapsed, tourLength + 1f);
            }
            else
            {
                animating          = false;
                curPosition.x      = start_x + dist_x;
                curPosition.y      = start_y + dist_y;
                transform.position = destination;
            }
            cameraLeft.orthographicSize = cameraRight.orthographicSize = cameraNormal.orthographicSize = zoomLevel;
        }
    }
			public NetSync(string method, NetworkCallers callers)
			{
				this.method = method;
				this.callers = callers;
				interpolate = Interpolate.True;
			}
예제 #36
0
        /// <summary>
        /// Writes one tile of current zoom.
        /// <para/>Crops zoom directly from input image.
        /// </summary>
        /// <param name="zoom">Zoom level.</param>
        /// <param name="tileX">Tile x.</param>
        /// <param name="tileY">Tile y.</param>
        /// <param name="inputImage">Input image.</param>
        private void WriteTile(int zoom, int tileX, int tileY, NetVips.Image inputImage)
        {
            #region Parameters checking

            if (zoom < 0)
            {
                throw new ImageException(string.Format(Strings.LesserThan, nameof(zoom), 0));
            }
            if (tileX < 0)
            {
                throw new ImageException(string.Format(Strings.LesserThan, nameof(tileX), 0));
            }
            if (tileY < 0)
            {
                throw new ImageException(string.Format(Strings.LesserThan, nameof(tileY), 0));
            }

            #endregion

            //Create directories for the tile. The overall structure looks like: outputDirectory/zoom/x/y.png.
            DirectoryInfo tileDirectoryInfo = new DirectoryInfo(Path.Combine(OutputDirectoryInfo.FullName,
                                                                             $"{zoom}", $"{tileX}"));
            CheckHelper.CheckDirectory(tileDirectoryInfo);

            const bool centreConvention = false;

            //Get the coordinate borders for current tile from tile numbers.
            (double minX, double minY, double maxX, double maxY) = Tile.Tile.TileBounds(tileX, tileY, zoom, TmsCompatible);

            //Get postitions and sizes for current tile.
            (int readPosX, int readPosY, int readXSize, int readYSize, int writePosX, int writePosY,
             int writeXSize, int writeYSize) = GeoQuery(minX, maxY, maxX, minY);

            //Warning: OpenLayers requires replacement of tileY to tileY+1
            FileInfo outputTileFileInfo = new FileInfo(Path.Combine(tileDirectoryInfo.FullName,
                                                                    $"{tileY}{Enums.Extensions.Png}"));

            //Try open input image and crop tile
            NetVips.Image tileImage;
            try
            {
                tileImage = inputImage.Crop(readPosX, readPosY, readXSize, readYSize);
            }
            catch (Exception exception)
            {
                throw new ImageException(string.Format(Strings.UnableToCreateTile, tileX, tileY), exception);
            }

            // Scaling calculations
            double xScale = 1.0 / ((double)tileImage.Width / writeXSize);
            double yScale = 1.0 / ((double)tileImage.Height / writeYSize);

            // Calculate integral box shrink
            // We will get the best quality (but be the slowest) if we let reduce
            // do all the work. Leave it the final 200 - 300% to do as a compromise
            // for efficiency.
            int xShrink = Math.Max(1, (int)Math.Floor(1.0 / (xScale * 2.0)));
            int yShrink = Math.Max(1, (int)Math.Floor(1.0 / (yScale * 2.0)));

            // Fast, integral box-shrink
            if (yShrink > 1)
            {
                tileImage = tileImage.Shrinkv(yShrink);
                yScale   *= yShrink;
            }
            if (xShrink > 1)
            {
                tileImage = tileImage.Shrinkh(xShrink);
                xScale   *= xShrink;
            }

            // Any residual downsizing
            if (yScale < 1.0)
            {
                tileImage = tileImage.Reducev(1.0 / yScale, NetVips.Enums.Kernel.Lanczos3, centreConvention);
            }
            if (xScale < 1.0)
            {
                tileImage = tileImage.Reduceh(1.0 / xScale, NetVips.Enums.Kernel.Lanczos3, centreConvention);
            }

            // Any upsizing
            if (xScale > 1.0 || yScale > 1.0)
            {
                // Input displacement. For centre sampling, shift by 0.5 down and right.
                //double id = centreConvention ? 0.5 : 0.0;
                const double id = 0.0;

                // Floating point affine transformation
                using (Interpolate interpolate = Interpolate.NewFromName(Enums.Image.Interpolations.Bicubic))
                {
                    if (xScale > 1.0 && yScale > 1.0)
                    {
                        tileImage = tileImage.Affine(new[] { xScale, 0.0, 0.0, yScale }, interpolate, idx: id, idy: id,
                                                     extend: NetVips.Enums.Extend.Copy);
                    }
                    else if (xScale > 1.0)
                    {
                        tileImage = tileImage.Affine(new[] { xScale, 0.0, 0.0, 1.0 }, interpolate, idx: id, idy: id,
                                                     extend: NetVips.Enums.Extend.Copy);
                    }
                    else
                    {
                        tileImage = tileImage.Affine(new[] { 1.0, 0.0, 0.0, yScale }, interpolate, idx: id, idy: id,
                                                     extend: NetVips.Enums.Extend.Copy);
                    }
                }
            }

            // Add alpha channel if needed
            for (; tileImage.Bands < Enums.Image.Image.Bands;)
            {
                tileImage = tileImage.Bandjoin(255);
            }

            // Make a transparent image
            NetVips.Image outputImage;
            try
            {
                outputImage = NetVips.Image.Black(Enums.Image.Image.TileSize, Enums.Image.Image.TileSize)
                              .NewFromImage(0, 0, 0, 0);

                // Insert tile into output image
                outputImage = outputImage.Insert(tileImage, writePosX, writePosY);
                outputImage.Pngsave(outputTileFileInfo.FullName);
            }
            catch (Exception exception)
            {
                throw new ImageException(string.Format(Strings.UnableToCreateTile, tileX, tileY), exception);
            }

            //Check if tile was created successfuly.
            CheckHelper.CheckFile(outputTileFileInfo, true);

            tileImage.Dispose();
            outputImage.Dispose();
        }
예제 #37
0
 /// <summary>
 /// Creates and starts a new rotation animation.
 /// </summary>
 public RotationAnimation(Sprite controllee, float target, float duration, Interpolate <float> interpolate)
     : base(controllee, target, duration, interpolate)
 {
 }
예제 #38
0
    // Token: 0x06000451 RID: 1105 RVA: 0x00022E9C File Offset: 0x0002109C
    public static IEnumerable <Vector3> NewBezier(Interpolate.Function ease, Vector3[] points, int slices)
    {
        IEnumerable <float> steps = Interpolate.NewCounter(0, slices + 1, 1);

        return(Interpolate.NewBezier <Vector3>(ease, points, new Interpolate.ToVector3 <Vector3>(Interpolate.Identity), (float)(slices + 1), steps));
    }
예제 #39
0
 /// <summary>
 /// Creates and starts a new position animation.
 /// </summary>
 public PositionAnimation(Sprite controllee, Vector2 target, float duration, Interpolate <Vector2> interpolate)
     : base(controllee, target, duration, interpolate)
 {
 }
예제 #40
0
    /**
     * Returns sequence generator from start to end over duration using the
     * given easing function. The sequence is generated as it is accessed
     * using the Time.deltaTime to calculate the portion of duration that has
     * elapsed.
     */
    public static IEnumerator NewEase(Function ease, Vector3 start, Vector3 end, float duration)
    {
        IEnumerable <float> timer = Interpolate.NewTimer(duration);

        return(NewEase(ease, start, end, duration, timer));
    }
			public NetSync()
			{
				method = string.Empty;
				callers = NetworkCallers.Everyone;
				interpolate = Interpolate.True;
			}
예제 #42
0
    /**
     * Returns sequence generator from the first node to the last node over
     * duration time using the points in-between the first and last node
     * as control points of a bezier curve used to generate the interpolated points
     * in the sequence. If there are no control points (ie. only two nodes, first
     * and last) then this behaves exactly the same as NewEase(). In other words
     * a zero-degree bezier spline curve is just the easing method. The sequence
     * is generated as it is accessed using the Time.deltaTime to calculate the
     * portion of duration that has elapsed.
     */
    public static IEnumerable <Vector3> NewBezier(Function ease, Transform[] nodes, float duration)
    {
        IEnumerable <float> timer = Interpolate.NewTimer(duration);

        return(NewBezier <Transform>(ease, nodes, TransformDotPosition, duration, timer));
    }
예제 #43
0
 // Token: 0x06000454 RID: 1108 RVA: 0x00022FE9 File Offset: 0x000211E9
 public static IEnumerable <Vector3> NewCatmullRom(Transform[] nodes, int slices, bool loop)
 {
     return(Interpolate.NewCatmullRom <Transform>(nodes, new Interpolate.ToVector3 <Transform>(Interpolate.TransformDotPosition), slices, loop));
 }
예제 #44
0
 /// <summary>
 /// Creates and starts a new color animation.
 /// </summary>
 public ColorAnimation(Sprite controllee, Color target, float duration, Interpolate <Color> interpolate)
     : base(controllee, target, duration, interpolate)
 {
 }
예제 #45
0
 public static IInterpolation nuaturalSpline(double[] x, double[] y)
 {
     return(Interpolate.CubicSplineRobust(x, y));
 }
예제 #46
0
        private void DrawData()
        {
            if (chartData != null)
            {
                for (int i = 0; i < chartData.Length; i++)
                {
                    GameObject data = FindChild("data" + i.ToString());
                    GameObject fill = FindChild("fill" + i.ToString());

                    if (data == null)
                    {
                        fill = new GameObject("fill" + i.ToString());
                        fill.transform.SetParent(FindChild("FillContainer").transform);
                        RectTransform fillRTTmp = fill.AddComponent <RectTransform>();

                        data = new GameObject();
                        data.transform.name = "data" + i.ToString();
                        data.transform.SetParent(FindChild("DataContainer").transform);
                        data.AddComponent <UILineRenderer>();
                        data.GetComponent <RectTransform>().pivot      = chartRT.pivot;
                        data.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);

                        fillRTTmp.pivot      = -data.GetComponent <RectTransform>().pivot;
                        fillRTTmp.localScale = new Vector3(1, 1, 1);

                        RawImage fillRI = fill.AddComponent <RawImage>();
                        fillRI.material = new Material(fillMaterial);
                        fillRI.texture  = new Texture2D((int)(chartWidth - xMargin), 1);
                    }

                    RectTransform  dataRT   = data.GetComponent <RectTransform>();
                    UILineRenderer dataLine = data.GetComponent <UILineRenderer>();
                    dataLine.LineCaps      = showLineCaps;
                    dataRT.position        = chartRT.position - positionAdjustment3;
                    dataRT.sizeDelta       = chartRT.sizeDelta;
                    dataLine.color         = chartData[i].dataLineColor;
                    dataLine.LineThickness = chartData[i].dataLineWidth;
                    dataLine.sprite        = chartData[i].dataLineSprite;

                    RectTransform fillRT    = fill.GetComponent <RectTransform>();
                    RawImage      fillImage = fill.GetComponent <RawImage>();

                    fillRT.localPosition = dataRT.localPosition + new Vector3(xMargin, yMargin, 0);
                    fillRT.sizeDelta     = dataRT.sizeDelta - new Vector2(xMargin, yMargin);
                    List <Vector3> displayData = new List <Vector3>();
                    for (int j = 0; j < chartData[i].data.Length; j++)
                    {
                        float   x   = xMargin + (chartWidth - xMargin) * (chartData[i].data[j].x / (maxXValue - minXValue)) - (chartWidth - xMargin) * (minXValue / (maxXValue - minXValue));
                        float   y   = yMargin + (chartHeight - yMargin) * (chartData[i].data[j].y / (maxYValue - minYValue)) - (chartHeight - yMargin) * (minYValue / (maxYValue - minYValue));
                        Vector3 vec = new Vector3(x, y);
                        if (showMarkers)
                        {
                            DrawMarker("marker" + j + "_" + data.transform.name, chartData[i].data[j].y.ToString(), vec, chartData[i].markerSprite, chartData[i].markerSize, chartData[i].markerColor);
                        }
                        displayData.Add(vec);
                    }

                    if (smoothData)
                    {
                        IEnumerable <Vector3> interpolatedPoints = Interpolate.NewCatmullRom(displayData.ToArray(), dataSmoothing, false);
                        displayData = interpolatedPoints.ToList();
                    }

                    List <Vector2> finalPoints = new List <Vector2>();

                    for (int j = 0; j < displayData.Count; j++)
                    {
                        finalPoints.Add(displayData[j]);
                    }

                    if (fillAreaUnderLine && finalPoints.Count > 1)
                    {
                        List <Vector2> linePoints  = GetBresenhamLine(finalPoints);
                        Texture        fillTexture = fillImage.texture;
                        Color          underColor  = chartData[i].dataFillColor;

                        if (fillTexture.width != chartWidth - xMargin || fillTexture.height != 1)
                        {
                            fillTexture      = new Texture2D((int)chartWidth - (int)xMargin, 1);
                            fillRT.sizeDelta = new Vector2(chartWidth - xMargin, chartHeight - yMargin);
                        }

                        Color32[] colorArray         = new Color32[fillTexture.width];
                        int       linePointsIterator = 0;
                        int       colorArrayIterator = 0;

                        while (linePointsIterator < linePoints.Count && linePoints[linePointsIterator].x <= chartWidth - xMargin)
                        {
                            if (colorArrayIterator < colorArray.Length)
                            {
                                if (linePoints[linePointsIterator].x >= minXValue)
                                {
                                    float setY = linePoints[linePointsIterator].y;
                                    linePointsIterator++;
                                    setY -= yMargin;
                                    if (setY >= chartHeight - yMargin)
                                    {
                                        setY = chartHeight - yMargin;
                                    }
                                    else if (setY <= 0)
                                    {
                                        setY = 0;
                                    }

                                    float yValue   = setY / (chartHeight - yMargin);
                                    byte  a        = (byte)(yValue * 255);
                                    float reminder = yValue * 255 - a;
                                    byte  b        = (byte)(reminder * 255);
                                    colorArray[colorArrayIterator] = new Color32(a, b, 0, 0);
                                    colorArrayIterator++;
                                }
                                else
                                {
                                    linePointsIterator++;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }

                        //if (j < linePoints.Count && linePoints[j].x >= minXValue)
                        //{
                        //    if (linePoints[j].x >= minXValue)
                        //    {
                        //        float setY = linePoints[j].y;
                        //        setY -= yMargin;
                        //        if (setY >= chartHeight - yMargin)
                        //        {
                        //            setY = chartHeight - yMargin;
                        //        }
                        //        else if (setY <= 0)
                        //        {
                        //            setY = 0;
                        //        }

                        //        float yValue = setY / (chartHeight - yMargin);
                        //        byte a = (byte)(yValue * 255);
                        //        float reminder = yValue * 255 - a;
                        //        byte b = (byte)(reminder * 255);
                        //        colorArray[colorArrayIterator] = new Color32(a, b, 0, 0);
                        //        colorArrayIterator++;
                        //    }
                        //}
                        //else
                        //{
                        //    colorArray[colorArrayIterator] = new Color32(50, 0, 0, 0);
                        //    colorArrayIterator++;
                        //}


                        if (colorArray.Length == fillTexture.width && colorArray.Length > 2)
                        {
                            (fillTexture as Texture2D).SetPixels32(colorArray);
                            (fillTexture as Texture2D).Apply();
                            fillImage.texture = fillTexture;
                            fillImage.color   = underColor;
                            fillImage.material.SetTexture("_SecTex", chartData[i].dataFillTexture);
                            float shift = (minXValue - chartData[i].data[0].x) / (maxXValue - minXValue);
                            if (minXValue >= chartData[i].data[0].x)
                            {
                                shift = 0;
                            }
                            fillImage.material.SetFloat("_ShiftFactor", shift);
                        }
                    }
                    else
                    {
                        fillImage.color = Color.clear;
                    }
                    dataLine.Points = finalPoints.ToArray();
                }
                for (int i = 0; i < chartData.Length; i++)
                {
                    GameObject data = FindChild("data" + i.ToString());
                    GameObject fill = FindChild("fill" + i.ToString());
                    fill.transform.SetSiblingIndex(i);
                    data.transform.SetSiblingIndex(i);
                }
            }
            if (!showMarkers)
            {
                DeleteMarkers(0);
            }
        }
예제 #47
0
 /// <summary>
 /// Calculates the point on the Bezier curve at parameter t.
 /// </summary>
 /// <param name="t">The arc parameter t.</param>
 /// <returns>The Euclidean coordinates of the point on the curve at parameter t.</returns>
 protected override Vector2 getPointAt(float t)
 {
     return(Interpolate.Bezier(p0, p1, p2, p3, t));
 }
			public NetSync(Interpolate ignoreInterpolation)
			{
				interpolate = ignoreInterpolation;
			}
예제 #49
0
    public static void RotateBy(GameObject obj, Vector3 displacement, float duration, Interpolate.EaseType easingFunction, Action<GameObject> onComplete = null, bool world = false)
	{
		Vector3 destination = obj.transform.localRotation.eulerAngles + displacement;
		RotateTo(obj, destination, duration, easingFunction, onComplete, world);
	}
			public NetSync(string method, NetworkCallers callers, Interpolate ignoreInterpolation)
			{
				this.method = method;
				this.callers = callers;
				interpolate = ignoreInterpolation;
			}
예제 #51
0
        public static string[] TesteMathNetInterpolation()
        {
            double DataPoints = 1000;

            // Create the data to be fitted
            //var x = new List<double> { 1, 8, 16, 25, 30 }; // 5 pontos

            var x = new List <double> {
                1, 2, 3, 4, 16, 30
            };                                                           // 5 pontos
            //var x = new List<double> { 1, 2, 3, 4, 5, 10, 15, 20, 25, 30 }; // 10 pontos

            var y = new List <double> {
                8.33, 9.25, 9.16, 8.43, 9.5, 9.14
            };
            //var y = new List<double> { 8.33, 9.37, 8.47, 9.32, 9.11, 9.04, 8.93, 9.49, 8.29, 8.88
            //var y = new List<double> { 10.255, 10.064, 9.961, 9.945, 9.930 , 9.37, 9.65, 9.95, 10.40, 10.88};
            //var y = new List<double> { 3, 3, 3, 3, 15, 40, 50, 60, 70, 80 };

            //Lembre-se sempre de modificar as variacoes de X e Y da plotagem

            var xAkima  = new List <double>();
            var yAkima  = new List <double>();
            var xLinear = new List <double>();
            var yLinear = new List <double>();

            /// Interpolação Linear
            var linearInterpolation = Interpolate.Linear(x.ToArray(), y.ToArray());

            /// Interpolação Polinomial
            //var PolinomialInterpolation = new NevillePolynomialInterpolation(x.ToArray(), y.ToArray());

            /// Interpolação Akima Spline
            var akimaInterpolation = CubicSpline.InterpolateAkima(x.ToArray(), y.ToArray());


            var ep = 0;
            var a  = x.Min();
            var b  = x.Max();

            #region Akima Interpolation
            for (int i = 0; i <= DataPoints; i++)
            {
                /// nomalizedForm = (b−a) (x−min / max − min) + a
                /// b = valor maximo do intervalo que os numeros devem ficar
                /// a = valor minimo do intervalo que os numeros devem ficar
                /// max = valor maximo do intervalo atual
                /// min = valor minimo do intervalo atual
                double normalized  = ((b + ep) - (a - ep)) * (i / DataPoints) + (a - ep);
                var    yInterpoled = akimaInterpolation.Interpolate(normalized);
                xAkima.Add(normalized);
                yAkima.Add(yInterpoled);
            }
            #endregion

            #region Linear Interpolation
            for (int i = 0; i <= DataPoints; i++)
            {
                double normalized  = ((b + ep) - (a - ep)) * (i / DataPoints) + (a - ep);
                var    yInterpoled = linearInterpolation.Interpolate(normalized);
                xLinear.Add(normalized);
                yLinear.Add(yInterpoled);
            }
            #endregion

            var pointsX = new List <double>();
            var pointSY = new List <double>();

            List <Point> logLinear = new List <Point>();
            List <Point> logAkima  = new List <Point>();

            #region Normalizar pontos dos periodos
            for (int i = 1; i <= 30; i++)
            {
                var cY = akimaInterpolation.Interpolate(i);

                pointsX.Add(i);
                pointSY.Add(cY);
                logAkima.Add(new Point(i, cY));
            }
            for (int i = 1; i <= 30; i++)
            {
                var cY = linearInterpolation.Interpolate(i);

                pointsX.Add(i);
                pointSY.Add(cY);
                logLinear.Add(new Point(i, cY));
            }
            #endregion

            //---plotar solução-- -
            PlotSolution(NameMethod,
                         x.ToArray(), y.ToArray(),
                         xAkima.ToArray(), yAkima.ToArray(),
                         xLinear.ToArray(), yLinear.ToArray(),
                         @"..\..\" + NameMethod + ".png");

            string[] output = new string[] { "", "" };
            foreach (Point p in logAkima)
            {
                output[0] += p.ToString() + "\n";
            }
            foreach (Point p in logLinear)
            {
                output[1] += p.ToString() + "\n";
            }

            return(output);
        }