AddPoint() 공개 메소드

public AddPoint ( string name, Vector3 pos, Quaternion quat, float timeInSeconds, float timeStop, Vector2 easeInOut ) : void
name string
pos Vector3
quat Quaternion
timeInSeconds float
timeStop float
easeInOut Vector2
리턴 void
예제 #1
0
	void SetupSplineInterpolator(SplineInterpolator interp, Transform[] trans)
	{
		interp.Reset();

		float step = (AutoClose) ? Duration / trans.Length :
			Duration / (trans.Length - 1);

		int c;
		for (c = 0; c < trans.Length; c++)
		{
			if (OrientationMode == eOrientationModeVineeth.NODE)
			{
				interp.AddPoint(trans[c].position, trans[c].rotation, step * c, new Vector2(0, 1));
			}
			else if (OrientationMode == eOrientationModeVineeth.TANGENT)
			{
				Quaternion rot;
				if (c != trans.Length - 1)
					rot = Quaternion.LookRotation(trans[c + 1].position - trans[c].position, trans[c].up);
				else if (AutoClose)
					rot = Quaternion.LookRotation(trans[0].position - trans[c].position, trans[c].up);
				else
					rot = trans[c].rotation;

				interp.AddPoint(trans[c].position, rot, step * c, new Vector2(0, 1));
			}
		}

		if (AutoClose)
			interp.SetAutoCloseMode(step * c);
	}
예제 #2
0
    void SetupSplineInterpolator(SplineInterpolator interp, Transform[] trans, int indexToStart)
    {
        interp.Reset();

        float step = (AutoClose) ? Duration / trans.Length :
                     Duration / (trans.Length - 1);

        for (int c = 0; c < trans.Length; c++)
        {
            int which = c;
            if (Reverse)
            {
                which = indexToStart - c;
                if (which < 0)
                {
                    which += trans.Length;
                }
            }
            else
            {
                which = (c + indexToStart) % trans.Length;
            }
            if (OrientationMode == eOrientationMode.NODE)
            {
                interp.AddPoint(trans[which].position, trans[which].rotation, step * c, new Vector2(0, 1));
            }

            // WILL NOT USE THIS, CAN LEAVE BROKEN
            else if (OrientationMode == eOrientationMode.TANGENT)
            {
                Quaternion rot;
                if (c != trans.Length - 1)
                {
                    rot = Quaternion.LookRotation(trans[c + 1].position - trans[c].position, trans[c].up);
                }
                else if (AutoClose)
                {
                    rot = Quaternion.LookRotation(trans[0].position - trans[c].position, trans[c].up);
                }
                else
                {
                    rot = trans[c].rotation;
                }

                interp.AddPoint(trans[c].position, rot, step * c, new Vector2(0, 1));
            }
        }

        if (AutoClose)
        {
            interp.SetAutoCloseMode(step * trans.Length);
        }
    }
    void SetupSplineInterpolator(SplineInterpolator interp, SplineNode[] ninfo)
    {
        interp.Reset();

        float currTime = 0;

        for (uint c = 0; c < ninfo.Length; c++)
        {
            if (OrientationMode == eOrientationMode.NODE)
            {
                interp.AddPoint(ninfo[c].Name, ninfo[c].Point,
                                ninfo[c].Rot,
                                currTime, ninfo[c].BreakTime,
                                new Vector2(0, 1));
            }
            else if (OrientationMode == eOrientationMode.TANGENT)
            {
                Quaternion rot;
                Vector3    up = ninfo[c].Rot * Vector3.up;

                if (c != ninfo.Length - 1)                                                  // is c the last point?
                {
                    rot = Quaternion.LookRotation(ninfo[c + 1].Point - ninfo[c].Point, up); // no, we can use c+1
                }
                else if (AutoClose)
                {
                    rot = Quaternion.LookRotation(ninfo[0].Point - ninfo[c].Point, up);
                }
                else
                {
                    rot = ninfo[c].Rot;
                }

                interp.AddPoint(ninfo[c].Name, ninfo[c].Point, rot,
                                currTime, ninfo[c].BreakTime,
                                new Vector2(0, 1));
            }

            // when ninfo[i].StopHereForSecs == 0, then each node of the spline is reached at
            // Time.time == timePerNode * c (so that last node is reached when Time.time == TimeBetweenAdjacentNodes).
            // However, when ninfo[i].StopHereForSecs > 0, then the arrival time of node (i+1)-th needs
            // to account for the stop time of node i-th
            TimeBetweenAdjacentNodes = 1.0f / (ninfo.Length - 1);
            currTime += TimeBetweenAdjacentNodes + ninfo[c].BreakTime;
        }

        if (AutoClose)
        {
            interp.SetAutoCloseMode(currTime);
        }
    }
    void SetupSplineInterpolator(SplineInterpolator interp, Transform[] trans)
    {
        interp.Reset();

        float step = (AutoClose) ? DURATION / trans.Length :
                     DURATION / (trans.Length - 1);

        int c;

        for (c = 0; c < trans.Length; c++)
        {
            Quaternion rot;
            if (c != trans.Length - 1)
            {
                rot = Quaternion.LookRotation(trans[c + 1].position - trans[c].position, trans[c].up);
            }
            else if (AutoClose)
            {
                rot = Quaternion.LookRotation(trans[0].position - trans[c].position, trans[c].up);
            }
            else
            {
                rot = trans[c].rotation;
            }

            interp.AddPoint(trans[c].position, rot, step * c, new Vector2(0, 1));
        }

        if (AutoClose)
        {
            interp.SetAutoCloseMode(step * c);
        }
    }
