AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
DistorterGravity.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.Collections;
5 using System.Collections.Generic;
6 using UnityEngine;
7 
8 namespace HoloToolkit.Unity.UX
9 {
10  public class DistorterGravity : Distorter
11  {
12  public Vector3 WorldCenterOfGravity
13  {
14  get
15  {
16  return transform.TransformPoint(LocalCenterOfGravity);
17  }
18  set
19  {
20  LocalCenterOfGravity = transform.InverseTransformPoint(value);
21  }
22  }
23 
24  public Vector3 LocalCenterOfGravity;
25  public Vector3 AxisStrength = Vector3.one;
26  [Range(0f, 10f)]
27  public float Radius = 0.5f;
28  public AnimationCurve GravityStrength = AnimationCurve.EaseInOut(0, 0, 1, 1);
29 
30  protected override Vector3 DistortPointInternal(Vector3 point, float strength)
31  {
32  Vector3 target = WorldCenterOfGravity;
33 
34  float normalizedDistance = 1f - Mathf.Clamp01 (Vector3.Distance(point, target) / Radius);
35 
36  strength *= GravityStrength.Evaluate (normalizedDistance);
37 
38  point.x = Mathf.Lerp(point.x, target.x, Mathf.Clamp01(strength * AxisStrength.x));
39  point.y = Mathf.Lerp(point.y, target.y, Mathf.Clamp01(strength * AxisStrength.y));
40  point.z = Mathf.Lerp(point.z, target.z, Mathf.Clamp01(strength * AxisStrength.z));
41 
42  return point;
43  }
44 
45  protected override Vector3 DistortScaleInternal(Vector3 point, float strength)
46  {
47  return point;
48  }
49 
50  public void OnDrawGizmos()
51  {
52  Gizmos.color = Color.red;
53  Gizmos.DrawSphere(WorldCenterOfGravity, 0.05f);
54  Gizmos.DrawWireSphere(WorldCenterOfGravity, Radius);
55  }
56  }
57 }
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