Skip to content

Commit bd7ea9c

Browse files
authored
Merge pull request #7035 from thalbern/user/bethalha/bctest
added tests to bounds control
2 parents f4d872c + 2f44cc1 commit bd7ea9c

File tree

1 file changed

+160
-6
lines changed

1 file changed

+160
-6
lines changed

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

Lines changed: 160 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,7 @@ private BoundsControl InstantiateSceneAndDefaultBbox()
5353
cube.transform.position = boundsControlStartCenter;
5454
BoundsControl bbox = cube.AddComponent<BoundsControl>();
5555

56-
MixedRealityPlayspace.PerformTransformation(
57-
p =>
58-
{
59-
p.position = Vector3.zero;
60-
p.LookAt(boundsControlStartCenter);
61-
});
56+
TestUtilities.PlayspaceToOriginLookingForward();
6257

6358
bbox.transform.localScale = boundsControlStartScale;
6459
bbox.Active = true;
@@ -158,7 +153,166 @@ public IEnumerator ScaleViaNearInteration()
158153
GameObject.Destroy(bbox.gameObject);
159154
// Wait for a frame to give Unity a change to actually destroy the object
160155
yield return null;
156+
}
157+
158+
/// <summary>
159+
/// Test bounds control rotation via far interaction
160+
/// Verifies gameobject has rotation in one axis only applied and no other transform changes happen during interaction
161+
/// </summary>
162+
[UnityTest]
163+
public IEnumerator RotateViaFarInteraction()
164+
{
165+
BoundsControl bbox = InstantiateSceneAndDefaultBbox();
166+
yield return VerifyInitialBoundsCorrect(bbox);
167+
168+
Vector3 pointOnCube = new Vector3(-0.033f, -0.129f, 0.499f); // position where hand ray points on center of the test cube
169+
Vector3 rightFrontRotationHandlePoint = new Vector3(0.121f, -0.127f, 0.499f); // position of hand for far interacting with front right rotation sphere
170+
Vector3 endRotation = new Vector3(-0.18f, -0.109f, 0.504f); // end position for far interaction scaling
171+
172+
TestHand hand = new TestHand(Handedness.Left);
173+
yield return hand.Show(pointOnCube); //initially make sure that hand ray is pointed on cube surface so we won't go behind the cube with our ray
174+
// grab front right rotation point
175+
yield return hand.MoveTo(rightFrontRotationHandlePoint);
176+
yield return hand.SetGesture(ArticulatedHandPose.GestureId.Pinch);
177+
// move to left side of cube
178+
yield return hand.MoveTo(endRotation);
179+
180+
// make sure rotation is as expected and no other transform values have been modified through this
181+
Vector3 expectedPosition = new Vector3(0f, 0f, 1.5f);
182+
Vector3 expectedSize = Vector3.one * 0.5f;
183+
float angle;
184+
Vector3 axis = new Vector3();
185+
bbox.transform.rotation.ToAngleAxis(out angle, out axis);
186+
float expectedAngle = 87f;
187+
float angleDiff = Mathf.Abs(expectedAngle - angle);
188+
Vector3 expectedAxis = new Vector3(0f, 1f, 0f);
189+
TestUtilities.AssertAboutEqual(axis, expectedAxis, "Rotated around wrong axis");
190+
Assert.IsTrue(angleDiff <= 1f, "cube didn't rotate as expected");
191+
TestUtilities.AssertAboutEqual(bbox.transform.position, expectedPosition, "cube moved while rotating");
192+
TestUtilities.AssertAboutEqual(bbox.transform.localScale, expectedSize, "cube scaled while rotating");
193+
194+
GameObject.Destroy(bbox.gameObject);
195+
// Wait for a frame to give Unity a change to actually destroy the object
196+
yield return null;
197+
}
198+
199+
/// <summary>
200+
/// Test bounds control rotation via near interaction
201+
/// Verifies gameobject has rotation in one axis only applied and no other transform changes happen during interaction
202+
/// </summary>
203+
[UnityTest]
204+
public IEnumerator RotateViaNearInteraction()
205+
{
206+
BoundsControl bbox = InstantiateSceneAndDefaultBbox();
207+
yield return VerifyInitialBoundsCorrect(bbox);
208+
209+
Vector3 pointOnCube = new Vector3(-0.033f, -0.129f, 0.499f); // position where hand ray points on center of the test cube
210+
Vector3 rightFrontRotationHandlePoint = new Vector3(0.248f, 0.001f, 1.226f); // position of hand for far interacting with front right rotation sphere
211+
Vector3 endRotation = new Vector3(-0.284f, -0.001f, 1.23f); // end position for far interaction scaling
212+
213+
TestHand hand = new TestHand(Handedness.Left);
214+
yield return hand.SetGesture(ArticulatedHandPose.GestureId.OpenSteadyGrabPoint);
215+
yield return hand.Show(pointOnCube);
216+
// grab front right rotation point
217+
yield return hand.MoveTo(rightFrontRotationHandlePoint);
218+
yield return hand.SetGesture(ArticulatedHandPose.GestureId.Pinch);
219+
// move to left side of cube
220+
yield return hand.MoveTo(endRotation);
221+
222+
// make sure rotation is as expected and no other transform values have been modified through this
223+
Vector3 expectedPosition = new Vector3(0f, 0f, 1.5f);
224+
Vector3 expectedSize = Vector3.one * 0.5f;
225+
float angle;
226+
Vector3 axis = new Vector3();
227+
bbox.transform.rotation.ToAngleAxis(out angle, out axis);
228+
float expectedAngle = 92f;
229+
float angleDiff = Mathf.Abs(expectedAngle - angle);
230+
Vector3 expectedAxis = new Vector3(0f, 1f, 0f);
231+
TestUtilities.AssertAboutEqual(axis, expectedAxis, "Rotated around wrong axis");
232+
Assert.IsTrue(angleDiff <= 1f, "cube didn't rotate as expected");
233+
TestUtilities.AssertAboutEqual(bbox.transform.position, expectedPosition, "cube moved while rotating");
234+
TestUtilities.AssertAboutEqual(bbox.transform.localScale, expectedSize, "cube scaled while rotating");
235+
236+
GameObject.Destroy(bbox.gameObject);
237+
// Wait for a frame to give Unity a change to actually destroy the object
238+
yield return null;
239+
}
240+
241+
/// <summary>
242+
/// Test bounds control rotation via hololens 1 interaction / GGV
243+
/// Verifies gameobject has rotation in one axis only applied and no other transform changes happen during interaction
244+
/// </summary>
245+
[UnityTest]
246+
public IEnumerator RotateViaHololens1Interaction()
247+
{
248+
BoundsControl control = InstantiateSceneAndDefaultBbox();
249+
yield return VerifyInitialBoundsCorrect(control);
250+
PlayModeTestUtilities.PushHandSimulationProfile();
251+
PlayModeTestUtilities.SetHandSimulationMode(HandSimulationMode.Gestures);
252+
253+
// move camera to look at rotation sphere
254+
CameraCache.Main.transform.LookAt(new Vector3(0.248f, 0.001f, 1.226f)); // rotation sphere front right
255+
256+
var startHandPos = new Vector3(0.364f, -0.157f, 0.437f);
257+
var endPoint = new Vector3(0.141f, -0.163f, 0.485f);
258+
259+
// perform tab with hand and drag to left
260+
TestHand rightHand = new TestHand(Handedness.Right);
261+
yield return rightHand.Show(startHandPos);
262+
yield return rightHand.SetGesture(ArticulatedHandPose.GestureId.Pinch);
263+
yield return rightHand.MoveTo(endPoint);
264+
265+
// make sure only Y axis rotation was performed and no other transform values have changed
266+
Vector3 expectedPosition = new Vector3(0f, 0f, 1.5f);
267+
Vector3 expectedSize = Vector3.one * 0.5f;
268+
float angle;
269+
Vector3 axis = new Vector3();
270+
control.transform.rotation.ToAngleAxis(out angle, out axis);
271+
float expectedAngle = 86f;
272+
float angleDiff = Mathf.Abs(expectedAngle - angle);
273+
Vector3 expectedAxis = new Vector3(0f, 1f, 0f);
274+
TestUtilities.AssertAboutEqual(axis, expectedAxis, "Rotated around wrong axis");
275+
Assert.IsTrue(angleDiff <= 1f, "cube didn't rotate as expected");
276+
TestUtilities.AssertAboutEqual(control.transform.position, expectedPosition, "cube moved while rotating");
277+
TestUtilities.AssertAboutEqual(control.transform.localScale, expectedSize, "cube scaled while rotating");
278+
279+
GameObject.Destroy(control.gameObject);
280+
// Wait for a frame to give Unity a change to actually destroy the object
281+
yield return null;
282+
283+
// Restore the input simulation profile
284+
PlayModeTestUtilities.PopHandSimulationProfile();
161285

286+
yield return null;
287+
}
288+
289+
/// <summary>
290+
/// Tests scaling of bounds control by grabbing a corner with the far interaction hand ray
291+
/// </summary>
292+
[UnityTest]
293+
public IEnumerator ScaleViaFarInteraction()
294+
{
295+
BoundsControl bbox = InstantiateSceneAndDefaultBbox();
296+
yield return VerifyInitialBoundsCorrect(bbox);
297+
298+
Vector3 rightCornerInteractionPoint = new Vector3(0.184f, 0.078f, 0.79f); // position of hand for far interacting with front right corner
299+
Vector3 pointOnCube = new Vector3(-0.033f, -0.129f, 0.499f); // position where hand ray points on center of the test cube
300+
Vector3 scalePoint = new Vector3(0.165f, 0.267f, 0.794f); // end position for far interaction scaling
301+
302+
TestHand hand = new TestHand(Handedness.Left);
303+
yield return hand.Show(pointOnCube); //initially make sure that hand ray is pointed on cube surface so we won't go behind the cube with our ray
304+
yield return hand.MoveTo(rightCornerInteractionPoint);
305+
yield return hand.SetGesture(ArticulatedHandPose.GestureId.Pinch);
306+
yield return hand.MoveTo(scalePoint);
307+
var endBounds = bbox.GetComponent<BoxCollider>().bounds;
308+
Vector3 expectedCenter = new Vector3(0.0453f, 0.0453f, 1.455f);
309+
Vector3 expectedSize = Vector3.one * 0.59f;
310+
TestUtilities.AssertAboutEqual(endBounds.center, expectedCenter, "endBounds incorrect center");
311+
TestUtilities.AssertAboutEqual(endBounds.size, expectedSize, "endBounds incorrect size");
312+
313+
GameObject.Destroy(bbox.gameObject);
314+
// Wait for a frame to give Unity a change to actually destroy the object
315+
yield return null;
162316
}
163317

164318
/// <summary>

0 commit comments

Comments
 (0)