Skip to content

Commit def648f

Browse files
Stephen HodgsonStephen Hodgson
authored andcommitted
Merge branch 'HTK-master' into HTK-local
2 parents 8b4b100 + 11f0e24 commit def648f

File tree

4 files changed

+45
-14
lines changed

4 files changed

+45
-14
lines changed

Assets/HoloToolkit-Examples/SpatialUnderstanding/SpatialUnderstanding-FeatureOverview/Scripts/AppState.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using HoloToolkit.Unity;
66
using System;
77
using HoloToolkit.Unity.InputModule;
8+
using HoloToolkit.Unity.SpatialMapping;
89

910
public class AppState : Singleton<AppState>, ISourceStateHandler, IInputClickHandler
1011
{

Assets/HoloToolkit/SpatialMapping/Scripts/TapToPlace.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ public class TapToPlace : MonoBehaviour, IInputClickHandler
4646
/// </summary>
4747
private SpatialMappingManager spatialMappingManager;
4848

49-
/// <summary>
50-
/// Keeps track of the relative position between the parent object to be moved and
51-
/// the current gameobject this script is attached to.
52-
/// </summary>
53-
private Vector3 parentPositionRelativeToChild;
54-
5549
public virtual void Start()
5650
{
5751
// Make sure we have all the components in the scene we need.
@@ -79,14 +73,12 @@ public virtual void Start()
7973

8074
if (PlaceParentOnTap)
8175
{
82-
if (ParentGameObjectToPlace != null && !gameObject.transform.IsChildOf(ParentGameObjectToPlace.transform))
76+
if (ParentGameObjectToPlace != null && !gameObject.transform.IsChildOf(ParentGameObjectToPlace.transform))
8377
{
8478
Debug.LogError("The specified parent object is not a parent of this object.");
8579
}
8680

8781
DetermineParent();
88-
89-
parentPositionRelativeToChild = gameObject.transform.position - ParentGameObjectToPlace.transform.position;
9082
}
9183
}
9284

@@ -117,7 +109,8 @@ public virtual void Update()
117109
if (PlaceParentOnTap)
118110
{
119111
// Place the parent object as well but keep the focus on the current game object
120-
ParentGameObjectToPlace.transform.position = hitInfo.point - parentPositionRelativeToChild;
112+
Vector3 currentMovement = hitInfo.point - gameObject.transform.position;
113+
ParentGameObjectToPlace.transform.position += currentMovement;
121114
ParentGameObjectToPlace.transform.rotation = toQuat;
122115
}
123116
else

Assets/HoloToolkit/Utilities/Editor/EditorGUILayoutExtensions.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace HoloToolkit.Unity
1010
{
1111
/// <summary>
12-
/// Extensions for the UnityEnditor.EditorGUILayout class.
12+
/// Extensions for the UnityEditor.EditorGUILayout class.
1313
/// </summary>
1414
public static class EditorGUILayoutExtensions
1515
{
@@ -40,10 +40,16 @@ public static void Label(string text, GUIStyle style, params GUILayoutOption[] o
4040
EditorGUILayout.EndHorizontal();
4141
}
4242

43-
public static T ObjectField<T>(GUIContent guiContent, T value, bool allowSceneObjects, GUILayoutOption[] guiLayoutOptions = null)
43+
public static T ObjectField<T>(GUIContent guiContent, T value, bool allowSceneObjects = false, GUILayoutOption[] guiLayoutOptions = null)
4444
{
4545
object objValue = value;
4646

47+
if (objValue == null)
48+
{
49+
// We want to return null so we can display our blank field.
50+
return (T)objValue;
51+
}
52+
4753
Type valueType = objValue.GetType();
4854
if (valueType == typeof(Material))
4955
{
@@ -70,4 +76,4 @@ public static T ObjectField<T>(GUIContent guiContent, T value, bool allowSceneOb
7076
return (T)objValue;
7177
}
7278
}
73-
}
79+
}

Assets/HoloToolkit/Utilities/Scripts/Extensions/VectorExtensions.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
using System.Collections.Generic;
5+
using System.Linq;
46
using UnityEngine;
57

68
namespace HoloToolkit.Unity
@@ -50,5 +52,34 @@ public static Vector3 InverseTransformPoint(this Vector3 point, Vector3 translat
5052
var scaleInv = new Vector3(1 / lossyScale.x, 1 / lossyScale.y, 1 / lossyScale.z);
5153
return Vector3.Scale(scaleInv, (Quaternion.Inverse(rotation) * (point - translation)));
5254
}
55+
56+
public static Vector3 Average(ICollection<Vector3> vectors)
57+
{
58+
if (vectors.Count == 0)
59+
{
60+
return Vector3.zero;
61+
}
62+
63+
var x = 0f;
64+
var y = 0f;
65+
var z = 0f;
66+
foreach (var pos in vectors)
67+
{
68+
x += pos.x;
69+
y += pos.y;
70+
z += pos.z;
71+
}
72+
return new Vector3(x / vectors.Count, y / vectors.Count, z / vectors.Count);
73+
}
74+
75+
public static Vector3 Median(ICollection<Vector3> vectors)
76+
{
77+
if (vectors.Count == 0)
78+
{
79+
return Vector3.zero;
80+
}
81+
82+
return vectors.OrderBy(v => v.sqrMagnitude).ElementAt(vectors.Count / 2);
83+
}
5384
}
54-
}
85+
}

0 commit comments

Comments
 (0)