Provides a way to calculate velocity via effectively creating a "complementary filter".

velQuick and velSmooth separately accumulate over time. velInstant and velUsed do not accumulate and are discarded each update. velQuick is responsive, but noisy. velSmooth is laggy but eventually more accurate. By tracking them separately the used result can be responsive in the short term and accurate in the long term.

Constructors

Accessors

Methods

Constructors

  • Creates a velocity tracker instance.

    Parameters

    • Optionalopts: {
          resetDeltaTime?: number;
          scaleTime?: number;
      }

      Optional parameters.

      • OptionalresetDeltaTime?: number

        Delta time in milliseconds that resets velocity tracking.

      • OptionalscaleTime?: number

        Scales velocity calculation to new time frame. 1000 is velocity per second.

    Returns TJSVelocityTrack

Accessors

  • get resetDeltaTime(): number
  • Returns number

    Gets resetDeltaTime.

  • set resetDeltaTime(resetDeltaTime): void
  • Sets resetDeltaTime.

    Parameters

    • resetDeltaTime: number

      Delta time in milliseconds that resets velocity tracking.

    Returns void

  • get scaleTime(): number
  • Returns number

    Gets scaleTime.

  • set scaleTime(scaleTime): void
  • Sets scaleTime.

    Parameters

    • scaleTime: number

      Scales velocity calculation to new time frame. 1000 is velocity per second.

    Returns void

Methods

  • Gets the current velocity tracking data.

    Returns {
        x: number;
        y: number;
        z: number;
    }

    Velocity tracking data.

    • x: number
    • y: number
    • z: number
  • Resets velocity tracking data.

    Parameters

    • Optionalx: number

      'X' value to set to last sample point.

    • Optionaly: number

      'Y' value to set to last sample point.

    • Optionalz: number

      'Z' value to set to last sample point.

    • OptionalsampleTime: number

      A sample time in milliseconds resolution.

    Returns void

  • Runs ongoing velocity calculation of x / y / z given a sample time.

    Parameters

    • Optionalx: number

      New sample X

    • Optionaly: number

      New sample Y

    • Optionalz: number

      New sample Z

    • OptionalsampleTime: number

      An optional specific time w/ millisecond resolution.

    Returns {
        x: number;
        y: number;
        z: number;
    }

    current velocity.

    • x: number
    • y: number
    • z: number