Skip to content

Commit d2b2a33

Browse files
default / max tests wip
1 parent c428524 commit d2b2a33

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed

Assets/MixedRealityToolkit.SDK/Experimental/Features/UX/BoundsControl/Visuals/ProximityEffect/ProximityEffect.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,30 +137,37 @@ public void UpdateScaling(Vector3 boundsCenter, Vector3 boundsExtents)
137137
{
138138
foreach (var pointer in inputSource.Pointers)
139139
{
140-
if (pointer.IsInteractionEnabled && !proximityPointers.Contains(pointer))
140+
// don't use IsInteractionEnabled for near pointers as the pointers might have a different radius when deciding
141+
// if they can interact with a near-by object - we might still want to show proximity scaling even if
142+
// eg. grab pointer decides it's too far away to actually perform the interaction
143+
if (pointer.IsActive
144+
&& (pointer.IsInteractionEnabled || pointer is IMixedRealityNearPointer)
145+
&& !proximityPointers.Contains(pointer))
141146
{
142147
proximityPointers.Add(pointer);
143148
}
144149
}
145150
}
146151

147152
// Get the max radius possible of our current bounds plus the proximity
148-
float maxRadius = Mathf.Max(Mathf.Max(boundsExtents.x, boundsExtents.y), boundsExtents.z);
149-
maxRadius *= maxRadius;
150-
maxRadius += config.ObjectCloseProximity + config.ObjectMediumProximity;
153+
float squareMaxLength= boundsExtents.sqrMagnitude + (3 * config.ObjectMediumProximity * config.ObjectMediumProximity);
151154

