UNPKG

lazy-widgets

Version:

Typescript retained mode GUI for the HTML canvas API

53 lines 2.19 kB
import { PointerDriver } from './PointerDriver.js'; /** * A {@link PointerDriver} which gets pointer events from raycasts in a 3D * engine's world. This is an abstract class and must be implemented. * * @category Driver */ export class RayPointerDriver extends PointerDriver { constructor() { super(...arguments); /** The sources which this is assigned to */ this.sources = new Set(); } /** * Receive a ray from a {@link RayPointerSource}. * * @param pointer - The source's pointer ID, given when setting the source's sink * @param pressing - Is the pointer pressed? If null, then the last pressing state will be used. A bitmask where each set bit represents a different button being pressed * @param origin - The world position where the ray is starting * @param direction - A normalised vector representing the ray's direction. Not a euler rotation nor a quaternion * @param shift - Is shift being pressed? * @param ctrl - Is control being pressed? * @param alt - Is alt being pressed? */ handlePointerRay(pointer, pressing, origin, direction, shift, ctrl, alt) { // Cast a ray and get the root that intersects with the ray and the // intersection coordinates const [root, xNorm, yNorm] = this.castRay(origin, direction); // Queue a leave event if no root intersected, else, queue a move event if (root === null) { this.leaveAnyPointer(pointer); } else { this.movePointer(root, pointer, xNorm, yNorm, pressing, shift, ctrl, alt); } } /** Add a source. Assigns itself to the given source. */ addSource(source) { if (!this.sources.has(source)) { source.setRayPointerDriver(this); this.sources.add(source); } } setPointerHint(pointer, hint) { const changed = super.setPointerHint(pointer, hint); // Call onPointerHintChanged handler for each source for (const source of this.sources) { source.onPointerHintChanged(pointer, hint); } return changed; } } //# sourceMappingURL=RayPointerDriver.js.map