Esempio n. 1
0
        public Vector3 xxxSteerForSeek(Vector3 target)
        {
            //  const Vector3 offset = target - position;
            Vector3 offset          = target - this.Position;
            Vector3 desiredVelocity = Vector3Helpers.TruncateLength(offset, this.MaxSpeed); //xxxnew

            return(desiredVelocity - this.Velocity);
        }
Esempio n. 2
0
        // apply a given steering force to our momentum,
        // adjusting our orientation to maintain velocity-alignment.
        public void ApplySteeringForce(Vector3 force, float elapsedTime)
        {
            Vector3 adjustedForce = AdjustRawSteeringForce(force, elapsedTime);

            // enforce limit on magnitude of steering force
            Vector3 clippedForce = Vector3Helpers.TruncateLength(adjustedForce, MaxForce);

            // compute acceleration and velocity
            Vector3 newAcceleration = (clippedForce / Mass);
            Vector3 newVelocity     = Velocity;

            // damp out abrupt changes and oscillations in steering acceleration
            // (rate is proportional to time step, then clipped into useful range)
            if (elapsedTime > 0)
            {
                float smoothRate = Utilities.Clip(9 * elapsedTime, 0.15f, 0.4f);
                Utilities.BlendIntoAccumulator(smoothRate, newAcceleration, ref acceleration);
            }

            // Euler integrate (per frame) acceleration into velocity
            newVelocity += acceleration * elapsedTime;

            // enforce speed limit
            newVelocity = Vector3Helpers.TruncateLength(newVelocity, MaxSpeed);

            // update Speed
            Speed = (newVelocity.Length);

            // Euler integrate (per frame) velocity into position
            Position = (Position + (newVelocity * elapsedTime));

            // regenerate local space (by default: align vehicle's forward axis with
            // new velocity, but this behavior may be overridden by derived classes.)
            RegenerateLocalSpace(newVelocity, elapsedTime);

            // maintain path curvature information
            MeasurePathCurvature(elapsedTime);

            // running average of recent positions
            Utilities.BlendIntoAccumulator(elapsedTime * 0.06f,             // QQQ
                                           Position,
                                           ref smoothedPosition);
        }