// %BANNER_BEGIN% // --------------------------------------------------------------------- // %COPYRIGHT_BEGIN% // Copyright (c) (2021-2022) Magic Leap, Inc. All Rights Reserved. // Use of this file is governed by the Software License Agreement, located here: https://www.magicleap.com/software-license-agreement-ml2 // Terms and conditions applicable to third-party materials accompanying this distribution may also be found in the top-level NOTICE file appearing herein. // %COPYRIGHT_END% // --------------------------------------------------------------------- // %BANNER_END% using System; using System.Runtime.InteropServices; using UnityEngine.XR.InteractionSubsystems; namespace UnityEngine.XR.MagicLeap { /// /// MagicLeap implementation of the XRGestureSubsystem. Do not create this directly. Use the SubsystemManager instead. /// public partial class GestureSubsystem { public static partial class Extensions { /// /// The event data related to a Magic Leap Touchpad gesture /// /// [StructLayout(LayoutKind.Sequential)] public struct TouchpadGestureEvent : IEquatable { /// /// The associated with this gesture. /// public GestureId id { get { return m_Id; } } /// /// The of the gesture. /// public GestureState state { get { return m_State; } } /// /// The controller id associated with this gesture. /// public byte controllerId { get { return m_ControllerId; } } /// /// Angle from the center of the touchpad to the finger. /// public float angle { get { return m_Angle; } } /// /// Direction of gesture /// public InputSubsystem.Extensions.TouchpadGesture.Direction direction { get { return m_Direction; } } /// /// For radial gestures, this is the absolute value of the angle. For scroll and pinch gestures, this is the absolute distance traveled in touchpad distance. The touchpad is defined as having extents of [-1.0,1.0] so this distance has a range of [0.0,2.0]. /// public float distance { get { return m_Distance; } } /// /// Gesture position (x,y) and force (z). Position is in the [-1.0,1.0] range and force is in the [0.0,1.0] range. /// public Vector3 positionAndForce { get { return m_PositionAndForce; } } /// /// For radial gestures, this is the radius of the gesture. The touchpad is defined as having extents of [-1.0,1.0] so this radius has a range of [0.0,2.0]. /// public float radius { get { return m_Radius; } } /// /// Speed of gesture. Note that this takes on different meanings depending on the gesture type being performed: /// public float speed { get { return m_Speed; } } /// /// Type of gesture. /// public InputSubsystem.Extensions.TouchpadGesture.Type type { get { return m_Type; } } /// /// Gets a default-initialized . /// /// A default . public static TouchpadGestureEvent GetDefault() { return new TouchpadGestureEvent(GestureId.invalidId, GestureState.Invalid, 0, 0.0f, InputSubsystem.Extensions.TouchpadGesture.Direction.None, 0.0f, Vector3.zero, 0.0f, 0.0f, InputSubsystem.Extensions.TouchpadGesture.Type.None); } /// /// Constructs a new . /// /// The associated with the gesture. /// The associated with the gesture. /// The controller id associated with this gesture. /// The angel of the touch of the gesture. /// The direction of the touch of the gesture. /// The distance of the gesture. /// The position and force of the gesture. /// The radius of the touch of the gesture. /// The speed of the gesture. /// The type of the gesture. public TouchpadGestureEvent(GestureId id, GestureState state, byte controllerId, float angle, InputSubsystem.Extensions.TouchpadGesture.Direction direction, float distance, Vector3 positionAndForce, float radius, float speed, InputSubsystem.Extensions.TouchpadGesture.Type type) { m_Id = id; m_State = state; m_ControllerId = controllerId; m_Angle = angle; m_Direction = direction; m_Distance = distance; m_PositionAndForce = positionAndForce; m_Radius = radius; m_Speed = speed; m_Type = type; } /// /// Generates a new string describing the gestures's properties suitable for debugging purposes. /// /// A string describing the gestures's properties. public override string ToString() { if(MLDevice.IsOpenXRLoaderActive()) { return "[Gestures currently unsupported under OpenXR!]"; } return string.Format( "Touchpad Gesture:\n\tgestureId: {0}\n\tgestureState: {1}\n\tcontrollerId: {2}\n\tangle: {3}\n\tdirection: {4}\n\tdistance: {5}\\n\tpositionAndForce: {6}\n\tradius: {7}\n\tspeed: {8}\n\ttype: {9}", id, state, controllerId, angle, direction, distance, positionAndForce, radius, speed, type); } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; return obj is TouchpadGestureEvent && Equals((TouchpadGestureEvent)obj); } public override int GetHashCode() { unchecked { var hashCode = m_Id.GetHashCode(); hashCode = (hashCode * 486187739) + ((int)m_State).GetHashCode(); hashCode = (hashCode * 486187739) + ((int)m_ControllerId).GetHashCode(); hashCode = (hashCode * 486187739) + ((int)m_Angle).GetHashCode(); hashCode = (hashCode * 486187739) + ((int)m_Direction).GetHashCode(); hashCode = (hashCode * 486187739) + ((int)m_Distance).GetHashCode(); hashCode = (hashCode * 486187739) + m_PositionAndForce.GetHashCode(); hashCode = (hashCode * 486187739) + ((int)m_Radius).GetHashCode(); hashCode = (hashCode * 486187739) + ((int)m_Speed).GetHashCode(); hashCode = (hashCode * 486187739) + ((int)m_Type).GetHashCode(); return hashCode; } } public static bool operator ==(TouchpadGestureEvent lhs, TouchpadGestureEvent rhs) { return lhs.Equals(rhs); } public static bool operator !=(TouchpadGestureEvent lhs, TouchpadGestureEvent rhs) { return !lhs.Equals(rhs); } public bool Equals(TouchpadGestureEvent other) { return m_Id == other.id && m_State == other.state && m_ControllerId == other.controllerId && m_Angle == other.angle && m_Direction == other.direction && m_Distance == other.distance && m_PositionAndForce == other.positionAndForce && m_Radius == other.radius && m_Speed == other.speed && m_Type == other.type; } GestureId m_Id; GestureState m_State; byte m_ControllerId; float m_Angle; InputSubsystem.Extensions.TouchpadGesture.Direction m_Direction; float m_Distance; Vector3 m_PositionAndForce; float m_Radius; float m_Speed; InputSubsystem.Extensions.TouchpadGesture.Type m_Type; } } } }