152155
// Grab points within sphere of influence from valid pointers
153156
foreach (var pointer in proximityPointers)
154157
{
155-
if (IsPointWithinBounds(boundsCenter, pointer.Position, maxRadius))
158+
159+
if (IsPointWithinBounds(boundsCenter, pointer.Position, squareMaxLength))
156160
{
157161
proximityPoints.Add(pointer.Position);
158162
}
159-
160-
Vector3? point = pointer.Result?.Details.Point;
161-
if (point.HasValue && IsPointWithinBounds(boundsCenter, pointer.Result.Details.Point, maxRadius))
162-
{
163-
proximityPoints.Add(pointer.Result.Details.Point);
163+
164+
if (pointer.Result?.CurrentPointerTarget != null)
165+
{
166+
Vector3? point = pointer.Result?.Details.Point;
167+
if (point.HasValue && IsPointWithinBounds(boundsCenter, pointer.Result.Details.Point, squareMaxLength))
168+
{
169+
proximityPoints.Add(pointer.Result.Details.Point);
170+
}
164171
}
165172
}
166173

@@ -278,11 +285,11 @@ private bool IsPointWithinBounds(Vector3 position, Vector3 point, float radiusSq
278285
/// <returns>ProximityState for given distance</returns>
279286
private ProximityState GetProximityState(float sqrDistance)
280287
{
281-
if (sqrDistance < config.ObjectCloseProximity * config.ObjectCloseProximity)
288+
if (sqrDistance <= (config.ObjectCloseProximity * config.ObjectCloseProximity))
282289
{
283290
return ProximityState.CloseProximity;
284291
}
285-
else if (sqrDistance < config.ObjectMediumProximity * config.ObjectMediumProximity)
292+
else if (sqrDistance <= (config.ObjectMediumProximity * config.ObjectMediumProximity))
286293
{
287294
return ProximityState.MediumProximity;
288295
}

Assets/MixedRealityToolkit.Tests/PlayModeTests/Experimental/BoundsControlTests.cs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,12 @@ public IEnumerator ScaleHandlesOnProximity()
381381
proximityConfig.FarGrowRate = 1.0f;
382382
bbox.CreateRig();
383383
yield return null; // wait so rig gameobjects get recreated
384-
yield return TestCurrentProximityConfiguration(bbox, hand);
384+
yield return TestCurrentProximityConfiguration(bbox, hand, "Defaults");
385385

386386
// reset hand
387387
yield return hand.MoveTo(initialHandPosition);
388388

389-
//--- 3. now test custom configuration is applied during runtime
389+
//--- 3. now test custom configuration is applied during runtime - max proximity values
390390
proximityConfig.CloseScale = 4.0f;
391391
proximityConfig.MediumScale = 3.0f;
392392
proximityConfig.FarScale = 2.0f;
@@ -396,7 +396,18 @@ public IEnumerator ScaleHandlesOnProximity()
396396

397397
bbox.CreateRig();
398398
yield return null; // wait so rig gameobjects get recreated
399-
yield return TestCurrentProximityConfiguration(bbox, hand);
399+
yield return TestCurrentProximityConfiguration(bbox, hand, "Custom runtime config max");
400+
401+
// reset hand
402+
yield return hand.MoveTo(initialHandPosition);
403+
404+
//--- 4. custom config - min values
405+
proximityConfig.ObjectMediumProximity = 0.005f;
406+
proximityConfig.ObjectCloseProximity = 0.001f;
407+
408+
bbox.CreateRig();
409+
yield return null; // wait so rig gameobjects get recreated
410+
yield return TestCurrentProximityConfiguration(bbox, hand, "Custom runtime config min");
400411
}
401412

402413

@@ -405,49 +416,55 @@ public IEnumerator ScaleHandlesOnProximity()
405416
/// </summary>
406417
/// <param name="bbox">Bounds Control to test on</param>
407418
/// <param name="hand">Test hand to use for testing proximity to handle</param>
408-
private IEnumerator TestCurrentProximityConfiguration(BoundsControl bbox, TestHand hand)
419+
private IEnumerator TestCurrentProximityConfiguration(BoundsControl bbox, TestHand hand, string testDescription)
409420
{
421+
const float handOffset = 0.036718f; // TODO : THIS OFFSET IS STILL WRONG!
422+
410423
// get config and scaling handle
411424
ScaleHandlesConfiguration scaleHandleConfig = bbox.ScaleHandlesConfiguration;
412425
Vector3 defaultHandleSize = Vector3.one * scaleHandleConfig.HandleSize;
413426
Transform scaleHandle = bbox.gameObject.transform.Find("rigRoot/corner_3");
414427
Transform proximityScaledVisual = scaleHandle.GetChild(0)?.GetChild(0);
415428
var frontRightCornerPos = scaleHandle.position;
429+
// compensate for hand offset
430+
frontRightCornerPos.y += handOffset;
416431

417432
//yield return null;
418433

419434
// check far scale applied
420435
ProximityEffectConfiguration proximityConfig = bbox.HandleProximityEffectConfiguration;
421436
Vector3 expectedFarScale = defaultHandleSize * proximityConfig.FarScale;
422-
Assert.AreEqual(proximityScaledVisual.localScale, expectedFarScale, "Proximity far scale wasn't applied to handle");
437+
yield return PlayModeTestUtilities.WaitForEnterKey();
438+
Assert.AreEqual(proximityScaledVisual.localScale, expectedFarScale, testDescription + " - Proximity far scale wasn't applied to handle");
423439

424440
// move into medium range and check if scale was applied
425441
Vector3 mediumProximityTestDist = frontRightCornerPos;
426-
mediumProximityTestDist.x += (proximityConfig.ObjectMediumProximity);
442+
mediumProximityTestDist.x += proximityConfig.ObjectMediumProximity;
427443
yield return hand.MoveTo(mediumProximityTestDist, 50);
428444
yield return PlayModeTestUtilities.WaitForEnterKey();
429445
Vector3 expectedMediumScale = defaultHandleSize * proximityConfig.MediumScale;
430-
Assert.AreEqual(proximityScaledVisual.localScale, expectedMediumScale, "Proximity medium scale wasn't applied to handle");
446+
Assert.AreEqual(proximityScaledVisual.localScale, expectedMediumScale, testDescription + " - Proximity medium scale wasn't applied to handle");
431447

432448
// move into close scale range and check if scale was applied
433449
Vector3 closeProximityTestDir = frontRightCornerPos;
434450
closeProximityTestDir.x += proximityConfig.ObjectCloseProximity;
435451
yield return hand.MoveTo(closeProximityTestDir);
436452
Vector3 expectedCloseScale = defaultHandleSize * proximityConfig.CloseScale;
437-
Assert.AreEqual(proximityScaledVisual.localScale, expectedCloseScale, "Proximity close scale wasn't applied to handle");
453+
yield return PlayModeTestUtilities.WaitForEnterKey();
454+
Assert.AreEqual(proximityScaledVisual.localScale, expectedCloseScale, testDescription + " - Proximity close scale wasn't applied to handle");
438455

439-
const float moveOutOfScaleConstant = 0.01f;
456+
float moveOutOfScaleConstant = proximityConfig.ObjectCloseProximity;
440457
// move out of close scale again - should fall back to medium proximity
441458
closeProximityTestDir.x += moveOutOfScaleConstant;
442459
yield return hand.MoveTo(closeProximityTestDir);
443460
yield return PlayModeTestUtilities.WaitForEnterKey();
444-
Assert.AreEqual(proximityScaledVisual.localScale, expectedMediumScale, "Proximity medium scale wasn't applied to handle");
461+
Assert.AreEqual(proximityScaledVisual.localScale, expectedMediumScale, testDescription + " - Proximity medium scale wasn't applied to handle");
445462

446463
// move slightly out of medium proximity and check if far scaling is applied
447464
mediumProximityTestDist.x += moveOutOfScaleConstant;
448465
yield return hand.MoveTo(mediumProximityTestDist);
449466
yield return PlayModeTestUtilities.WaitForEnterKey();
450-
Assert.AreEqual(proximityScaledVisual.localScale, expectedFarScale, "Proximity far scale wasn't applied to handle");
467+
Assert.AreEqual(proximityScaledVisual.localScale, expectedFarScale, testDescription + " - Proximity far scale wasn't applied to handle");
451468

452469
yield return null;
453470
}

0 commit comments

Comments
 (0)