Tanoda
Plugins/LeapMotion/Modules/InteractionEngine/Scripts/Utility/Extensions.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
10using System;
11using System.Collections;
12using System.Collections.Generic;
13using UnityEngine;
14
15namespace Leap.Unity.Interaction {
16
17 #region IInteractionBehaviour
18
19 public static class IInteractionBehaviourExtensions {
20
21 public static bool ShouldIgnoreHover(this IInteractionBehaviour intObj, InteractionController controller) {
22 switch (intObj.ignoreHoverMode) {
23 case IgnoreHoverMode.None: return false;
24 case IgnoreHoverMode.Left: return !controller.isTracked || controller.isLeft;
25 case IgnoreHoverMode.Right: return !controller.isTracked || controller.isRight;
26 case IgnoreHoverMode.Both: default: return true;
27 }
28 }
29
30 }
31
32 #endregion
33
34 #region Vector3
35
36 public static class Vector3Extensions {
37
38 public static Vector3 ConstrainToSegment(this Vector3 position, Vector3 a, Vector3 b) {
39 Vector3 ba = b - a;
40 return Vector3.Lerp(a, b, Vector3.Dot(position - a, ba) / ba.sqrMagnitude);
41 }
42
43 public static float LargestComp(this Vector3 v) {
44 return Mathf.Max(Mathf.Max(v.x, v.y), v.z);
45 }
46
47 public static int LargestCompIdx(this Vector3 v) {
48 return v.x > v.y ?
49 v.x > v.z ?
50 0 // x > y, x > z
51 : 2 // x > y, z > x
52 : v.y > v.z ?
53 1 // y > x, y > z
54 : 2; // y > x, z > y
55 }
56
57 public static Vector3 Abs(this Vector3 v) {
58 return new Vector3(Mathf.Abs(v.x), Mathf.Abs(v.y), Mathf.Abs(v.z));
59 }
60
61 }
62
63 #endregion
64
65}
IgnoreHoverMode
Specified on a per-object basis to allow Interaction objects to ignore hover for the left hand,...