コード例 #1
0
 protected virtual void OnEnable()
 {
     velocitySamples          = new Vector3[VelocityAverageFrames];
     angularVelocitySamples   = new Vector3[AngularVelocityAverageFrames];
     previousPosition         = Source.TryGetPosition();
     previousRotation         = Source.TryGetRotation();
     previousRelativePosition = RelativeTo.TryGetPosition();
     previousRelativeRotation = RelativeTo.TryGetRotation();
 }
コード例 #2
0
        /// <summary>
        /// Collects samples for velocity.
        /// </summary>
        /// <param name="factor">The multiplier to apply to the transform difference.</param>
        protected virtual void EstimateVelocity(float factor)
        {
            if (velocitySamples.Length == 0)
            {
                return;
            }

            Vector3 currentRelativePosition = RelativeTo.TryGetPosition();
            Vector3 relativeDeltaPosition   = currentRelativePosition - previousRelativePosition;
            Vector3 currentPosition         = Source.TryGetPosition();
            int     sampleIndex             = currentSampleCount % velocitySamples.Length;

            velocitySamples[sampleIndex] = factor * (currentPosition - previousPosition - relativeDeltaPosition);
            previousPosition             = currentPosition;
            previousRelativePosition     = currentRelativePosition;
        }
コード例 #3
0
 protected virtual void OnAfterRelativeToChange()
 {
     previousRelativePosition = RelativeTo.TryGetPosition();
     previousRelativeRotation = RelativeTo.TryGetRotation();
 }