예제 #5
0
    void SetupSplineInterpolator(SplineInterpolator interp, Transform[] trans)
    {
        interp.Reset();

        float step = (AutoClose) ? Duration / trans.Length :
                     Duration / (trans.Length - 1);

        int c;

        for (c = 0; c < trans.Length; c++)
        {
            if (OrientationMode == eOrientationMode.NODE)
            {
                interp.AddPoint(trans[c].position, trans[c].rotation, step * c, new Vector2(0, 1));
            }
            else if (OrientationMode == eOrientationMode.TANGENT)
            {
                Quaternion rot;
                if (c != trans.Length - 1)
                {
                    if (trans[c + 1].position - trans[c].position != Vector3.zero)
                    {
                        rot = Quaternion.LookRotation(trans[c + 1].position - trans[c].position, trans[c].up);
                    }
                    else
                    {
                        rot = Quaternion.identity;
                    }
                }
                else if (AutoClose)
                {
                    rot = Quaternion.LookRotation(trans[0].position - trans[c].position, trans[c].up);
                }
                else
                {
                    rot = trans[c].rotation;
                }

                interp.AddPoint(trans[c].position, rot, step * c, new Vector2(0, 1));
            }
        }

        if (AutoClose)
        {
            interp.SetAutoCloseMode(step * c);
        }
    }
    void SetupSplineInterpolator(SplineInterpolator interp, Transform[] trans)
    {
        //Debug.Log(Time.realtimeSinceStartup + " " + this + " SetupSplineInterpolator " + interp + " " + trans);
        interp.Reset();

        float step = (AutoClose) ? Duration / trans.Length :
                     Duration / (trans.Length - 1);

        //Debug.Log(Time.realtimeSinceStartup + " " + this + " step = " + step);
        int c;

        for (c = 0; c < trans.Length; c++)
        {
            if (OrientationMode == eOrientationMode.NODE)
            {
                interp.AddPoint(trans[c].position, trans[c].rotation, step * c, new Vector2(0, 1));
            }
            else if (OrientationMode == eOrientationMode.TANGENT)
            {
                Quaternion rot;
                if (c != trans.Length - 1)
                {
                    rot = Quaternion.LookRotation(trans[c + 1].position - trans[c].position, trans[c].up);
                }
                else if (AutoClose)
                {
                    rot = Quaternion.LookRotation(trans[0].position - trans[c].position, trans[c].up);
                }
                else
                {
                    rot = trans[c].rotation;
                }

                interp.AddPoint(trans[c].position, rot, step * c, new Vector2(0, 1));
            }
        }

        if (AutoClose)
        {
            interp.SetAutoCloseMode(step * c);
        }
    }
