Exemplo n.º 1
0
        //--------------------- AccumulateForce ----------------------------------
        //
        //  This function calculates how much of its max steering force the 
        //  vehicle has left to apply and then applies that amount of the
        //  force to add.
        //------------------------------------------------------------------------
        public bool AccumulateForce(ref Vector2D RunningTot, Vector2D ForceToAdd)
        {

            //calculate how much steering force the vehicle has used so far
            double MagnitudeSoFar = RunningTot.Length();

            //calculate how much steering force remains to be used by this vehicle
            double MagnitudeRemaining = m_parentMovingEntity.MaxForce - MagnitudeSoFar;

            //return false if there is no more force left to use
            if (MagnitudeRemaining <= 0.0) return false;

            //calculate the magnitude of the force we want to add
            double MagnitudeToAdd = ForceToAdd.Length();

            //if the magnitude of the sum of ForceToAdd and the running total
            //does not exceed the maximum force available to this vehicle, just
            //add together. Otherwise add as much of the ForceToAdd vector is
            //possible without going over the max.
            if (MagnitudeToAdd < MagnitudeRemaining)
            {
                RunningTot += ForceToAdd;
            }
            else
            {
                //add it to the steering force
                RunningTot += (Vector2D.Vec2DNormalize(ForceToAdd) * MagnitudeRemaining);
            }

            return true;
        }
Exemplo n.º 2
0
        public static Vector2D Vec2DNormalize(Vector2D v)
        {
            Vector2D vec = new Vector2D(v.X, v.Y);

            double vector_length = vec.Length();

            if (vector_length > double.Epsilon)
            {
                vec.X /= vector_length;
                vec.Y /= vector_length;
            }

            return vec;
        }