Inheritance: MonoBehaviour
コード例 #1
0
    void OnDrawGizmos()
    {
        Transform[] trans = GetTransforms();
        if (trans.Length < 2)
        {
            return;
        }

        SplineInterpolator interp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;

        SetupSplineInterpolator(interp, trans);
        interp.StartInterpolation(null, false, WrapMode);


        Vector3 prevPos = trans[0].position;

        for (int c = 1; c <= 100; c++)
        {
            float   currTime = c * Duration / 100;
            Vector3 currPos  = interp.GetHermiteAtTime(currTime);
            float   mag      = (currPos - prevPos).magnitude * 2;
            Gizmos.color = new Color(mag, 0, 0, 1);
            Gizmos.DrawLine(prevPos, currPos);
            prevPos = currPos;
        }
    }
コード例 #2
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++)
        {
            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);
        }
    }
コード例 #3
0
        private void findYEvent(object sender, EventArgs e) //обробник події пошуку Y (подія зміни данних у findXbox або змыни вибору methodPicker)
        {
            double x = 0;

            timeBox.Text      = "";
            iterationBox.Text = "";
            operationBox.Text = "";
            polyLabel.Text    = "";
            try
            {
                string text = findXbox.Text.Replace(".", ",");
                x = Convert.ToDouble(text);
                switch (methodPicker.SelectedIndex)
                {
                case 0:
                    var h = new NewtonInterpolator(data.ToList());
                    h.setPowerOfInterpolation(powerOfInterpolation);
                    findY(h, x);
                    break;

                case 1:
                    var s = new SplineInterpolator(data.ToList());
                    findY(s, x);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                foundYbox.Text = "Error!";
            }
        }
コード例 #4
0
ファイル: Trigger.cs プロジェクト: Zerophase/DyMProject
        protected override void Start()
        {
            splineController = Camera.main.GetComponent<SplineController>();
            splineInterpolator = Camera.main.GetComponent<SplineInterpolator>();

            base.Start();
        }
コード例 #5
0
    private void OnDrawGizmos()
    {
        if (Path.Length < 2)
        {
            return;
        }
        if (Array.Exists(Path, go => go == null))
        {
            return;
        }

        SplineInterpolator spline = SetupSpline(Path);

        Gizmos.color = Color.red;
        Gizmos.DrawRay(spline.GetHermiteAtTime(Testing), Vector3.up);

        Gizmos.color = Color.white;
        Vector3 lastPosition = spline.GetHermiteAtTime(0);
        int     nodeCount    = spline.GetNodeCount();

        if (nodeCount % 2 != 0)
        {
            nodeCount--;
        }                                        //test if the node count is even, if odd subtract one
        for (float t = _period; t <= nodeCount; t += _period)
        {
            Vector3 curretPosition = spline.GetHermiteAtTime(t);
            Gizmos.DrawLine(lastPosition, curretPosition);
            lastPosition = curretPosition;
        }
    }
コード例 #6
0
    public void Trigger()
    {
        if (triggered)
        {
            return;
        }

        triggered = true;

        if (points.Count < 2)
        {
            return;
        }

        //Set up our interpolator instance.
        this.m_splineInterpolator = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;

        SetupSplineInterpolator(this.m_splineInterpolator, points);
        this.m_splineInterpolator.StartInterpolation(null, false);

        //Get our LineRenderer instance, and draw the spline in play mode.
        LineRenderer lineRenderer = GetComponent<LineRenderer>();
        lineRenderer.SetVertexCount(vertexCount);

        for (int c = 0; c < vertexCount; c++)
        {
            float currTime = c * duration / vertexCount;
            Vector3 currPos = this.m_splineInterpolator.GetHermiteAtTime(currTime);

            lineRenderer.SetPosition(c, currPos);
        }

        //Begin movement along the spline.
        FollowSpline();
    }
コード例 #7
0
    // --------------------------------------------------------------------------------------------
    // UNITY CALLBACKS
    // --------------------------------------------------------------------------------------------

    void OnDrawGizmos()
    {
        //Debug.Log("drawing gizmos SplineController");
        SplineNode[] info = GetSplineNodes();
        if (info.Length < 2)
        {
            return;
        }

        SplineInterpolator interp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;

        SetupSplineInterpolator(interp, info);
        interp.StartInterpolation(null, null, null,         /* callbacks */
                                  false /* no rotations */, WrapMode);

        Vector3 prevPos = info[0].Point;
        float   endTime = GetDuration(info);

        Gizmos.color = Color.red;
        for (int c = 0; c <= 100; c++)
        {
            Vector3 currPos = interp.GetHermiteAtTime((float)c * endTime / 100.0f);

            /* USEFUL SANITY CHECK TO DO IN THE DEBUGGER*/
            if (float.IsNaN(currPos.x))
            {
                Debug.Log("NaN while drawing gizmos!!!!");                 // should never arrive here!
            }
            //float mag = (currPos-prevPos).magnitude * 2;
            //Gizmos.color = new Color(mag, 0, 0, 1);
            Gizmos.DrawLine(prevPos, currPos);

            prevPos = currPos;
        }
    }
コード例 #8
0
        void OnDrawGizmos()
        {
            if (ShowHelperSpline)
            {
                Transform[] trans = GetTransforms();
                if (trans.Length < 2)
                {
                    return;
                }
                SplineInterpolator interp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;
                SetupSplineInterpolator(interp, trans);
                interp.StartInterpolation(null, false, eWrapMode.ONCE);

                Vector3 prevPos = trans[0].position;

                for (int c = 0; c <= LineSoftnessFactor; c++)
                {
                    float   currTime = c * Duration / LineSoftnessFactor;
                    Vector3 currPos  = interp.GetHermiteAtTime(currTime);
                    if (c == 0)
                    {
                        currPos = trans[0].position;
                    }

                    Gizmos.color = HelperSplineColor;//new Color(mag, 0, 0, 1);
                    Gizmos.DrawLine(prevPos, currPos);
                    prevPos = currPos;
                }
            }
        }
コード例 #9
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);
	}
