AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
TwoHandScaleLogic.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.Generic;
5 using UnityEngine;
6 
7 namespace HoloToolkit.Unity.InputModule.Utilities.Interactions
8 {
18  public class TwoHandScaleLogic
19  {
20  private Vector3 m_startObjectScale;
21  private float m_startHandDistanceMeters;
22 
28  public virtual void Setup(Dictionary<uint, Vector3> handsPressedMap, Transform manipulationRoot)
29  {
30  m_startHandDistanceMeters = GetMinDistanceBetweenHands(handsPressedMap);
31  m_startObjectScale = manipulationRoot.transform.localScale;
32  }
33 
39  public virtual Vector3 UpdateMap(Dictionary<uint, Vector3> handsPressedMap)
40  {
41  var ratioMultiplier = GetMinDistanceBetweenHands(handsPressedMap) / m_startHandDistanceMeters;
42  return m_startObjectScale * ratioMultiplier;
43  }
44 
45  private float GetMinDistanceBetweenHands(Dictionary<uint, Vector3> handsPressedMap)
46  {
47  var result = float.MaxValue;
48  Vector3[] handLocations = new Vector3[handsPressedMap.Values.Count];
49  handsPressedMap.Values.CopyTo(handLocations, 0);
50  for (int i = 0; i < handLocations.Length; i++)
51  {
52  for (int j = i + 1; j < handLocations.Length; j++)
53  {
54  var distance = Vector3.Distance(handLocations[i], handLocations[j]);
55  if (distance < result)
56  {
57  result = distance;
58  }
59  }
60  }
61  return result;
62  }
63  }
64 }
virtual void Setup(Dictionary< uint, Vector3 > handsPressedMap, Transform manipulationRoot)
Initialize system with source info from controllers/hands
virtual Vector3 UpdateMap(Dictionary< uint, Vector3 > handsPressedMap)
update Gameobject with new Scale state
Implements a scale logic that will scale an object based on the ratio of the distance between hands...