Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

trackable-pointer.ts 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * encantar.js
  3. * GPU-accelerated Augmented Reality for the web
  4. * Copyright (C) 2022-2024 Alexandre Martins <alemartf(at)gmail.com>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published
  8. * by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. * trackable-pointer.ts
  20. * A trackable representing an instance of pointer-based input
  21. */
  22. import { Trackable } from '../tracker';
  23. import { Vector2 } from '../../geometry/vector2';
  24. /**
  25. * The phase of a TrackablePointer. Possible values:
  26. * - "began": the tracking began in this frame (e.g., a finger has just touched the screen)
  27. * - "stationary": the user did not move the pointer in this frame
  28. * - "moved": the user moved the pointer in this frame
  29. * - "ended": the tracking ended in this frame (e.g., a finger has just been lifted from the screen)
  30. * - "canceled": the tracking was canceled in this frame (e.g., the page has just lost focus)
  31. */
  32. export type TrackablePointerPhase = 'began' | 'moved' | 'stationary' | 'ended' | 'canceled';
  33. /**
  34. * A trackable representing an instance of pointer-based input
  35. */
  36. export interface TrackablePointer extends Trackable
  37. {
  38. /** a unique identifier assigned to this pointer */
  39. readonly id: number;
  40. /** the phase of the pointer */
  41. readonly phase: TrackablePointerPhase;
  42. /** current position in normalized units [-1,1]x[-1,1] */
  43. readonly position: Vector2;
  44. /** the difference between the position of the pointer in this and in the previous frame */
  45. readonly deltaPosition: Vector2;
  46. /** the position of the pointer when its tracking began */
  47. readonly initialPosition: Vector2;
  48. /** current velocity, given in normalized units per second */
  49. readonly velocity: Vector2;
  50. /** elapsed time, in seconds, since the tracking of this pointer began */
  51. readonly elapsedTime: number;
  52. /** how much this pointer has moved, in normalized units, since its tracking began */
  53. readonly totalDistance: number;
  54. /** whether or not this is the primary pointer for this type */
  55. readonly isPrimary: boolean;
  56. /** the type of the originating device; typically "mouse", "touch" or "pen" */
  57. readonly kind: string;
  58. }