Skip to content

Commit 4b6eaef

Browse files
added rotation tests for far and near interaction
1 parent e0dc749 commit 4b6eaef

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,89 @@ public IEnumerator ScaleViaNearInteration()
155155
yield return null;
156156
}
157157

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+
158241
/// <summary>
159242
/// Tests scaling of bounds control by grabbing a corner with the far interaction hand ray
160243
/// </summary>

0 commit comments

Comments
 (0)