// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using UnityEngine;
namespace Microsoft.MixedReality.Toolkit.Utilities
{
///
/// A simple line with two points.
///
[AddComponentMenu("Scripts/MRTK/Core/SimpleLineDataProvider")]
public class SimpleLineDataProvider : BaseMixedRealityLineDataProvider
{
[Tooltip("The starting point of this line.")]
[SerializeField]
private MixedRealityPose startPoint = MixedRealityPose.ZeroIdentity;
///
/// The starting point of this line which is always located at the GameObject's transform position
///
/// Always located at this GameObject's Transform.position
public MixedRealityPose StartPoint => startPoint;
[SerializeField]
[Tooltip("The point where this line will end.\nNote: Start point is always located at the GameObject's transform position.")]
private MixedRealityPose endPoint = new MixedRealityPose(Vector3.right, Quaternion.identity);
///
/// The point where this line will end.
///
public MixedRealityPose EndPoint
{
get => endPoint;
set => endPoint = value;
}
#region Line Data Provider Implementation
///
public override int PointCount => 2;
///
protected override Vector3 GetPointInternal(int pointIndex)
{
switch (pointIndex)
{
case 0:
return StartPoint.Position;
case 1:
return EndPoint.Position;
default:
Debug.LogError("Invalid point index");
return Vector3.zero;
}
}
///
protected override void SetPointInternal(int pointIndex, Vector3 point)
{
switch (pointIndex)
{
case 0:
startPoint.Position = point;
break;
case 1:
endPoint.Position = point;
break;
default:
Debug.LogError("Invalid point index");
break;
}
}
///
protected override Vector3 GetPointInternal(float normalizedDistance)
{
return Vector3.Lerp(StartPoint.Position, EndPoint.Position, normalizedDistance);
}
///
protected override float GetUnClampedWorldLengthInternal()
{
return Vector3.Distance(StartPoint.Position, EndPoint.Position);
}
///
protected override Vector3 GetUpVectorInternal(float normalizedLength)
{
return transform.up;
}
#endregion Line Data Provider Implementation
}
}