コード例 #10
0
    void OnDrawGizmos()
    {
        if (BiomeGenerator != null)
        {
            foreach (var s in BiomeGenerator.settlements)
            {
                foreach (var road in s.Roads)
                {
                    var nodes = road.Points.Select((x, i) => new SplineInterpolator.SplineNode(new Vector3(x.x, 0, x.y), (float)i / road.Points.Count, new Vector2(0, 1))).ToList();

                    SplineInterpolator interp = new SplineInterpolator(nodes);

                    Vector3 prevPos = interp.GetHermiteAtTime(0);
                    for (int c = 1; c <= 100; c++)
                    {
                        float   currTime = c * 1f / 100;
                        Vector3 currPos  = interp.GetHermiteAtTime(currTime);

                        var height = GetTerrainHeight(new Vector2(currPos.x, currPos.z));

                        currPos.y = height + 1;
                        float mag = (currPos - prevPos).magnitude * 2;

                        var cross = Vector3.Cross(currPos - prevPos, Vector3.up).normalized * 10;
                        Gizmos.DrawLine(prevPos - cross, currPos - cross);
                        Gizmos.DrawLine(prevPos + cross, currPos + cross);

                        prevPos = currPos;
                    }
                }
            }
        }
    }
コード例 #11
0
 // Use this for initialization
 void Start()
 {
     SetupData();
     SetupButtons();
     splineInterpolator         = GameObject.Find("Main Camera").GetComponent <SplineInterpolator>();
     splineController           = GameObject.Find("Main Camera").GetComponent <SplineController>();
     topNode                    = new GameObject("Side Menu");
     topNode.transform.position = new Vector3(-100.0f, -79.0f, 106.0f);
     topNode.transform.rotation = Quaternion.Euler(77.5f, 5.6f, 0);
 }
コード例 #12
0
    void Start()
    {
        mSplineInterp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;

        mTransforms = GetTransforms();

        if (HideOnExecute)
        {
            DisableTransforms();
        }
    }