예제 #7
0
    void SetupSplineInterpolator(SplineInterpolator interp, Transform[] trans)
    {
        interp.Reset();

        int c;

        for (c = 0; c < trans.Length; c++)
        {
            interp.AddPoint(trans[c].position, trans[c].rotation, c, new Vector2(0, 1));
        }

        if (AutoClose)
        {
            interp.SetAutoCloseMode(c);
        }
    }
예제 #8
0
        //Drawn Spline for WayPoints
        void SetupSplineInterpolator(SplineInterpolator interp, Transform[] trans)
        {
            interp.Reset();

            float step = (ClosedRacingLine) ? (Duration / trans.Length) : Duration / (trans.Length - 1);

            int c;

            for (c = 0; c < trans.Length; c++)
            {
                interp.AddPoint(trans[c].position, trans[c].rotation, step * c, new Vector2(0, 1));
            }

            if (ClosedRacingLine)
            {
                interp.SetAutoCloseMode(step * c);
            }
        }
예제 #9
0
    private SplineInterpolator SetupSpline(IEnumerable <GameObject> gos)
    {
        //converting gameobjects to a list of transforms
        List <Transform> transforms = new List <Transform>();

        foreach (GameObject go in gos)
        {
            transforms.Add(go.transform);
        }

        //setup spline
        SplineInterpolator interp = transform.GetComponent <SplineInterpolator>();

        interp.Reset();
        for (int c = 0; c < transforms.Count; c++)
        {
            interp.AddPoint(transforms[c].position, transforms[c].rotation, c, new Vector2(0, 1));
        }
        interp.StartInterpolation(null, false, eWrapMode.ONCE);
        return(interp);
    }
예제 #10
0
    protected virtual void ConstructCurve(SplineInterpolator interp, SplineNode[] nInfo)
    {
        if (Speed <= 0 && nInfo.Length < 3) return;
        float totalLength = 0;
        float[] curveLengths = new float[nInfo.Length];
        float[] nodeArrivalTimes = new float[nInfo.Length];
        float currTime = 0;
        uint c = 1;
        bool pathEnded = false;

        //Cache the tag so we can reset it after we have calculated how fast the object should move.
        string actualTag = gameObject.tag;

        //Preserve the original position so that the object doesn't get deleted due to the simulation.
        Vector3 originalPosition = gameObject.transform.position;

        gameObject.tag = "Simulation";
        //Swap splines just in case we use mSplineInterp elsewhere.
        interp.StartInterpolation(

        //On Path End.
        () => {
            //Debug.Log("On Path Ended");
            pathEnded = true;

        },
        //On Node Arrival.
        (int idxArrival, SplineNode nodeArrival) => {
            curveLengths[c] = mTotalSegmentSpeed;
            //Debug.Log("SplineController: mTotalSegmentSpeed is " + mTotalSegmentSpeed + "from node " + nInfo[idxArrival - 1].Point + " to " + nodeArrival.Point);
            totalLength += mTotalSegmentSpeed;
            mTotalSegmentSpeed = 0;
            ++c;
        },
        //On Node Callback
        (int idxLeavingSpline, SplineNode OnNodeArrivalCallback) => {
            //Debug.Log("On Node callback: " + idxLeavingSpline);

        }, false, eWrapMode.ONCE);

        //Starts the Simulation.
        float deltaTime = 0.00005f;
        float currentTime = 0f;
        while (!pathEnded) {
            interp.Update(currentTime);
            mTotalSegmentSpeed += mSplineInterp.DistanceTraveled;
            currentTime += deltaTime;
        }
        //Debug.Log("SplineController: totalLength is " + totalLength);
        interp.Clear();

        gameObject.transform.position = originalPosition;
        //From that, evaluate how much distance between each node makes up the curve and scale that time to be the break time.
        float totalTime = GetDuration(nInfo);
        //Debug.Log("SplineController: totalTime is " + totalTime);

        float averageSpeed = totalLength / totalTime;

        float timeToEnd = 0;
        float speedMultiplier = 0;
        for (int i = 0; i < curveLengths.Length; i++)
        {
            float hermiteLengthToEvaluate = curveLengths[i];
            //Debug.Log("SplineController: hermiteLengthToEvaluate is " + hermiteLengthToEvaluate + " and the node is " + nInfo[i].Name);
            if (hermiteLengthToEvaluate > 0) {
                speedMultiplier = (hermiteLengthToEvaluate / totalLength) * (1 / Speed);
                timeToEnd = totalTime * speedMultiplier;
                //Debug.Log("SplineController: timeToEnd is " + timeToEnd);
            }

            interp.AddPoint(nInfo[i].Name, nInfo[i].Point,
                            nInfo[i].Rot,
                            timeToEnd + currTime, 0,
                            new Vector2(0, 1));
            currTime += timeToEnd;
        }
        gameObject.tag = actualTag;
    }
