Exemplo n.º 1
0
        public void DrawPath()
        {
            if (GoalReached)
            {
                return;
            }

            float pathLength = pathSpline.ComputeCurveLength(nextControlPoint);

            if (pathLength <= 0.0f)
            {
                return;
            }

            float stepDist = 0.2f;
            int   lines    = (int)math.floor(pathLength / stepDist);

            float3 position = pathSpline.EvaluatePointAtDistance(0.0f, nextControlPoint).position;

            for (int i = 0; i < lines; ++i)
            {
                float  distance     = ((i + 1) / (float)lines) * pathLength;
                float3 nextPosition = pathSpline.EvaluatePointAtDistance(distance, nextControlPoint).position;

                DebugDraw.DrawLine(position, nextPosition, Color.white);

                position = nextPosition;
            }

            for (int i = 0; i < pathSpline.segments.Length; ++i)
            {
                float radius = (i == pathSpline.segments.Length - 1) ? navParams.finalControlPointRadius : navParams.intermediateControlPointRadius;
                DebugDraw.DrawSphere(pathSpline.segments[i].OutPosition, quaternion.identity, radius, (nextControlPoint <= i) ? Color.red : Color.white);
            }
        }
        /// <summary>
        /// Displays the trajectory model in world space.
        /// </summary>
        /// <param name="worldRootTransform">Anchor transform to be used as a reference for the trajectory display.</param>
        /// <param name="color">The color to be used for the trajectory display.</param>
        public void Display(AffineTransform worldRootTransform, Color color)
        {
            Color fillColor            = color;
            Color linesAndContourColor = color;

            linesAndContourColor.a = 0.9f;

            int trajectoryLength = TrajectoryLength;

            Binary.DebugDrawTransform(worldRootTransform, 0.1f);

            var previousRootTransform = worldRootTransform * this[0];

            for (int i = 1; i < trajectoryLength; ++i)
            {
                var currentRootTransform =
                    worldRootTransform * this[i];

                DebugDraw.DrawLine(previousRootTransform.t,
                                   currentRootTransform.t, color);

                previousRootTransform = currentRootTransform;
            }

            void DrawArrow(AffineTransform transform)
            {
                DebugDraw.DrawArrow(
                    worldRootTransform * transform,
                    fillColor, linesAndContourColor, 0.25f);
            }

            int stepSize = Missing.truncToInt(Binary.SampleRate / 3);
            int numSteps = trajectoryLength / stepSize;

            for (int i = 0; i < numSteps; ++i)
            {
                DrawArrow(this[i * stepSize]);
            }

            DrawArrow(this[trajectoryLength - 1]);
        }