import { DIVEInput } from '../Input.ts'; /** @experimental See {@link GyroInput}. */ export type GyroInputSettings = { /** How long `enable()` waits for a first reading, in milliseconds. */ timeout?: number; /** * How quickly the reported tilt follows the sensor, per second. Higher is * snappier; `Infinity` passes readings through unfiltered. */ smoothing?: number; /** * Play in radians: the reported tilt only moves once the sensor has moved * further than this from it, and then trails it by this much. Takes out * the jitter of a hand without the jumps of a threshold. `0` turns it off. */ deadzone?: number; }; /** * The way the device is held, as an absolute `axis` on `orientation`. * * `value` is the tilt relative to a neutral pose, in radians, as if the screen * were a window: `x > 0` turned to the right, `y > 0` turned up. Turning the * device within the screen plane is ignored. The neutral pose is the one held * when {@link enable} receives its first reading, or at {@link recalibrate}. * * Browsers that guard the sensor -- iOS -- only grant it from inside a user * gesture, so call {@link GyroInput.requestPermission} straight from the click * handler, before anything else is awaited. * * @experimental How the tilt is measured and filtered is still being tuned on * devices; values, defaults and settings may change without a major release. */ export declare class GyroInput extends DIVEInput { static get isSupported(): boolean; /** * Asks for the sensor where the browser requires it, and resolves whether it * may be used. Browsers that do not ask resolve `true`. */ static requestPermission(): Promise; timeout: number; smoothing: number; deadzone: number; private _state; private _pending; /** What a second `enable()` gets while the first still waits. */ private _enabling; private readonly _neutral; private readonly _current; private _needsCalibration; private readonly _euler; private readonly _screen; private readonly _relative; private readonly _normal; /** The tilt after the low-pass, and after the play on top of it. */ private readonly _filtered; private readonly _reported; private _lastTime; constructor(settings?: GyroInputSettings); get enabled(): boolean; /** * Starts listening and settles with the first reading, which becomes the * neutral pose. Rejects when none arrives in time -- desktop browsers report * orientation events without values. */ enable(): Promise; /** Stops listening. A pending {@link enable} rejects. */ disable(): void; /** Makes the next reading the neutral pose. */ recalibrate: () => void; dispose(): void; private _stop; /** Resolves a pending `enable()`, or rejects it with `error`. */ private _settle; private _onOrientation; /** The device orientation as a screen-aligned frame, into `_current`. */ private _readOrientation; /** * Low-pass, then play, into `_reported`. * * The low-pass is timed by the events themselves, so a sensor that reports * at 60 Hz and one at 200 Hz feel the same. A calibration starts both over * at the reading, which is neutral by definition. */ private _filter; /** Where `reported` ends up, when it may lag `filtered` by the deadzone. */ private _trail; /** * Where the screen faces now, seen from the neutral pose. * * Taken from the screen normal rather than from Euler angles: no wraparound * at 360 degrees, no gimbal lock at 90, and turning within the screen plane * leaves the normal where it is. * * `y` is the angle in the vertical plane, `x` how far the normal leaves that * plane. The other way round, a sideways wobble would grow with the tilt -- * by `1 / cos(y)`, twice as much at 60 degrees -- and moving the device up * and down would turn the camera sideways. */ private _tilt; }