AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
Distorter.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 abstract class Distorter : MonoBehaviour, IComparable<Distorter>
10  {
11  [SerializeField]
12  [Range(0, 10)]
13  protected int distortOrder = 0;
14  [SerializeField]
15  [Range(0, 1)]
16  protected float distortStrength = 1f;
17 
18  public int CompareTo(Distorter other)
19  {
20  if (other == null) {
21  return 0;
22  }
23 
24  return DistortOrder.CompareTo(other.DistortOrder);
25  }
26 
34  public Vector3 DistortPoint (Vector3 point, float strength = 1f)
35  {
36  if (!isActiveAndEnabled) {
37  return point;
38  }
39 
40  strength = Mathf.Clamp01 (strength * DistortStrength);
41 
42  if (strength <= 0)
43  {
44  return point;
45  }
46 
47  return DistortPointInternal(point, strength);
48  }
49 
57  public Vector3 DistortScale(Vector3 scale, float strength = 1f)
58  {
59  if (!isActiveAndEnabled) {
60  return scale;
61  }
62 
63  strength = Mathf.Clamp01(strength * DistortStrength);
64 
65  return DistortScaleInternal(scale, strength);
66  }
67 
74  protected abstract Vector3 DistortPointInternal(Vector3 point, float strength);
75 
82  protected abstract Vector3 DistortScaleInternal(Vector3 point, float strength);
83 
84  protected virtual void OnEnable()
85  {
86  // Makes script enableable in editor
87  }
88 
89  protected virtual void OnDisable()
90  {
91  // Makes script enableable in editor
92  }
93 
94  public float DistortStrength
95  {
96  get { return distortStrength; }
97  set { distortStrength = Mathf.Clamp01(value); }
98  }
99 
100  public int DistortOrder
101  {
102  get { return distortOrder; }
103  set { distortOrder = value; } // TODO implement auto-sort
104  }
105  }
106 }
int CompareTo(Distorter other)
Definition: Distorter.cs:18
Vector3 DistortPoint(Vector3 point, float strength=1f)
Distorts a world-space point Automatically applies DistortStrength and ensures that strength never ex...
Definition: Distorter.cs:34
Vector3 DistortScale(Vector3 scale, float strength=1f)
Distorts a world-space scale Automatically applies DistortStrength and ensures that strength never ex...
Definition: Distorter.cs:57