AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
QuaternionInterpolated.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
8 {
13  [Serializable]
15  {
19  public float DeltaSpeed = 360f;
20 
24  public Quaternion Value { get; private set; }
28  public Quaternion TargetValue { get; private set; }
29  public Quaternion StartValue { get; private set; }
30  public float Duration { get; private set; }
31  public float Counter { get; private set; }
32 
34  {
35  Reset(Quaternion.identity);
36  }
37 
38  public QuaternionInterpolated(Quaternion initialValue)
39  {
40  Reset(initialValue);
41  }
42 
47  public void Reset(Quaternion value)
48  {
49  Value = value;
50  TargetValue = value;
51  StartValue = value;
52  Duration = 0f;
53  Counter = 0f;
54  }
55 
60  public void SetTarget(Quaternion targetValue)
61  {
62  TargetValue = targetValue;
63  StartValue = Value;
64  Duration = Quaternion.Angle(StartValue, TargetValue) / DeltaSpeed;
65  Counter = 0f;
66  }
67 
72  public bool HasUpdate()
73  {
74  return Quaternion.Angle(TargetValue, Value) > 0.05f;
75  }
76 
82  public Quaternion GetUpdate(float deltaTime)
83  {
84  Counter += deltaTime;
85  Value = Quaternion.Slerp(StartValue, TargetValue, Counter / Duration);
86 
87  return Value;
88  }
89  }
90 }
void Reset(Quaternion value)
Resets property to zero interpolation and set value.
bool HasUpdate()
Returns whether there are further updates required to get the target value.
Quaternion GetUpdate(float deltaTime)
Performs and fets the updated value.
Class to encapsulate an interpolating Quaternion property. TODO: Remove if redundant to InterpolatedQ...
void SetTarget(Quaternion targetValue)
Set a target for property to interpolate to.