示例#1
0
        // ----------------------------------------------------------------------------
        // measure path curvature (1/turning-radius), maintain smoothed version


        void measurePathCurvature(float elapsedTime)
        {
            if (elapsedTime > 0)
            {
                Vector3 pos = Position;
                Vector3 fwd = Forward;
                Vector3 dP  = _lastPosition - pos;
                Vector3 dF  = (_lastForward - fwd) / dP.magnitude;
                //SI - BIT OF A WEIRD FIX HERE . NOT SURE IF ITS CORRECT
                //Vector3 lateral = dF.perpendicularComponent (forward ());
                Vector3 lateral = OpenSteerUtility.perpendicularComponent(dF, fwd);

                float sign = (Vector3.Dot(lateral, Side) < 0) ? 1.0f : -1.0f;
                _curvature = lateral.magnitude * sign;

                /*
                 *  If elapsedTime is greater than 0.25, that means that blendIntoAccumulator
                 *  will end up clipping the first parameter to [0..1], and we'll lose information,
                 *  making this call framerate-dependent.
                 *
                 *  No idea where that 4.0f value comes from, probably out of a hat.
                 */
                _smoothedCurvature = OpenSteerUtility.blendIntoAccumulator(elapsedTime * 4.0f,
                                                                           _curvature,
                                                                           _smoothedCurvature);

                _lastForward  = fwd;
                _lastPosition = pos;
            }
        }
示例#2
0
        // ----------------------------------------------------------------------------
        // alternate version: keep FORWARD parallel to velocity, adjust UP according
        // to a no-basis-in-reality "banking" behavior, something like what birds and
        // airplanes do

        // XXX experimental cwr 6-5-03

        public void regenerateLocalSpaceForBanking(Vector3 newVelocity, float elapsedTime)
        {
            // the length of this global-upward-pointing vector controls the vehicle's
            // tendency to right itself as it is rolled over from turning acceleration
            Vector3 globalUp = new Vector3(0, 0.2f, 0);

            // acceleration points toward the center of local path curvature, the
            // length determines how much the vehicle will roll while turning
            Vector3 accelUp = _smoothedAcceleration * 0.05f;

            // combined banking, sum of UP due to turning and global UP
            Vector3 bankUp = accelUp + globalUp;

            // blend bankUp into vehicle's UP basis vector
            // RJM: framerate-dependent, hopefuly we're getting more than 3 frames per second :-)
            float   smoothRate = elapsedTime * 3;
            Vector3 tempUp     = Up;

            tempUp = OpenSteerUtility.blendIntoAccumulator(smoothRate, bankUp, tempUp);
            tempUp.Normalize();
            Up = tempUp;

            #if ANNOTATE_LOCALSPACE
            annotationLine(position(), position() + (globalUp * 4), gWhite);
            annotationLine(position(), position() + (bankUp * 4), gOrange);
            annotationLine(position(), position() + (accelUp * 4), gRed);
            annotationLine(position(), position() + (up() * 1), gYellow);
            #endif

            // adjust orthonormal basis vectors to be aligned with new velocity
            if (Speed > 0)
            {
                Forward = (newVelocity / Speed);
            }
        }
示例#3
0
 private void measurePathCurvature(float elapsedTime)
 {
     if (elapsedTime > 0f)
     {
         Vector3 position = base.Position;
         Vector3 forward  = base.Forward;
         Vector3 vector   = this._lastPosition - position;
         Vector3 source   = (this._lastForward - forward) / vector.get_magnitude();
         Vector3 vector2  = OpenSteerUtility.perpendicularComponent(source, forward);
         float   num      = (Vector3.Dot(vector2, base.Side) >= 0f) ? -1f : 1f;
         this._curvature         = vector2.get_magnitude() * num;
         this._smoothedCurvature = OpenSteerUtility.blendIntoAccumulator(elapsedTime * 4f, this._curvature, this._smoothedCurvature);
         this._lastForward       = forward;
         this._lastPosition      = position;
     }
 }
示例#4
0
        public void regenerateLocalSpaceForBanking(Vector3 newVelocity, float elapsedTime)
        {
            Vector3 vector     = new Vector3(0f, 0.2f, 0f);
            Vector3 vector2    = this._smoothedAcceleration * 0.05f;
            Vector3 newValue   = vector2 + vector;
            float   smoothRate = elapsedTime * 3f;
            Vector3 vector3    = base.Up;

            vector3 = OpenSteerUtility.blendIntoAccumulator(smoothRate, newValue, vector3);
            vector3.Normalize();
            base.Up = vector3;
            if (base.Speed > 0f)
            {
                base.Forward = newVelocity / base.Speed;
            }
        }