示例#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);
        }
示例#2
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)
                                      ));
        }
示例#3
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;
        }