Ejemplo n.º 1
0
        public Vector3 GetDirection(float inPercent, Curve inSegmentCurve = Curve.Linear)
        {
            if (m_Dirty)
            {
                Process();
            }

            SplineSegment segment;

            GetSegment(inPercent, out segment);

            float p1 = inSegmentCurve.Evaluate(segment.Interpolation);
            float p2 = p1 + SplineMath.LookAhead;

            Vector3 v1 = SplineMath.Hermite(m_Vertices[segment.VertexA].OutTangent, m_Vertices[segment.VertexA].Point,
                                            m_Vertices[segment.VertexB].Point, m_Vertices[segment.VertexB].InTangent,
                                            p1);
            Vector3 v2 = SplineMath.Hermite(m_Vertices[segment.VertexA].OutTangent, m_Vertices[segment.VertexA].Point,
                                            m_Vertices[segment.VertexB].Point, m_Vertices[segment.VertexB].InTangent,
                                            p2);

            Vector3 dir = new Vector3(
                v2.x - v1.x,
                v2.y - v1.y,
                v2.z - v1.z
                );

            dir.Normalize();
            return(dir);
        }
Ejemplo n.º 2
0
        public Vector3 GetPoint(float inPercent, Curve inSegmentCurve = Curve.Linear)
        {
            if (m_Dirty)
            {
                Process();
            }

            return(SplineMath.Quadratic(m_Start, m_Control, m_End, inSegmentCurve.Evaluate(inPercent)));
        }
Ejemplo n.º 3
0
        public bool Process()
        {
            if (!m_Dirty)
            {
                return(false);
            }

            m_Distance = Vector3.Distance(m_Start, m_End);

            float preciseDist = 0;
            float segmentDist = 0;

            Vector3 prev = m_Start;
            Vector3 next;

            if (m_PreciseSegmentCount < 1)
            {
                m_PreciseSegmentCount = 1;
            }

            Array.Resize(ref m_PreciseSegmentData, Mathf.NextPowerOfTwo(m_PreciseSegmentCount));

            for (int i = 0; i < m_PreciseSegmentCount; ++i)
            {
                next        = SplineMath.Quadratic(m_Start, m_Control, m_End, (float)(i + 1) / m_PreciseSegmentCount);
                segmentDist = Vector3.Distance(prev, next);

                m_PreciseSegmentData[i].Marker = preciseDist;
                m_PreciseSegmentData[i].Length = segmentDist;

                preciseDist += segmentDist;
                prev         = next;
            }

            m_PreciseDistance = preciseDist;

            float invPreciseDist = 1f / preciseDist;

            for (int i = 0; i < m_PreciseSegmentCount; ++i)
            {
                m_PreciseSegmentData[i].Marker *= invPreciseDist;
                m_PreciseSegmentData[i].Length *= invPreciseDist;
            }

            m_Dirty = false;
            if (m_OnUpdated != null)
            {
                m_OnUpdated(this);
            }
            return(true);
        }
Ejemplo n.º 4
0
        public Vector3 GetDirection(float inPercent, Curve inSegmentCurve = Curve.Linear)
        {
            if (m_Dirty)
            {
                Process();
            }

            float p = inSegmentCurve.Evaluate(inPercent);

            Vector3 dir = SplineMath.QuadraticDerivative(m_Start, m_Control, m_End, p);

            dir.Normalize();

            return(dir);
        }
Ejemplo n.º 5
0
        public Vector3 GetPoint(float inPercent, Curve inSegmentCurve = Curve.Linear)
        {
            if (m_Dirty)
            {
                Process();
            }

            SplineSegment segment;

            GetSegment(inPercent, out segment);

            return(SplineMath.Hermite(m_Vertices[segment.VertexA].OutTangent, m_Vertices[segment.VertexA].Point,
                                      m_Vertices[segment.VertexB].Point, m_Vertices[segment.VertexB].InTangent,
                                      inSegmentCurve.Evaluate(segment.Interpolation)
                                      ));
        }
Ejemplo n.º 6
0
        private void CalculateLengths()
        {
            int segCount = m_SegmentCount;

            if (!m_Looped)
            {
                m_VertexData[segCount].Marker = 1;
                m_VertexData[segCount].Length = 0;
            }

            if (m_SubdivisionsPerSegment < 1)
            {
                m_SubdivisionsPerSegment = 1;
            }

            m_PreciseSegmentCount = segCount * m_SubdivisionsPerSegment;
            Array.Resize(ref m_PreciseSegmentData, Mathf.NextPowerOfTwo(m_PreciseSegmentCount));

            float directDistance  = 0;
            float preciseDistance = 0;

            for (int i = 0; i < segCount; ++i)
            {
                int     nextVertIndex = (i + 1) % m_VertexCount;
                Vector3 myPos         = m_Vertices[i].Point;
                Vector3 nextPos       = m_Vertices[nextVertIndex].Point;

                float directSegmentDist = Vector3.Distance(myPos, nextPos);

                float   preciseSegmentDist = 0;
                Vector3 prevPrecisePoint   = myPos;
                Vector3 nextPrecisePoint;
                for (int j = 0; j < m_SubdivisionsPerSegment; ++j)
                {
                    nextPrecisePoint   = SplineMath.Hermite(m_Vertices[i].OutTangent, myPos, nextPos, m_Vertices[nextVertIndex].InTangent, (float)(j + 1) / m_SubdivisionsPerSegment);
                    preciseSegmentDist = Vector3.Distance(prevPrecisePoint, nextPrecisePoint);

                    int idx = i * m_SubdivisionsPerSegment + j;
                    m_PreciseSegmentData[idx].Marker = preciseDistance;
                    m_PreciseSegmentData[idx].Length = preciseSegmentDist;

                    preciseDistance += preciseSegmentDist;
                    prevPrecisePoint = nextPrecisePoint;
                }

                m_VertexData[i].Marker = directDistance;
                m_VertexData[i].Length = directSegmentDist;

                directDistance += directSegmentDist;
            }

            float invDirectDistance  = 1f / directDistance;
            float invPreciseDistance = 1f / preciseDistance;

            for (int i = 0; i < segCount; ++i)
            {
                m_VertexData[i].Marker *= invDirectDistance;
                m_VertexData[i].Length *= invDirectDistance;
            }

            for (int i = 0; i < m_PreciseSegmentCount; ++i)
            {
                m_PreciseSegmentData[i].Marker *= invPreciseDistance;
                m_PreciseSegmentData[i].Length *= invPreciseDistance;
            }

            m_DirectDistance  = directDistance;
            m_PreciseDistance = preciseDistance;
        }