AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
Parabola.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 System;
5 using UnityEngine;
6 
7 namespace HoloToolkit.Unity.UX
8 {
9  public class Parabola : LineBase
10  {
11  [Header("Parabola Settings")]
12  public Vector3 Start = Vector3.zero;
13  public Vector3 End = Vector3.forward;
14  public Vector3 UpDirection = Vector3.up;
15  [Range(0.01f, 10f)]
16  public float Height = 1f;
17 
18  public override int NumPoints
19  {
20  get
21  {
22  return 2;
23  }
24  }
25 
26  protected override Vector3 GetPointInternal(int pointIndex)
27  {
28  switch (pointIndex)
29  {
30  case 0:
31  return Start;
32 
33  case 1:
34  return End;
35 
36  default:
37  return Vector3.zero;
38  }
39  }
40 
41  protected override void SetPointInternal(int pointIndex, Vector3 point)
42  {
43  switch (pointIndex)
44  {
45  case 0:
46  Start = point;
47  break;
48 
49  case 1:
50  End = point;
51  break;
52 
53  default:
54  break;
55  }
56  }
57 
58  protected override Vector3 GetPointInternal(float normalizedDistance)
59  {
60  return LineUtils.GetPointAlongParabola(Start, End, UpDirection, Height, normalizedDistance);
61  }
62 
63  protected override float GetUnclampedWorldLengthInternal()
64  {
65  // Crude approximation
66  // TODO optimize
67  float distance = 0f;
68  Vector3 last = GetUnclampedPoint(0f);
69  for (int i = 1; i < 10; i++)
70  {
71  Vector3 current = GetUnclampedPoint((float)i / 10);
72  distance += Vector3.Distance(last, current);
73  }
74  return distance;
75  }
76 
77  protected override Vector3 GetUpVectorInternal(float normalizedLength)
78  {
79  return transform.up;
80  }
81 
82 #if UNITY_EDITOR
83  [UnityEditor.CustomEditor(typeof(Parabola))]
84  public class CustomEditor : LineBaseEditor
85  {
86  protected override void DrawCustomSceneGUI()
87  {
88  base.DrawCustomSceneGUI();
89 
90  Parabola line = (Parabola)target;
91 
92  line.FirstPoint = SquareMoveHandle(line.FirstPoint);
93  line.LastPoint = SquareMoveHandle(line.LastPoint);
94  // Draw a handle for the parabola height
95  line.Height = AxisMoveHandle(line.FirstPoint, line.transform.up, line.Height);
96  }
97  }
98 #endif
99  }
100 }
override Vector3 GetPointInternal(int pointIndex)
Get a point based on point index Point index will be pre-clamped
Definition: Parabola.cs:26
override Vector3 GetPointInternal(float normalizedDistance)
Get a point based on normalized distance along line Normalized distance will be pre-clamped ...
Definition: Parabola.cs:58
override void SetPointInternal(int pointIndex, Vector3 point)
Definition: Parabola.cs:41
override float GetUnclampedWorldLengthInternal()
Get the UNCLAMPED world length of the line
Definition: Parabola.cs:63
override Vector3 GetUpVectorInternal(float normalizedLength)
Gets the up vector at a normalized length along line (used for rotation)
Definition: Parabola.cs:77
static Vector3 GetPointAlongParabola(Vector3 start, Vector3 end, Vector3 up, float height, float normalizedLength)
Definition: LineUtility.cs:154