AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
Vector3Interpolated.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
7 {
12  public class Vector3Interpolated
13  {
17  public float HalfLife = 0.08f;
18 
22  public Vector3 Value { get; private set; }
26  public Vector3 TargetValue { get; private set; }
27 
29  {
30  Reset(Vector3.zero);
31  }
32 
33  public Vector3Interpolated(Vector3 initialValue)
34  {
35  Reset(initialValue);
36  }
37 
42  public void Reset(Vector3 value)
43  {
44  Value = value;
45  TargetValue = value;
46  }
47 
52  public void SetTarget(Vector3 targetValue)
53  {
54  TargetValue = targetValue;
55  }
56 
61  public bool HasUpdate()
62  {
63  return TargetValue != Value;
64  }
65 
71  public Vector3 GetUpdate(float deltaTime)
72  {
73  Vector3 distance = (TargetValue - Value);
74 
75  if (distance.sqrMagnitude <= Mathf.Epsilon)
76  {
77  // When close enough, jump to the target
78  Value = TargetValue;
79  }
80  else
81  {
82  Value = InterpolationUtilities.ExpDecay(Value, TargetValue, HalfLife, deltaTime);
83  }
84 
85 
86  return Value;
87  }
88  }
89 }
bool HasUpdate()
Returns whether there are further updates required to get the target value.
void SetTarget(Vector3 targetValue)
Set a target for property to interpolate to.
Vector3 GetUpdate(float deltaTime)
Performs and gets the updated value.
Class to encapsulate an interpolating Vector3 property. TODO: Remove if redundant to InterpolatedVect...
Static class containing interpolation-related utility functions.
void Reset(Vector3 value)
Resets property to zero interpolation and set value.
static float ExpDecay(float from, float to, float hLife, float dTime)