// Copyright HTC Corporation All Rights Reserved. using System; namespace VIVE.OpenXR.Hand { /// /// The XrHandTrackerEXT handle represents the resources for hand tracking of the specific hand. /// public struct XrHandTrackerEXT : IEquatable { private readonly ulong value; public XrHandTrackerEXT(ulong u) { value = u; } public static implicit operator ulong(XrHandTrackerEXT xrInst) { return xrInst.value; } public static implicit operator XrHandTrackerEXT(ulong u) { return new XrHandTrackerEXT(u); } public bool Equals(XrHandTrackerEXT other) { return value == other.value; } public bool Equals(ulong other) { return value == other; } public override bool Equals(object obj) { return obj is XrHandTrackerEXT && Equals((XrHandTrackerEXT)obj); } public override int GetHashCode() { return value.GetHashCode(); } public override string ToString() { return value.ToString(); } public static bool operator ==(XrHandTrackerEXT a, XrHandTrackerEXT b) { return a.Equals(b); } public static bool operator !=(XrHandTrackerEXT a, XrHandTrackerEXT b) { return !a.Equals(b); } public static bool operator >=(XrHandTrackerEXT a, XrHandTrackerEXT b) { return a.value >= b.value; } public static bool operator <=(XrHandTrackerEXT a, XrHandTrackerEXT b) { return a.value <= b.value; } public static bool operator >(XrHandTrackerEXT a, XrHandTrackerEXT b) { return a.value > b.value; } public static bool operator <(XrHandTrackerEXT a, XrHandTrackerEXT b) { return a.value < b.value; } public static XrHandTrackerEXT operator +(XrHandTrackerEXT a, XrHandTrackerEXT b) { return a.value + b.value; } public static XrHandTrackerEXT operator -(XrHandTrackerEXT a, XrHandTrackerEXT b) { return a.value - b.value; } public static XrHandTrackerEXT operator *(XrHandTrackerEXT a, XrHandTrackerEXT b) { return a.value * b.value; } public static XrHandTrackerEXT operator /(XrHandTrackerEXT a, XrHandTrackerEXT b) { if (b.value == 0) { throw new DivideByZeroException(); } return a.value / b.value; } } /// /// The XrHandEXT describes which hand the XrHandTrackerEXT is tracking. /// public enum XrHandEXT { /// /// Specifies the hand tracker will be tracking the user’s left hand. /// XR_HAND_LEFT_EXT = 1, /// /// Specifies the hand tracker will be tracking the user’s right hand. /// XR_HAND_RIGHT_EXT = 2, XR_HAND_MAX_ENUM_EXT = 3 } /// /// Defines 26 joints for hand tracking: 4 joints for the thumb finger, 5 joints for the other four fingers, and the wrist and palm of the hands. /// public enum XrHandJointEXT { XR_HAND_JOINT_PALM_EXT = 0, XR_HAND_JOINT_WRIST_EXT = 1, XR_HAND_JOINT_THUMB_METACARPAL_EXT = 2, XR_HAND_JOINT_THUMB_PROXIMAL_EXT = 3, XR_HAND_JOINT_THUMB_DISTAL_EXT = 4, XR_HAND_JOINT_THUMB_TIP_EXT = 5, XR_HAND_JOINT_INDEX_METACARPAL_EXT = 6, XR_HAND_JOINT_INDEX_PROXIMAL_EXT = 7, XR_HAND_JOINT_INDEX_INTERMEDIATE_EXT = 8, XR_HAND_JOINT_INDEX_DISTAL_EXT = 9, XR_HAND_JOINT_INDEX_TIP_EXT = 10, XR_HAND_JOINT_MIDDLE_METACARPAL_EXT = 11, XR_HAND_JOINT_MIDDLE_PROXIMAL_EXT = 12, XR_HAND_JOINT_MIDDLE_INTERMEDIATE_EXT = 13, XR_HAND_JOINT_MIDDLE_DISTAL_EXT = 14, XR_HAND_JOINT_MIDDLE_TIP_EXT = 15, XR_HAND_JOINT_RING_METACARPAL_EXT = 16, XR_HAND_JOINT_RING_PROXIMAL_EXT = 17, XR_HAND_JOINT_RING_INTERMEDIATE_EXT = 18, XR_HAND_JOINT_RING_DISTAL_EXT = 19, XR_HAND_JOINT_RING_TIP_EXT = 20, XR_HAND_JOINT_LITTLE_METACARPAL_EXT = 21, XR_HAND_JOINT_LITTLE_PROXIMAL_EXT = 22, XR_HAND_JOINT_LITTLE_INTERMEDIATE_EXT = 23, XR_HAND_JOINT_LITTLE_DISTAL_EXT = 24, XR_HAND_JOINT_LITTLE_TIP_EXT = 25, XR_HAND_JOINT_MAX_ENUM_EXT = 26 } /// /// The XrHandJointSetEXT enum describes the set of hand joints to track when creating an XrHandTrackerEXT. /// public enum XrHandJointSetEXT { /// /// Indicates that the created XrHandTrackerEXT tracks the set of hand joints described by XrHandJointEXT enum, i.e. the xrLocateHandJointsEXT function returns an array of joint locations with the count of XR_HAND_JOINT_COUNT_EXT and can be indexed using XrHandJointEXT. /// XR_HAND_JOINT_SET_DEFAULT_EXT = 0, XR_HAND_JOINT_SET_MAX_ENUM_EXT = 1 } /// /// An application can inspect whether the system is capable of hand tracking input by extending the XrSystemProperties with XrSystemHandTrackingPropertiesEXT structure when calling xrGetSystemProperties. /// public struct XrSystemHandTrackingPropertiesEXT { /// /// The XrStructureType of this structure. /// public XrStructureType type; /// /// NULL or a pointer to the next structure in a structure chain. No such structures are defined in core OpenXR or this extension. /// public IntPtr next; /// /// An XrBool32, indicating if current system is capable of hand tracking input. /// public XrBool32 supportsHandTracking; }; /// /// The XrHandTrackerCreateInfoEXT structure describes the information to create an XrHandTrackerEXT handle. /// public struct XrHandTrackerCreateInfoEXT { /// /// The XrStructureType of this structure. /// public XrStructureType type; /// /// NULL or a pointer to the next structure in a structure chain. No such structures are defined in core OpenXR or this extension. /// public IntPtr next; /// /// An XrHandEXT which describes which hand the tracker is tracking. /// public XrHandEXT hand; /// /// An XrHandJointSetEXT describe the set of hand joints to retrieve. /// public XrHandJointSetEXT handJointSet; /// The XrStructureType of this structure. /// NULL or a pointer to the next structure in a structure chain. No such structures are defined in core OpenXR or this extension. /// An XrHandEXT which describes which hand the tracker is tracking. /// An XrHandJointSetEXT describe the set of hand joints to retrieve. public XrHandTrackerCreateInfoEXT(XrStructureType in_type, IntPtr in_next, XrHandEXT in_hand, XrHandJointSetEXT in_handJointSet) { type = in_type; next = in_next; hand = in_hand; handJointSet = in_handJointSet; } } /// /// The XrHandJointsLocateInfoEXT structure describes the information to locate hand joints. /// public struct XrHandJointsLocateInfoEXT { /// /// The XrStructureType of this structure. /// public XrStructureType type; /// /// NULL or a pointer to the next structure in a structure chain. No such structures are defined in core OpenXR or this extension. /// public IntPtr next; /// /// An XrSpace within which the returned hand joint locations will be represented. /// public XrSpace baseSpace; /// /// An XrTime at which to locate the hand joints. /// public XrTime time; /// The XrStructureType of this structure. /// NULL or a pointer to the next structure in a structure chain. No such structures are defined in core OpenXR or this extension. /// An XrSpace within which the returned hand joint locations will be represented. /// An XrTime at which to locate the hand joints. public XrHandJointsLocateInfoEXT(XrStructureType in_type, IntPtr in_next, XrSpace in_baseSpace, XrTime in_time) { type = in_type; next = in_next; baseSpace = in_baseSpace; time = in_time; } }; /// /// XrHandJointLocationEXT structure describes the position, orientation, and radius of a hand joint. /// public struct XrHandJointLocationEXT { /// /// A bitfield, with bit masks defined in XrSpaceLocationFlags, to indicate which members contain valid data. If none of the bits are set, no other fields in this structure should be considered to be valid or meaningful. /// public XrSpaceLocationFlags locationFlags; /// /// An XrPosef defining the position and orientation of the origin of a hand joint within the reference frame of the corresponding XrHandJointsLocateInfoEXT::baseSpace. /// public XrPosef pose; /// /// A float value radius of the corresponding joint in units of meters. /// public float radius; } /// /// XrHandJointVelocityEXT structure describes the linear and angular velocity of a hand joint. /// public struct XrHandJointVelocityEXT { /// /// A bitfield, with bit masks defined in XrSpaceVelocityFlags, to indicate which members contain valid data. If none of the bits are set, no other fields in this structure should be considered to be valid or meaningful. /// public XrSpaceVelocityFlags velocityFlags; /// /// The relative linear velocity of the hand joint with respect to and expressed in the reference frame of the corresponding XrHandJointsLocateInfoEXT::baseSpace, in units of meters per second. /// public XrVector3f linearVelocity; /// /// The relative angular velocity of the hand joint with respect to the corresponding XrHandJointsLocateInfoEXT::baseSpace. The vector’s direction is expressed in the reference frame of the corresponding XrHandJointsLocateInfoEXT::baseSpace and is parallel to the rotational axis of the hand joint. The vector’s magnitude is the relative angular speed of the hand joint in radians per second. The vector follows the right-hand rule for torque/rotation. /// public XrVector3f angularVelocity; } /// /// The application can chain an XrHandJointVelocitiesEXT structure to the next pointer of XrHandJointLocationsEXT when calling xrLocateHandJointsEXT to retrieve the hand joint velocities. /// public struct XrHandJointVelocitiesEXT { /// /// The XrStructureType of this structure. /// public XrStructureType type; /// /// NULL or a pointer to the next structure in a structure chain. No such structures are defined in core OpenXR or this extension. /// public IntPtr next; /// /// A uint32_t describing the number of elements in jointVelocities array. /// UInt32 jointCount; /// /// An array of XrHandJointVelocityEXT receiving the returned hand joint velocities. /// IntPtr jointVelocities; //XrHandJointVelocityEXT* } /// /// XrHandJointLocationsEXT structure returns the state of the hand joint locations. /// public struct XrHandJointLocationsEXT { /// /// The XrStructureType of this structure. /// public XrStructureType type; /// /// NULL or a pointer to the next structure in a structure chain, such as XrHandJointVelocitiesEXT. /// public IntPtr next; /// /// An XrBool32 indicating if the hand tracker is actively tracking. /// public XrBool32 isActive; /// /// A uint32_t describing the count of elements in jointLocations array. /// public UInt32 jointCount; /// /// An array of XrHandJointLocationEXT receiving the returned hand joint locations. /// public IntPtr jointLocations; //XrHandJointLocationEXT* /// The XrStructureType of this structure. /// NULL or a pointer to the next structure in a structure chain, such as XrHandJointVelocitiesEXT. /// An XrBool32 indicating if the hand tracker is actively tracking. /// A uint32_t describing the count of elements in jointLocations array. /// An array of XrHandJointLocationEXT receiving the returned hand joint locations. public XrHandJointLocationsEXT(XrStructureType in_type, IntPtr in_next, XrBool32 in_isActive, UInt32 in_jointCount, IntPtr in_jointLocations) { type = in_type; next = in_next; isActive = in_isActive; jointCount = in_jointCount; jointLocations = in_jointLocations; } } public static class ViveHandTrackingHelper { /// /// Defines the number of hand joint enumerants defined in XrHandJointEXT. /// public const int XR_HAND_JOINT_COUNT_EXT = 26; /// /// The function delegate of xrCreateHandTrackerEXT. /// /// An XrSession in which the hand tracker will be active. /// The XrHandTrackerCreateInfoEXT used to specify the hand tracker. /// The returned XrHandTrackerEXT handle. /// XR_SUCCESS for success. public delegate XrResult xrCreateHandTrackerEXTDelegate( XrSession session, ref XrHandTrackerCreateInfoEXT createInfo, out XrHandTrackerEXT handTracker); /// /// The function delegate of xrDestroyHandTrackerEXT. /// /// An XrHandTrackerEXT previously created by xrCreateHandTrackerEXT. /// XR_SUCCESS for success. public delegate XrResult xrDestroyHandTrackerEXTDelegate( XrHandTrackerEXT handTracker); /// /// The function delegate of xrLocateHandJointsEXT. /// /// An XrHandTrackerEXT previously created by xrCreateHandTrackerEXT. /// A pointer to XrHandJointsLocateInfoEXT describing information to locate hand joints. /// A pointer to XrHandJointLocationsEXT receiving the returned hand joint locations. /// public delegate XrResult xrLocateHandJointsEXTDelegate( XrHandTrackerEXT handTracker, XrHandJointsLocateInfoEXT locateInfo, ref XrHandJointLocationsEXT locations); } }