forked from microsoft/MixedRealityToolkit-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector3Interpolated.cs
More file actions
91 lines (79 loc) · 2.55 KB
/
Vector3Interpolated.cs
File metadata and controls
91 lines (79 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
//
using UnityEngine;
namespace HoloToolkit.Unity
{
/// <summary>
/// Class to encapsulate an interpolating Vector3 property.
/// TODO: Remove if reduncatnt to InterpolatedVector3.cs
/// </summary>
public class Vector3Interpolated
{
/// <summary>
/// Half-life used to control how fast values are interpolated.
/// </summary>
public float HalfLife = 0.08f;
/// <summary>
/// Current value of the property.
/// </summary>
public Vector3 Value { get; private set; }
/// <summary>
/// Target value of the property.
/// </summary>
public Vector3 TargetValue { get; private set; }
public Vector3Interpolated()
{
Reset(Vector3.zero);
}
public Vector3Interpolated(Vector3 initialValue)
{
Reset(initialValue);
}
/// <summary>
/// Resets property to zero interpolation and set value.
/// </summary>
/// <param name="value">Desired value to reset</param>
public void Reset(Vector3 value)
{
Value = value;
TargetValue = value;
}
/// <summary>
/// Set a target for property to interpolate to.
/// </summary>
/// <param name="targetValue">Targeted value.</param>
public void SetTarget(Vector3 targetValue)
{
TargetValue = targetValue;
}
/// <summary>
/// Returns whether there are further updates required to get the target value.
/// </summary>
/// <returns>True if updates are required. False otherwise.</returns>
public bool HasUpdate()
{
return TargetValue != Value;
}
/// <summary>
/// Performs and gets the updated value.
/// </summary>
/// <param name="deltaTime">Tick delta.</param>
/// <returns>Updated value.</returns>
public Vector3 GetUpdate(float deltaTime)
{
Vector3 distance = (TargetValue - Value);
if (distance.sqrMagnitude <= Mathf.Epsilon)
{
// When close enough, jump to the target
Value = TargetValue;
}
else
{
Value = InterpolationUtilities.ExpDecay(Value, TargetValue, HalfLife, deltaTime);
}
return Value;
}
}
}