Example #1
0
        public DeadReckoning(IKinematic physObject, bool estimateVelocity = false)
        {
            this.estimateVelocity = estimateVelocity;
            predictedPhysObject   = physObject;
            stateOld = new KinematicState(physObject.Position, physObject.Velocity, physObject.Acceleration);
            stateNew = new KinematicState(physObject.Position, physObject.Velocity, physObject.Acceleration);

            updateTimer.Start();
        }
Example #2
0
        /// <summary>
        /// We use this to predict a current state
        /// </summary>
        /// <param name="oldState"></param>
        /// <param name="newState"></param>
        /// <param name="interpWeighting"></param>
        KinematicState BlendKinematicStates(IKinematic oldState, IKinematic newState, float interpWeighting = 0.5f)
        {
            interpWeighting = Mathf.Clamp01(interpWeighting);

            float interpNew = interpWeighting;
            float interpOld = 1 - interpWeighting;

            //Explanation of percentateToNew:
            //A value of 0.0 will return the exact same state as "oldState",
            //A value of 1.0 will return the exact same state as "newState",
            //A value of 0.5 will return a state with data exactly in the middle of that of "old" and "new".
            //Its value should never be outside of [0, 1].

            Vector3 blendedVelocity = oldState.Velocity + (newState.Velocity - oldState.Velocity) * normalizedTime;

            KinematicState final = new KinematicState();

            final.Position     = (interpOld * oldState.Position) + (interpNew * newState.Position);
            final.Velocity     = (interpOld * oldState.Velocity) + (interpNew * newState.Velocity);
            final.Acceleration = (interpOld * oldState.Acceleration) + (interpNew * newState.Acceleration);

            return(final);
        }
Example #3
0
        /// <summary>
        /// Will modify and update a phys object with an extrapolated position based on a delta time
        /// </summary>
        /// <param name="physObject"></param>
        /// <param name="deltaTime"></param>
        public static IKinematic ExtrapolatePosition(IKinematic physObject, float deltaTime)
        {
            Vector3 newPos = physObject.Position + physObject.Velocity * deltaTime + 0.5f * physObject.Acceleration * deltaTime * deltaTime;

            return(new KinematicState(newPos, physObject.Velocity, physObject.Acceleration));
        }