コード例 #13
0
    void m_WheelModel_reinitialize()
    {
        m_wheel_mesh_sections_count = m_spokes_count * (m_wheel_mesh_additional_sections_count + 1);

        m_rim_base_sections = new Points3D[m_wheel_mesh_sections_count + 1];
        for (int i = 0; i < m_wheel_mesh_sections_count; ++i)
        {
            m_rim_base_sections[i] = new Points3D();
            m_rim_base_sections[i].addPoint(new Vector3D(0, -0.015, 0));
            m_rim_base_sections[i].addPoint(new Vector3D(-0.008, -0.015, 0));
            m_rim_base_sections[i].addPoint(new Vector3D(-0.008, -0.020, 0));
            m_rim_base_sections[i].addPoint(new Vector3D(-0.010, -0.020, 0));
            m_rim_base_sections[i].addPoint(new Vector3D(-0.010, -0.010, 0));
            m_rim_base_sections[i].addPoint(new Vector3D(-0.005, 0, 0));
            m_rim_base_sections[i].addPoint(new Vector3D(0.005, 0, 0));
            m_rim_base_sections[i].addPoint(new Vector3D(0.010, -0.010, 0));
            m_rim_base_sections[i].addPoint(new Vector3D(0.010, -0.020, 0));
            m_rim_base_sections[i].addPoint(new Vector3D(0.008, -0.020, 0));
            m_rim_base_sections[i].addPoint(new Vector3D(0.008, -0.015, 0));
            m_rim_base_sections[i].addPoint(new Vector3D(0, -0.015, 0));
        }

        int base_section_point_count = m_rim_base_sections[0].points_count;

        double[][] rough_wave_x    = new double [base_section_point_count][];
        double[][] rough_wave_y    = new double [base_section_point_count][];
        int        rough_min_range = (m_wheel_mesh_sections_count / m_spokes_count) * 3;
        int        rough_max_range = (m_wheel_mesh_sections_count / m_spokes_count) * 6;

        for (int i = 0; i < base_section_point_count; ++i)
        {
            rough_wave_x[i] = SplineInterpolator.generateRoughLoopedCurve(m_wheel_mesh_sections_count, rough_min_range, rough_max_range, m_rim_rough_size);
            rough_wave_y[i] = SplineInterpolator.generateRoughLoopedCurve(m_wheel_mesh_sections_count, rough_min_range, rough_max_range, m_rim_rough_size);
        }

        for (int i = 0; i < m_wheel_mesh_sections_count; ++i)
        {
            for (int j = 1; j < base_section_point_count - 1; ++j)   //exclude seam

            {
                m_rim_base_sections[i][j] += new Vector3D(rough_wave_x[j][i], rough_wave_y[j][i], 0);
            }
        }

        m_rim_base_sections[m_wheel_mesh_sections_count] = m_rim_base_sections[0].copy();

        m_WheelModel = new WheelModel(m_spokes_count, m_cross_count, m_rim_d, m_hub_d, m_axle_length, m_l_dish, m_r_dish);
        for (int i = 0; i < m_WheelModel.spokes_count; ++i)
        {
            m_WheelModel_spokes_rev90_offset[i] = UnityEngine.Random.Range(0, 4);
        }

        m_WheelModel_random_unbalance();
    }
コード例 #14
0
ファイル: TrackManager.cs プロジェクト: srajabi/Casketball
    void Start()
    {
        if(sc == null)
        {
            sc = this.GetComponent<SplineController>() as SplineController;
        }

        if(si == null)
        {
            si = this.GetComponent<SplineInterpolator>() as SplineInterpolator;
        }
    }
コード例 #15
0
 /// <summary>
 /// Starts the interpolation
 /// </summary>
 public void FollowSpline()
 {
     if (mTransforms.Length > 0)
     {
         SetupMovers(mTransforms);
         foreach (GameObject m in movers)
         {
             SplineInterpolator mSplineInterp = m.GetComponent <SplineInterpolator>();
             mSplineInterp.StartInterpolation(null, true, WrapMode);
         }
     }
 }
コード例 #16
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);
        }
    }
コード例 #17
0
	void Start()
	{
		mSplineInterp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;

		mSplineNodeInfo = GetSplineNodes();

		if (HideOnExecute)
			DisableNodeObjects();

		if (AutoStart)
			FollowSpline();
	}
