AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
Ellipse.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using UnityEngine;
5 
6 namespace HoloToolkit.Unity.UX
7 {
8  public class Ellipse : LineBase
9  {
10  const int MaxPoints = 2048;
11 
12  [Header ("Ellipse Settings")]
13  public int Resolution = 36;
14  public Vector2 Radius = new Vector2(1f, 1f);
15 
16  public override int NumPoints
17  {
18  get
19  {
20  Resolution = Mathf.Clamp(Resolution, 0, MaxPoints);
21  return Resolution;
22  }
23  }
24 
25  protected override Vector3 GetPointInternal(float normalizedDistance)
26  {
27  return LineUtils.GetEllipsePoint(Radius.x, Radius.y, normalizedDistance * 2f * Mathf.PI);
28  }
29 
30  protected override Vector3 GetPointInternal(int pointIndex)
31  {
32  float angle = ((float)pointIndex / Resolution) * 2f * Mathf.PI;
33  return LineUtils.GetEllipsePoint(Radius.x, Radius.y, angle);
34  }
35 
36  protected override void SetPointInternal(int pointIndex, Vector3 point)
37  {
38  // Does nothing for an ellipse
39  return;
40  }
41 
42  protected override float GetUnclampedWorldLengthInternal()
43  {
44  // Crude approximation
45  // TODO optimize
46  float distance = 0f;
47  Vector3 last = GetUnclampedPoint(0f);
48  for (int i = 1; i < 10; i++)
49  {
50  Vector3 current = GetUnclampedPoint((float)i / 10);
51  distance += Vector3.Distance(last, current);
52  }
53  return distance;
54  }
55 
56 #if UNITY_EDITOR
57  [UnityEditor.CustomEditor(typeof(Ellipse))]
58  public class CustomEditor : LineBaseEditor { }
59 #endif
60  }
61 }
override Vector3 GetPointInternal(int pointIndex)
Get a point based on point index Point index will be pre-clamped
Definition: Ellipse.cs:30
override void SetPointInternal(int pointIndex, Vector3 point)
Definition: Ellipse.cs:36
override float GetUnclampedWorldLengthInternal()
Get the UNCLAMPED world length of the line
Definition: Ellipse.cs:42
static Vector3 GetEllipsePoint(float radiusX, float radiusY, float angle)
Definition: LineUtility.cs:245
override Vector3 GetPointInternal(float normalizedDistance)
Get a point based on normalized distance along line Normalized distance will be pre-clamped ...
Definition: Ellipse.cs:25