using System;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.Scripting;
using TrackingState = UnityEngine.XR.InputTrackingState;
namespace UnityEngine.XR.OpenXR.Input
{
///
/// Represents a tracked object in real-world space. All poses are given in the same root space, dictated by .
///
#if USE_INPUT_SYSTEM_POSE_CONTROL
[Obsolete("OpenXR.Input.Pose is deprecated, Please use UnityEngine.InputSystem.XR.PoseState instead", false)]
#endif
public struct Pose
{
///
/// If true, this position is being accurately tracked in real-world space. This value means that no values are estimated and tracking is not currently inhibited in any way.
///
public bool isTracked { get; set; }
///
/// A series of flags that identify which tracking values currently have data. That data can be measured by the real world or estimated when tracking is inhibited.
///
public TrackingState trackingState { get; set; }
///
/// The position, in meters, of the object in real-world space. This will be available if contains the flag.
///
public Vector3 position { get; set; }
///
/// The rotation, in radians, of the object in real-world space. This will be available if contains the flag.
///
public Quaternion rotation { get; set; }
///
/// The velocity, in meters per second, of the object in real-world space. This will be available if contains the flag.
///
public Vector3 velocity { get; set; }
///
/// The position, in radians per second, of the object in-real world space. This will be available if contains the flag.
///
public Vector3 angularVelocity { get; set; }
}
///
/// Input System control that wraps up a structure. All individual pose elements can be referenced separately. See for more details.
///
#if USE_INPUT_SYSTEM_POSE_CONTROL
[Obsolete("OpenXR.Input.PoseControl is deprecated. Please use UnityEngine.InputSystem.XR.PoseControl instead.", false)]
#endif
public class PoseControl : InputControl
{
///
/// Separate access to the value.
///
[Preserve]
[InputControl(offset = 0)]
public ButtonControl isTracked { get; private set; }
///
/// Separate access to the value.
///
[Preserve]
[InputControl(offset = 4)]
public IntegerControl trackingState { get; private set; }
///
/// Separate access to the value.
///
[Preserve]
[InputControl(offset = 8, noisy = true)]
public Vector3Control position { get; private set; }
///
/// Separate access to the value.
///
[Preserve]
[InputControl(offset = 20, noisy = true)]
public QuaternionControl rotation { get; private set; }
///
/// Separate access to the value.
///
[Preserve]
[InputControl(offset = 36, noisy = true)]
public Vector3Control velocity { get; private set; }
///
/// Separate access to the value.
///
[Preserve]
[InputControl(offset = 48, noisy = true)]
public Vector3Control angularVelocity { get; private set; }
///
/// Default Constructor required by the Input System for instantiation.
///
public PoseControl()
{ }
///
/// See [InputControl.FinishSetup](xref:UnityEngine.InputSystem.InputControl.FinishSetup)
///
protected override void FinishSetup()
{
isTracked = GetChildControl("isTracked");
trackingState = GetChildControl("trackingState");
position = GetChildControl("position");
rotation = GetChildControl("rotation");
velocity = GetChildControl("velocity");
angularVelocity = GetChildControl("angularVelocity");
base.FinishSetup();
}
///
/// Read unprocessed state values from the input control state.
///
/// State data to read from.
/// The pose data from the unprocessed state.
public override unsafe Pose ReadUnprocessedValueFromState(void* statePtr)
{
return new Pose()
{
isTracked = isTracked.ReadUnprocessedValueFromState(statePtr) > 0.5f,
trackingState = (TrackingState)trackingState.ReadUnprocessedValueFromState(statePtr),
position = position.ReadUnprocessedValueFromState(statePtr),
rotation = rotation.ReadUnprocessedValueFromState(statePtr),
velocity = velocity.ReadUnprocessedValueFromState(statePtr),
angularVelocity = angularVelocity.ReadUnprocessedValueFromState(statePtr),
};
}
///
/// Write value data into input control state.
///
/// The value to write into the control state.
/// A pointer to the control state data.
public override unsafe void WriteValueIntoState(Pose value, void* statePtr)
{
isTracked.WriteValueIntoState(value.isTracked, statePtr);
trackingState.WriteValueIntoState((uint)value.trackingState, statePtr);
position.WriteValueIntoState(value.position, statePtr);
rotation.WriteValueIntoState(value.rotation, statePtr);
velocity.WriteValueIntoState(value.velocity, statePtr);
angularVelocity.WriteValueIntoState(value.angularVelocity, statePtr);
}
}
}