コード例 #18
0
ファイル: FishBehavior.cs プロジェクト: Mqyee/MyDemo
 void Start()
 {
     splineC  = fishgroup.gameObject.GetComponent <SplineController>();
     splineI  = fishgroup.gameObject.GetComponent <SplineInterpolator>();
     nodes    = splineI.GetPoints();
     moveMode = splineI.GetState();
     isRotate = splineI.IsRotate();
     if (isfullpath == false)
     {
         delay = Random.Range(0, delay);
     }
 }
コード例 #19
0
    void Start()
    {
        if (sc == null)
        {
            sc = this.GetComponent <SplineController>() as SplineController;
        }

        if (si == null)
        {
            si = this.GetComponent <SplineInterpolator>() as SplineInterpolator;
        }
    }
コード例 #20
0
	void Start()
	{
		mSplineInterp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;

		mTransforms = GetTransforms();

		if (HideOnExecute)
			DisableTransforms();

		if (AutoStart)
			FollowSpline();
	}
コード例 #21
0
            public ProcessorResult <List <float> > AddWholePath(List <float> path, float spacing, PathPointLayout layout)
            {
                if (path.Count == 0)
                {
                    throw new Exception("Path has no points!");
                }

                SplineInterpolator = new DistanceBasedInterpolator(layout, spacing, splitCount, true, true);

                var iterpolatedPoints = SplineInterpolator.Add(true, true, new Spline(layout.ChannelMask, path), new Spline(layout.ChannelMask));

                return(iterpolatedPoints);
            }
コード例 #22
0
    void Start()
    {
        mSplineInterp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;

        mSplineInterp.mSplineController = this;

        Setup();

        if (AutoStart)
        {
            FollowSpline();
        }
    }
コード例 #23
0
        /// <summary>
        /// Transform accumulated pointer input to ink geometry
        /// </summary>
        /// <returns>Tuple containing added data (Item1) and predicted or preliminary data (Item2)</returns>
        /// <remarks>Passes accumulated path segment (from PathProducer) through remaining stages of
        /// the raster ink pipeline - Smoother, SplineProducer & SplineInterpolator</remarks>
        public ProcessorResult <List <float> > GetPath()
        {
            var smoothPath = mSmoothingFilter.Add(mPathSegment.IsFirst, mPathSegment.IsLast, mPathSegment.AccumulatedAddition, mPathSegment.LastPrediction);

            var spline = SplineProducer.Add(mPathSegment.IsFirst, mPathSegment.IsLast, smoothPath.Addition, smoothPath.Prediction);

            var points = SplineInterpolator.Add(mPathSegment.IsFirst, mPathSegment.IsLast, spline.Addition, spline.Prediction);

            mPathSegment.Reset();
            mPointerDataUpdateCount = 0;

            return(points);
        }
コード例 #24
0
    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);
        }
    }
コード例 #25
0
ファイル: CurvesEffect.cs プロジェクト: ywscr/Pinta
        private UnaryPixelOp MakeUop()
        {
            UnaryPixelOp op;

            byte[][] transferCurves;
            int      entries;

            switch (Data.Mode)
            {
            case ColorTransferMode.Rgb:
                UnaryPixelOps.ChannelCurve cc = new UnaryPixelOps.ChannelCurve();
                transferCurves = new byte[][] { cc.CurveR, cc.CurveG, cc.CurveB };
                entries        = 256;
                op             = cc;
                break;

            case ColorTransferMode.Luminosity:
                UnaryPixelOps.LuminosityCurve lc = new UnaryPixelOps.LuminosityCurve();
                transferCurves = new byte[][] { lc.Curve };
                entries        = 256;
                op             = lc;
                break;

            default:
                throw new InvalidEnumArgumentException();
            }


            int channels = transferCurves.Length;

            for (int channel = 0; channel < channels; channel++)
            {
                SortedList <int, int> channelControlPoints = Data.ControlPoints[channel];
                IList <int>           xa           = channelControlPoints.Keys;
                IList <int>           ya           = channelControlPoints.Values;
                SplineInterpolator    interpolator = new SplineInterpolator();
                int length = channelControlPoints.Count;

                for (int i = 0; i < length; i++)
                {
                    interpolator.Add(xa[i], ya[i]);
                }

                for (int i = 0; i < entries; i++)
                {
                    transferCurves[channel][i] = Utility.ClampToByte(interpolator.Interpolate(i));
                }
            }

            return(op);
        }
