// Copyright HTC Corporation All Rights Reserved.
using System;
using System.Runtime.InteropServices;
namespace VIVE.OpenXR.EyeTracker
{
///
/// The XrEyeTrackerHTC handle represents the resources for eye tracking.
///
public struct XrEyeTrackerHTC : IEquatable
{
private readonly UInt64 value;
public XrEyeTrackerHTC(UInt64 u)
{
value = u;
}
public static implicit operator UInt64(XrEyeTrackerHTC equatable)
{
return equatable.value;
}
public static implicit operator XrEyeTrackerHTC(UInt64 u)
{
return new XrEyeTrackerHTC(u);
}
public bool Equals(XrEyeTrackerHTC other)
{
return value == other.value;
}
public bool Equals(UInt64 other)
{
return value == other;
}
public override bool Equals(object obj)
{
return obj is XrEyeTrackerHTC && Equals((XrEyeTrackerHTC)obj);
}
public override int GetHashCode()
{
return value.GetHashCode();
}
public override string ToString()
{
return value.ToString();
}
public static bool operator ==(XrEyeTrackerHTC a, XrEyeTrackerHTC b) { return a.Equals(b); }
public static bool operator !=(XrEyeTrackerHTC a, XrEyeTrackerHTC b) { return !a.Equals(b); }
public static bool operator >=(XrEyeTrackerHTC a, XrEyeTrackerHTC b) { return a.value >= b.value; }
public static bool operator <=(XrEyeTrackerHTC a, XrEyeTrackerHTC b) { return a.value <= b.value; }
public static bool operator >(XrEyeTrackerHTC a, XrEyeTrackerHTC b) { return a.value > b.value; }
public static bool operator <(XrEyeTrackerHTC a, XrEyeTrackerHTC b) { return a.value < b.value; }
public static XrEyeTrackerHTC operator +(XrEyeTrackerHTC a, XrEyeTrackerHTC b) { return a.value + b.value; }
public static XrEyeTrackerHTC operator -(XrEyeTrackerHTC a, XrEyeTrackerHTC b) { return a.value - b.value; }
public static XrEyeTrackerHTC operator *(XrEyeTrackerHTC a, XrEyeTrackerHTC b) { return a.value * b.value; }
public static XrEyeTrackerHTC operator /(XrEyeTrackerHTC a, XrEyeTrackerHTC b)
{
if (b.value == 0)
{
throw new DivideByZeroException();
}
return a.value / b.value;
}
}
///
/// The XrEyePositionHTC describes which eye is under tracking for the data retrieved from XrEyeGazeDataHTC, XrEyePupilDataHTC or XrEyeGeometricDataHTC.
///
public enum XrEyePositionHTC
{
///
/// Specifies the position of the left eye.
///
XR_EYE_POSITION_LEFT_HTC = 0,
///
/// Specifies the position of the right eye.
///
XR_EYE_POSITION_RIGHT_HTC = 1,
XR_EYE_POSITION_COUNT_HTC = 2
};
///
/// An application can inspect whether the system is capable of eye tracking input by extending the XrSystemProperties with XrSystemEyeTrackingPropertiesHTC structure when calling xrGetSystemProperties.
///
[StructLayout(LayoutKind.Sequential)]
public struct XrSystemEyeTrackingPropertiesHTC
{
///
/// 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;
///
/// Indicating if the current system is capable of receiving eye tracking input.
///
public XrBool32 supportsEyeTracking;
};
///
/// The XrEyeTrackerCreateInfoHTC structure describes the information to create an XrEyeTrackerHTC handle.
///
[StructLayout(LayoutKind.Sequential)]
public struct XrEyeTrackerCreateInfoHTC
{
///
/// 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;
/// 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.
public XrEyeTrackerCreateInfoHTC(XrStructureType in_type, IntPtr in_next)
{
type = in_type;
next = in_next;
}
};
///
/// The XrEyeGazeDataInfoHTC structure describes the information to get eye gaze directions.
///
[StructLayout(LayoutKind.Sequential)]
public struct XrEyeGazeDataInfoHTC
{
///
/// 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 eye poses will be represented.
///
public XrSpace baseSpace;
///
/// An XrTime at which the eye gaze information is requested.
///
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 eye poses will be represented.
/// An XrTime at which the eye gaze information is requested.
public XrEyeGazeDataInfoHTC(XrStructureType in_type, IntPtr in_next, XrSpace in_baseSpace, XrTime in_time)
{
type = in_type;
next = in_next;
baseSpace = in_baseSpace;
time = in_time;
}
};
///
/// The XrSingleEyeGazeDataHTC structure describes the validity and direction of a eye gaze observation.
///
[StructLayout(LayoutKind.Sequential)]
public struct XrSingleEyeGazeDataHTC
{
///
/// An XrBool32 indicating if the returned gazePose is valid. Callers should check the validity of pose prior to use.
///
public XrBool32 isValid;
///
/// An XrPosef describing the position and orientation of the user's eye. The pose is represented in the coordinate system provided by XrEyeGazeDataInfoHTC::baseSpace.
///
public XrPosef gazePose;
/// An XrBool32 indicating if the returned gazePose is valid. Callers should check the validity of pose prior to use.
/// An XrPosef describing the position and orientation of the user's eye. The pose is represented in the coordinate system provided by XrEyeGazeDataInfoHTC::baseSpace.
public XrSingleEyeGazeDataHTC(XrBool32 in_isValid, XrPosef in_gazePose)
{
isValid = in_isValid;
gazePose = in_gazePose;
}
};
///
/// The XrEyeGazeDataHTC structure returns the state of the eye gaze directions.
///
[StructLayout(LayoutKind.Sequential)]
public struct XrEyeGazeDataHTC
{
///
/// 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 XrTime at which the eye gaze information is requested.
///
public XrTime time;
///
/// An array of XrSingleEyeGazeDataHTC receiving the returned eye gaze directions.
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public XrSingleEyeGazeDataHTC[] gaze;
};
///
/// The XrEyePupilDataInfoHTC structure describes the information to get pupil data.
///
[StructLayout(LayoutKind.Sequential)]
public struct XrEyePupilDataInfoHTC
{
///
/// 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;
/// 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.
public XrEyePupilDataInfoHTC(XrStructureType in_type, IntPtr in_next)
{
type = in_type;
next = in_next;
}
};
///
/// The XrSingleEyePupilDataHTC structure describes the validity, diameter and position of a pupil observation.
///
[StructLayout(LayoutKind.Sequential)]
public struct XrSingleEyePupilDataHTC
{
///
/// An XrBool32 indicating if the returned pupilDiameter is valid. Callers should check the validity of diameter prior to use.
///
public XrBool32 isDiameterValid;
///
/// An XrBool32 indicating if the returned pupilPosition is valid. Callers should check the validity of position prior to use.
///
public XrBool32 isPositionValid;
///
/// The diameter of pupil in millimeters.
///
public float pupilDiameter;
///
/// The position of pupil in sensor area which x and y are normalized in [0,1] with +Y up and +X to the right.
///
public XrVector2f pupilPosition;
/// An XrBool32 indicating if the returned gazePose is valid. Callers should check the validity of pose prior to use.
/// An XrBool32 indicating if the returned pupilPosition is valid. Callers should check the validity of position prior to use.
/// The diameter of pupil in millimeters.
/// The position of pupil in sensor area which x and y are normalized in [0,1]with +Y up and +X to the right.
public XrSingleEyePupilDataHTC(XrBool32 in_isDiameterValid, XrBool32 in_isPositionValid, float in_pupilDiameter, XrVector2f in_pupilPosition)
{
isDiameterValid = in_isDiameterValid;
isPositionValid = in_isPositionValid;
pupilDiameter = in_pupilDiameter;
pupilPosition = in_pupilPosition;
}
};
///
/// The XrEyePupilDataHTC structure returns the pupil data.
///
[StructLayout(LayoutKind.Sequential)]
public struct XrEyePupilDataHTC
{
///
/// 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 XrTime at which the pupil data was captured.
///
public XrTime time;
///
/// An array of XrSingleEyePupilDataHTC receiving the returned pupil data.
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public XrSingleEyePupilDataHTC[] pupilData;
};
///
/// The XrEyeGeometricDataInfoHTC structure describes the information to get geometric related data.
///
[StructLayout(LayoutKind.Sequential)]
public struct XrEyeGeometricDataInfoHTC
{
///
/// 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;
/// 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.
public XrEyeGeometricDataInfoHTC(XrStructureType in_type, IntPtr in_next)
{
type = in_type;
next = in_next;
}
};
///
/// The XrSingleEyeGeometricDataHTC structure describes the geometric related data.
///
[StructLayout(LayoutKind.Sequential)]
public struct XrSingleEyeGeometricDataHTC
{
///
/// A flag that indicates if the geometric data is valid. Callers should check the validity of the geometric data prior to use.
///
public XrBool32 isValid;
///
/// A value in range [0,1] representing the openness of the user's eye. When this value is zero, the eye closes normally. When this value is one, the eye opens normally. When this value goes higher, the eye approaches open.
///
public float eyeOpenness;
///
/// A value in range [0,1] representing how the user's eye open widely. When this value is zero, the eye opens normally. When this value goes higher, the eye opens wider.
public float eyeWide;
///
/// A value in range [0,1] representing how the user's eye is closed. When this value is zero, the eye closes normally. When this value goes higher, the eye closes tighter.
///
public float eyeSqueeze;
/// A flag that indicates if the geometric data is valid. Callers should check the validity of the geometric data prior to use.
/// A value in range [0,1] representing the openness of the user's eye. When this value is zero, the eye closes normally. When this value is one, the eye opens normally. When this value goes higher, the eye approaches open.
/// A value in range [0,1] representing how the user's eye open widely. When this value is zero, the eye opens normally. When this value goes higher, the eye opens wider.
/// A value in range [0,1] representing how the user's eye is closed. When this value is zero, the eye closes normally. When this value goes higher, the eye closes tighter.
public XrSingleEyeGeometricDataHTC(XrBool32 in_isValid, float in_eyeOpenness, float in_eyeWide, float in_eyeSqueeze)
{
isValid = in_isValid;
eyeOpenness = in_eyeOpenness;
eyeWide = in_eyeWide;
eyeSqueeze = in_eyeSqueeze;
}
};
[StructLayout(LayoutKind.Sequential)]
public struct XrEyeGeometricDataHTC
{
///
/// 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 XrTime at which the returned eye data is tracked.
///
public XrTime time;
///
/// An array of XrSingleEyeGeometricDataHTC receiving the returned eye geometric data.
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public XrSingleEyeGeometricDataHTC[] eyeGeometricData;
};
public static class ViveEyeTrackerHelper
{
/// An XrSession in which the eye tracker will be active.
/// The XrEyeTrackerCreateInfoHTC used to specify the eye tracker.
/// The returned XrEyeTrackerHTC handle.
/// XR_SUCCESS for success.
public delegate XrResult xrCreateEyeTrackerHTCDelegate(
XrSession session,
ref XrEyeTrackerCreateInfoHTC createInfo,
out XrEyeTrackerHTC eyeTracker);
/// An XrEyeTrackerHTC previously created by xrCreateEyeTrackerHTC.
/// XR_SUCCESS for success.
public delegate XrResult xrDestroyEyeTrackerHTCDelegate(
XrEyeTrackerHTC eyeTracker);
///
/// Retrieves the XrEyeGazeDataHTC data of a XrEyeTrackerHTC.
///
/// An XrEyeTrackerHTC previously created by xrCreateEyeTrackerHTC.
/// The information to get eye gaze.
/// A pointer to XrEyeGazeDataHTC receiving the returned eye poses.
/// XR_SUCCESS for success.
public delegate XrResult xrGetEyeGazeDataHTCDelegate(
XrEyeTrackerHTC eyeTracker,
ref XrEyeGazeDataInfoHTC gazeInfo,
ref XrEyeGazeDataHTC eyeGazes);
/// An XrEyeTrackerHTC previously created by xrCreateEyeTrackerHTC.
/// The information to get pupil data.
/// A pointer to XrEyePupilDataHTC returned by the runtime.
/// XR_SUCCESS for success.
public delegate XrResult xrGetEyePupilDataHTCDelegate(
XrEyeTrackerHTC eyeTracker,
ref XrEyePupilDataInfoHTC pupilDataInfo,
ref XrEyePupilDataHTC pupilData);
/// An XrEyeTrackerHTC previously created by xrCreateEyeTrackerHTC.
/// A pointer to XrEyeGeometricDataInfoHTC structure.
/// A pointer to XrEyeGeometricDataHTC returned by the runtime.
/// XR_SUCCESS for success.
public delegate XrResult xrGetEyeGeometricDataHTC(
XrEyeTrackerHTC eyeTracker,
ref XrEyeGeometricDataInfoHTC info,
ref XrEyeGeometricDataHTC eyeGeometricData);
}
}