// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.XR.ARSubsystems;
using Pose = UnityEngine.Pose;
namespace Microsoft.MixedReality.OpenXR.ARSubsystems
{
///
/// The session-relative data associated with a marker.
/// Following design pattern set by
///
///
[StructLayout(LayoutKind.Sequential)]
public struct XRMarker : ITrackable
{
private static readonly XRMarker s_Default = new XRMarker(
TrackableId.invalidId,
Pose.identity,
TrackingState.None,
Vector2.zero,
Vector2.zero,
0.0f,
TransformMode.MostStable,
ARMarkerType.QRCode,
IntPtr.Zero);
///
/// Gets a default-initialized . This can be
/// different from the zero-initialized version, e.g., the
/// is Pose.identity instead of zero-initialized.
///
internal static XRMarker defaultValue => s_Default;
///
/// Constructs a new . This is just a data container
/// for a marker's session relative data. These are typically created by
/// .
///
/// The associated with the marker.
/// The Pose associated with the marker.
/// The associated with the marker.
/// The center of the marker, in marker space (relative to ).
/// The dimensions associated with the marker.
/// The time when the marker was last seen.
/// The type of the marker. Currently only markers of type QRCode are supported.
/// The native pointer associated with the marker.
internal XRMarker(
TrackableId trackableId,
Pose pose,
TrackingState trackingState,
Vector2 center,
Vector2 size,
float lastSeenTime,
TransformMode transformMode,
ARMarkerType markerType,
IntPtr nativePtr)
{
this.trackableId = trackableId;
this.pose = pose;
this.trackingState = trackingState;
this.center = center;
this.size = size;
this.lastSeenTime = lastSeenTime;
this.transformMode = transformMode;
this.markerType = markerType;
this.nativePtr = nativePtr;
}
///
/// The associated with this marker.
///
public TrackableId trackableId { get; }
///
/// The Pose, in session space, of the marker.
///
public Pose pose { get; internal set; }
///
/// The of the marker.
///
public TrackingState trackingState { get; internal set; }
///
/// The center of the marker in marker space (relative to its ).
///
public Vector2 center { get; internal set; }
///
/// The size (dimensions) of the marker in meters.
///
public Vector2 size { get; internal set; }
///
/// The time the marker was last seen.
///
public float lastSeenTime { get; internal set; }
///
/// The type of transform on the marker.
///
public TransformMode transformMode { get; internal set; }
///
/// The type of the marker. Currently we only support markers of type QRCode.
///
public ARMarkerType markerType { get; }
///
/// A native pointer associated with this marker.
/// The data pointer to by this pointer is implementation defined.
///
public IntPtr nativePtr { get; }
}
}