コード例 #26
0
        public Vector2 Do(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, float progress)
        {
            Dictionary <double, double> points = new Dictionary <double, double>
            {
                { p0.x, p0.y },
                { p1.x, p1.y },
                { p2.x, p2.y },
                { p3.x, p3.y }
            };

            SplineInterpolator splineInterpolator = new SplineInterpolator(points);

            return(splineInterpolator.GetValue(progress));
        }
コード例 #27
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);
        }
    }
コード例 #28
0
    void Start()
    {
        mSplineInterp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;

        mSplineNodeInfo = GetSplineNodes();

        if (HideOnExecute)
        {
            DisableNodeObjects();
        }

        if (AutoStart)
        {
            FollowSpline();
        }
    }
コード例 #29
0
    public void StartSpline()
    {
        mSplineInterp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;

        mTransforms = GetTransforms();

        if (HideOnExecute)
        {
            DisableTransforms();
        }

        if (AutoStart)
        {
            FollowSpline();
        }
    }
コード例 #30
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);
        }
    }
コード例 #31
0
    void OnDrawGizmos()
    {
        Transform[] trans = GetTransforms();
        if (trans.Length < 2)
        {
            return;
        }

        SplineInterpolator interp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;

        SetupSplineInterpolator(interp, trans);
        interp.StartInterpolation(null, eRotationMode.PATH_ANGLE, WrapMode);

        Vector3 prevPos = trans[0].position;
        //Quaternion prevRot = trans [0].rotation;
        int numberOfLines = 500;

        for (int c = 1; c <= numberOfLines; c++)
        {
            float      currTime = c * Duration / numberOfLines;
            Vector3    currPos  = interp.GetHermiteAtTime(currTime);
            Quaternion currRot  = interp.GetRotationAtTime(currTime);
            //float mag = (currPos-prevPos).magnitude * 2;
            Gizmos.color = new Color(0, 0, 1, 1);
            Gizmos.DrawLine(prevPos, currPos);

            Vector3 dP = currPos - prevPos;

            Transform _transform = new GameObject().transform;
            _transform.rotation = currRot;

            Quaternion armDir   = Quaternion.LookRotation(dP, _transform.up);
            Vector3    rightArm = armDir * Vector3.right;
            Vector3    leftArm  = armDir * Vector3.left;

            Gizmos.color = new Color(0, 1, 0, 1);

            Gizmos.DrawRay(currPos, rightArm);
            Gizmos.DrawRay(currPos, leftArm);

            prevPos = currPos;
            //prevRot = currRot;

            DestroyImmediate(_transform.gameObject);
        }
    }
コード例 #32
0
		private UnaryPixelOp MakeUop (SortedList<int, int>[] controlPoints, ColorTransferMode mode)
		{
			UnaryPixelOp op;
			byte[][] transferCurves;
			int entries;

			switch (mode) {
				case ColorTransferMode.Rgb:
					var cc = new ChannelCurveOp ();
					transferCurves = new byte[][] { cc.CurveR, cc.CurveG, cc.CurveB };
					entries = 256;
					op = cc;
					break;

				case ColorTransferMode.Luminosity:
					var lc = new LuminosityCurveOp ();
					transferCurves = new byte[][] { lc.Curve };
					entries = 256;
					op = lc;
					break;

				default:
					throw new InvalidEnumArgumentException ();
			}


			int channels = transferCurves.Length;

			for (int channel = 0; channel < channels; channel++) {
				var channelControlPoints = controlPoints[channel];
				var xa = channelControlPoints.Keys;
				var ya = channelControlPoints.Values;
				SplineInterpolator interpolator = new SplineInterpolator ();
				int length = channelControlPoints.Count;

				for (int i = 0; i < length; i++) {
					interpolator.Add (xa[i], ya[i]);
				}

				for (int i = 0; i < entries; i++) {
					transferCurves[channel][i] = Utility.ClampToByte (interpolator.Interpolate (i));
				}
			}

			return op;
		}