예제 #11
0
    protected virtual void SetupSplineInterpolator(SplineInterpolator interp, SplineNode[] ninfo)
    {
        interp.Clear();

        float currTime = 0;

        List<SplineNode> nInfoAsList = new List<SplineNode>(ninfo);

        for (uint c = 0; c < ninfo.Length; c++)
        {
            if (OrientationMode == eOrientationMode.NODE)
            {
                interp.AddPoint(ninfo[c].Name, ninfo[c].Point,
                                ninfo[c].Rot,
                                currTime, ninfo[c].BreakTime,
                                new Vector2(0, 1));
            }
            else if (OrientationMode == eOrientationMode.TANGENT)
            {
                Quaternion rot;
                Vector3 up = ninfo[c].Rot * Vector3.up;

                if (c != ninfo.Length - 1)		// is c the last point?
                    rot = Quaternion.LookRotation(ninfo[c+1].Point - ninfo[c].Point, up);	// no, we can use c+1
                else if (AutoClose)
                    rot = Quaternion.LookRotation(ninfo[0].Point - ninfo[c].Point, up);
                else
                    rot = ninfo[c].Rot;

                interp.AddPoint(ninfo[c].Name, ninfo[c].Point, rot,
                                currTime, ninfo[c].BreakTime,
                                new Vector2(0, 1));
            }

            // when ninfo[i].StopHereForSecs == 0, then each node of the spline is reached at
            // Time.time == timePerNode * c (so that last node is reached when Time.time == TimeBetweenAdjacentNodes).
            // However, when ninfo[i].StopHereForSecs > 0, then the arrival time of node (i+1)-th needs
            // to account for the stop time of node i-th
            currTime += ninfo[c].BreakTime;

            if ((Speed <= 0 || Application.isEditor) && !Application.isPlaying) {
                currTime += TimeBetweenAdjacentNodes;
            }
        }

        //Debug.Log("SplineController, there are " + eOrientationMode.NODE + " nodes currently");

        //Normalizes the speed by adjusting which times our spline interpolator
        //needs to arrive at a particular node before they are added to the actual
        //interpolator.
        if (Speed > 0 && Application.isPlaying) {
            ConstructCurve(interp, ninfo);
        }

        if (AutoClose)
            interp.SetAutoCloseMode(currTime);
    }
