Skip to content

Commit b01b969

Browse files
authored
Merge pull request #20 from ProjectLighthouseCAU/orientation-motion-events
Add `OrientationEvent` and `MotionEvent`
2 parents aecb579 + a2ae847 commit b01b969

File tree

1 file changed

+54
-1
lines changed
  • src/common/protocol/input

1 file changed

+54
-1
lines changed

src/common/protocol/input/new.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,58 @@ export interface MIDIEvent extends BaseInputEvent<'midi'> {
133133
data: Uint8Array;
134134
}
135135

136+
/**
137+
* A device orientation event payload.
138+
*
139+
* Modeled after https://developer.mozilla.org/de/docs/Web/API/DeviceOrientationEvent.
140+
*/
141+
export interface OrientationEvent extends BaseInputEvent<'orientation'> {
142+
/** Whether the device provides absolute orientation data. */
143+
absolute: boolean;
144+
/** The motion of the device around the z-axis, in degrees from 0 (inclusive) to 360 (exclusive). */
145+
alpha: number;
146+
/** The motion of the device around the x-axis (front to back motion), in degrees from -180 (inclusive) to 180 (exclusive). */
147+
beta: number;
148+
/** The motion of the device around the y-axis (left to right motion), in degrees from -90 (inclusive) to 90 (exclusive). */
149+
gamma: number;
150+
}
151+
152+
/**
153+
* A device motion event payload.
154+
*
155+
* Modeled after https://developer.mozilla.org/de/docs/Web/API/DeviceMotionEvent.
156+
*/
157+
export interface MotionEvent extends BaseInputEvent<'motion'> {
158+
/** The acceleration of the device in m/s^2 (in 3D space). */
159+
acceleration: {
160+
/** The acceleration on the x-axis. */
161+
x: number;
162+
/** The acceleration on the y-axis. */
163+
y: number;
164+
/** The acceleration on the z-axis. */
165+
z: number;
166+
},
167+
/** The acceleration of the device, including gravity, in m/s^2 (in 3D space). */
168+
accelerationIncludingGravity: {
169+
/** The acceleration on the x-axis (west to east). */
170+
x: number;
171+
/** The acceleration on the y-axis (south to north). */
172+
y: number;
173+
/** The acceleration on the z-axis (down to up). */
174+
z: number;
175+
},
176+
/** The rotation rate in deg/s on the three rotation axes alpha, beta and gamma. */
177+
rotationRate: {
178+
/** The rate at which the device rotates about its z-axis (i.e. is twisted around a line perpendicular to its screen.) */
179+
alpha: number;
180+
/** The rate at which the device rotates about its x-axis (i.e. front to back) */
181+
beta: number;
182+
/** The rate at which the device rotates about its y-axis (i.e. side to side) */
183+
gamma: number;
184+
},
185+
/** The granularity of these events in ms. */
186+
interval: number;
187+
}
188+
136189
/** An input event payload. */
137-
export type InputEvent = KeyEvent | MouseEvent | GamepadEvent | MIDIEvent;
190+
export type InputEvent = KeyEvent | MouseEvent | GamepadEvent | MIDIEvent | OrientationEvent | MotionEvent;

0 commit comments

Comments
 (0)