コード例 #33
0
    void Start()
    {
        Duration      = CoasterBuilder.buildtimer / coasterspeed;;
        mSplineInterp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;

        mTransforms = GetTransforms();

        if (HideOnExecute)
        {
            DisableTransforms();
        }

        if (AutoStart)
        {
            FollowSpline();
        }
    }
コード例 #34
0
    void Start()
    {
        mSplineInterp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;

        //mTransforms = GetTransforms();

        //Hide Soline Roots
        if (HideOnExecute)
        {
            DisableTransforms();
        }

        if (AutoStart)
        {
            FollowSpline();
        }
    }
コード例 #35
0
    void OnEnable()
    {
        mSplineInterp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;

        mTransforms = GetTransforms();

        if (HideOnExecute)
        {
            DisableTransforms();
        }

        if (AutoStart)
        {
            FollowSpline();
        }

        SavePathwaPos();
    }
コード例 #36
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);
            }
        }
    void OnDrawGizmos()
    {
        Transform[] trans = GetTransforms();

        if (trans == null)
        {
            return;
        }

        if (trans.Length < 2)
        {
            return;
        }

        // This was semi-incorrectly changed in porting this to Unity's C#:
        // SplineInterpolator interp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;
        // that's not entirely correct; we need a *new* SplineInterpolator to draw the gizmos with.
        // The one that we have as a Component is the one used in game itself.
        // trying to use the same one for both means that the object just twitches in place,
        // since it then gets reset continuously by the gizmo drawing.
        // we might need to make SplineInterpolator into something other than a Monobehaviour --
        // or create an empty gameobject to AddComponent() it to (only in Editor)  --Matt M.
        GameObject         GizmoSplineInterpolator = new GameObject();
        SplineInterpolator interp = (SplineInterpolator)GizmoSplineInterpolator.AddComponent(typeof(SplineInterpolator));

        SetupSplineInterpolator(interp, trans);
        interp.StartInterpolation(null, false, WrapMode);


        Vector3 prevPos = trans[0].position;

        for (int c = 1; c <= 100; c++)
        {
            float   currTime = c * Duration / 100;
            Vector3 currPos  = interp.GetHermiteAtTime(currTime);
            //Debug.Log("currPos = " + currPos + " at " + currTime);
            float mag = (currPos - prevPos).magnitude * 2;
            Gizmos.color = new Color(mag, 0, 0, 1);
            Gizmos.DrawLine(prevPos, currPos);
            prevPos = currPos;
        }

        DestroyImmediate(GizmoSplineInterpolator);
    }
コード例 #38
0
ファイル: SplineController.cs プロジェクト: BBJV/camachi
    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);
    }
コード例 #39
0
        private UnaryPixelOp MakeUop()
        {
            UnaryPixelOp uopRet;
            byte[][] transferCurves;
            int entries;

            switch (colorTransferMode)
            {
                case ColorTransferMode.Rgb:
                    UnaryPixelOps.ChannelCurve cc = new UnaryPixelOps.ChannelCurve();
                    transferCurves = new byte[][] { cc.CurveR, cc.CurveG, cc.CurveB };
                    entries = 256;
                    uopRet = cc;
                    break;

                case ColorTransferMode.Luminosity:
                    UnaryPixelOps.LuminosityCurve lc = new UnaryPixelOps.LuminosityCurve();
                    transferCurves = new byte[][] { lc.Curve };
                    entries = 256;
                    uopRet = lc;
                    break;

                default:
                    throw new InvalidEnumArgumentException();
            }

            
            int channels = transferCurves.Length;

            for (int channel = 0; channel < channels; ++channel)
            {
                SortedList<int, int> channelControlPoints = controlPoints[channel];
                IList<int> xa = channelControlPoints.Keys;
                IList<int> ya = channelControlPoints.Values;
                SplineInterpolator interpolator = new SplineInterpolator();
                int length = channelControlPoints.Count;

                for (int i = 0; i < length; ++i)
                {
                    interpolator.Add(xa[i], ya[i]);
                }

                for (int i = 0; i < entries; ++i)
                {
                    transferCurves[channel][i] = Utility.ClampToByte(interpolator.Interpolate(i));
                }
            }

            return uopRet;
        }
