AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
DistorterWiggly.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 DistorterWiggly : Distorter
9  {
10  public const float MinScaleMultiplier = 0.05f;
11  public const float MaxScaleMultiplier = 1f;
12  public const float MinSpeedMultiplier = -25f;
13  public const float MaxSpeedMultiplier = 25f;
14  public const float MinStrengthMultiplier = 0.00001f;
15  public const float MaxStrengthMultiplier = 1f;
16 
17  const float GlobalScale = 0.1f;
18 
19  [Range(MinScaleMultiplier, MaxScaleMultiplier)]
20  public float ScaleMultiplier = 0.1f;
21  [Range(MinSpeedMultiplier, MaxSpeedMultiplier)]
22  public float SpeedMultiplier = 3f;
23  [Range(MinStrengthMultiplier, MaxStrengthMultiplier)]
24  public float StrengthMultiplier = 0.01f;
25  public Vector3 AxisStrength = new Vector3(0.5f, 0.1f, 0.5f);
26  public Vector3 AxisSpeed = new Vector3(0.2f, 0.5f, 0.7f);
27  public Vector3 AxisOffset = new Vector3(0.2f, 0.5f, 0.7f);
28 
29  protected override Vector3 DistortPointInternal(Vector3 point, float strength)
30  {
31  Vector3 wiggly = point;
32  float scale = ScaleMultiplier * GlobalScale;
33  wiggly.x = Wiggle(AxisSpeed.x * SpeedMultiplier, (wiggly.x + AxisOffset.x) / scale, AxisStrength.x * StrengthMultiplier);
34  wiggly.y = Wiggle(AxisSpeed.y * SpeedMultiplier, (wiggly.y + AxisOffset.y) / scale, AxisStrength.y * StrengthMultiplier);
35  wiggly.z = Wiggle(AxisSpeed.z * SpeedMultiplier, (wiggly.z + AxisOffset.z) / scale, AxisStrength.z * StrengthMultiplier);
36  return point + (wiggly * strength);
37  }
38 
39  protected override Vector3 DistortScaleInternal(Vector3 point, float strength)
40  {
41  return point;
42  }
43 
44  private float Wiggle(float speed, float offset, float strength)
45  {
46  return Mathf.Sin((Time.unscaledTime * speed) + offset) * strength;
47  }
48  }
49 }
override Vector3 DistortPointInternal(Vector3 point, float strength)
Internal function where position distortion is done
override Vector3 DistortScaleInternal(Vector3 point, float strength)
Internal function where scale distortion is done