예제 #12
0
    void SetupSplineInterpolator(SplineInterpolator interp, Transform[] trans)
    {
        //Debug.Log(Time.realtimeSinceStartup + " " + this + " SetupSplineInterpolator " + interp + " " + trans);
        interp.Reset();

        float step = (AutoClose) ? Duration / trans.Length :
            Duration / (trans.Length - 1);

        //Debug.Log(Time.realtimeSinceStartup + " " + this + " step = " + step);
        int c;
        for (c = 0; c < trans.Length; c++)
        {
            if (OrientationMode == eOrientationMode.NODE)
            {
                interp.AddPoint(trans[c].position, trans[c].rotation, step * c, new Vector2(0, 1));
            }
            else if (OrientationMode == eOrientationMode.TANGENT)
            {
                Quaternion rot;
                if (c != trans.Length - 1)
                    rot = Quaternion.LookRotation(trans[c + 1].position - trans[c].position, trans[c].up);
                else if (AutoClose)
                    rot = Quaternion.LookRotation(trans[0].position - trans[c].position, trans[c].up);
                else
                    rot = trans[c].rotation;

                interp.AddPoint(trans[c].position, rot, step * c, new Vector2(0, 1));
            }
        }

        if (AutoClose)
            interp.SetAutoCloseMode(step * c);
    }
    void SetupSplineInterpolator(SplineInterpolator interp, Transform[] trans)
    {
        interp.Reset();
        float Step;

        int   Counter;
        float TotalLength = 0;

        float[] DistanceList = new float[trans.Length];

        if (AutoClose)
        {
            for (int i = 0; i < trans.Length; i++)
            {
                float Distance;

                if (i == trans.Length - 1)
                {
                    Distance     = Vector3.Distance(trans[i].position, trans[0].position);
                    TotalLength += Distance;
                }
                else
                {
                    Distance     = Vector3.Distance(trans[i].position, trans[i + 1].position);
                    TotalLength += Distance;
                }
                DistanceList[i] = Distance;
            }
        }
        else
        {
            for (int i = 0; i < trans.Length - 1; i++)
            {
                float Distance;
                Distance        = Vector3.Distance(trans[i].position, trans[i + 1].position);
                TotalLength    += Distance;
                DistanceList[i] = Distance;
            }
        }

        float CurrentDis = 0;

        for (Counter = 0; Counter < trans.Length; Counter++)
        {
            Quaternion rot;
            if (Counter != trans.Length - 1)
            {
                rot = Quaternion.LookRotation(trans[Counter + 1].position - trans[Counter].position, trans[Counter].up);
            }
            else if (AutoClose)
            {
                rot = Quaternion.LookRotation(trans[0].position - trans[Counter].position, trans[Counter].up);
            }
            else
            {
                rot = trans[Counter].rotation;
            }

            Step = CurrentDis / TotalLength / STEP_DIVIDER;

            interp.AddPoint(trans[Counter].position, rot, Step, new Vector2(0, 1));
            CurrentDis = CurrentDis + DistanceList[Counter];
        }



        if (AutoClose)
        {
            interp.SetAutoCloseMode(CurrentDis / TotalLength / STEP_DIVIDER);
        }
    }
	void SetupSplineInterpolator(SplineInterpolator interp, SplineNode[] ninfo)
	{
		interp.Reset();
		
		float currTime = 0;
		for (uint c = 0; c < ninfo.Length; c++)
		{
			if (OrientationMode == eOrientationMode.NODE)
			{
				interp.AddPoint(ninfo[c].Name, ninfo[c].Point, 
								ninfo[c].Rot, 
								currTime, ninfo[c].BreakTime, 
								new Vector2(0, 1));
			}
			else if (OrientationMode == eOrientationMode.TANGENT)
			{
				Quaternion rot;
				Vector3 up = ninfo[c].Rot * Vector3.up;
				
				if (c != ninfo.Length - 1)		// is c the last point?
					rot = Quaternion.LookRotation(ninfo[c+1].Point - ninfo[c].Point, up);	// no, we can use c+1
				else if (AutoClose)
					rot = Quaternion.LookRotation(ninfo[0].Point - ninfo[c].Point, up);
				else
					rot = ninfo[c].Rot;

				interp.AddPoint(ninfo[c].Name, ninfo[c].Point, rot, 
								currTime, ninfo[c].BreakTime, 
								new Vector2(0, 1));
			}
			
			// when ninfo[i].StopHereForSecs == 0, then each node of the spline is reached at
			// Time.time == timePerNode * c (so that last node is reached when Time.time == TimeBetweenAdjacentNodes).
			// However, when ninfo[i].StopHereForSecs > 0, then the arrival time of node (i+1)-th needs
			// to account for the stop time of node i-th
		    TimeBetweenAdjacentNodes = 1.0f / (ninfo.Length - 1);
			currTime += TimeBetweenAdjacentNodes + ninfo[c].BreakTime;
		}

		if (AutoClose)
			interp.SetAutoCloseMode(currTime);
	}
예제 #15
0
    void SetupSplineInterpolator(SplineInterpolator interp, List<GameObject> gameObjects)
    {
        interp.Reset(splineObject);

        float step = duration / (gameObjects.Count - 1);

        for (int i = 0; i < gameObjects.Count; i++)
        {
            Transform trans = gameObjects[i].transform;
            Vector3 offset = new Vector3(trans.position.x, trans.position.y + 0.4f, trans.position.z);
            interp.AddPoint(gameObjects[i], offset, trans.rotation, step * i, new Vector2(0, 1));
        }
    }