コード例 #40
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);
    }
コード例 #41
0
ファイル: WanderingPlanet.cs プロジェクト: namesake08/orbit
        //public void OnRenderObject()
        //{
        //        //Material line_m = LineCreator.CreateLineMaterial();
        //        Material line_m = new Material(
        //         @"Shader ""Lines/Colored Blended"" {
        //             SubShader {
        //                 Tags { ""RenderType""=""Opaque"" }
        //                 Pass {
        //                     ZWrite On
        //                     ZTest LEqual
        //                     Cull Off
        //                     Fog { Mode Off }
        //                     BindChannels {
        //                         Bind ""vertex"", vertex Bind ""color"", color
        //                     }
        //                 }
        //             }
        //         }");
        //        line_m.SetPass(0);
        //        if (mTransforms.Length < 2)
        //            return;
        //        GL.PushMatrix();
        //        GL.Begin(GL.LINES);
        //        Vector3 prevPos = _splinePoints[0];
        //        for (int c = 1; c <= 100; c++)
        //        {
        //            Vector3 currPos = _splinePoints[c];
        //            GL.Color(new Color(0.1f, 0.1f, 0.1f, 0.5f));
        //            GL.Vertex3(prevPos.x, prevPos.y, prevPos.z);
        //            float angle = MathHelper.AngleBetween(currPos, prevPos);
        //            float dist = Vector3.Distance(currPos, prevPos);
        //            GL.Vertex3(currPos.x + dist/2 * Mathf.Cos(angle), currPos.y + dist/2 * Mathf.Sin(angle), currPos.z);
        //            prevPos = currPos;
        //        }
        //        GL.End();
        //        GL.PopMatrix();
        //}
        void Start()
        {
            _trail = Instantiate(GameValues.SplineLineTrail);

            _trail.transform.parent = transform;
            _trail.transform.localPosition = new Vector3(0, 0, -0.1f);

            mSplineInterp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;

            mTransforms = GetTransforms();

            if (HideOnExecute)
                DisableTransforms();

            if (AutoStart)
                FollowSpline();

            PerformLineRenderer();
        }
コード例 #42
0
    void Start()
    {
        mSplineInterp = GetComponent<SplineInterpolator>();

        mTransforms = GetTransforms();

        var line = GetComponent<LineRenderer>();

        if (line != null && line.enabled)
        {
            if (mTransforms.Length > 2)
            {
                line.SetVertexCount(100);

                SplineInterpolator interp = GetComponent<SplineInterpolator>();

                SetupSplineInterpolator(interp, mTransforms);
                interp.StartInterpolation(null, false, WrapMode);

                for (int c = 0; c <= 100; c++)
                {
                    float currTime = c * Duration / 100;
                    Vector3 currPos = interp.GetHermiteAtTime(currTime);

                    line.SetPosition(c, currPos);
                }
            }
        }

        if (HideOnExecute)
            DisableTransforms();

        if (AutoStart)
            FollowSpline();
    }
コード例 #43
0
	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);
	}
コード例 #44
0
 protected override void SetupSplineInterpolator(SplineInterpolator interp, SplineNode[] ninfo)
 {
     Speed = Speeds[_SplineToExecute];
     base.SetupSplineInterpolator (interp, ninfo);
 }
コード例 #45
0
    void OnEnable()
    {
        mSplineInterp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;

        //mTransforms = GetTransforms();
        mTransforms = GameObject.Find ("PointManager").GetComponent<PointTest> ().ReturnPointsTable (3);

        if (HideOnExecute)
            DisableTransforms();

        if (AutoStart)
            FollowSpline();
    }
コード例 #46
0
ファイル: WanderingPlanet.cs プロジェクト: ai-ry/orbit
        void Start()
        {
            InitTrail();

            mSplineInterp = GetComponent(typeof(SplineInterpolator)) as SplineInterpolator;

            mTransforms = GetTransforms();

            if (HideOnExecute)
                DisableTransforms();

            if (AutoStart)
                FollowSpline();

            PerformLineRenderer();
        }
コード例 #47
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));
        }
    }
コード例 #48
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;
    }