tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

getInputPose_pointer.https.html (3491B)


      1 <!DOCTYPE html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script src="resources/webxr_util.js"></script>
      5 <script src="resources/webxr_test_constants.js"></script>
      6 <script src="resources/webxr_test_asserts.js"></script>
      7 
      8 <script>
      9 
     10 let testName = "XRInputSources with a target ray mode of 'tracked-pointer' "
     11  + "properly communicate their poses";
     12 
     13 let fakeDeviceInitParams = TRACKED_IMMERSIVE_DEVICE;
     14 
     15 let testFunction =
     16  (session, fakeDeviceController, t) => new Promise((resolve) => {
     17    let input_source = fakeDeviceController.simulateInputSourceConnection({
     18      handedness: "right",
     19      targetRayMode: "tracked-pointer",
     20      pointerOrigin: IDENTITY_TRANSFORM,
     21      profiles: []
     22    });
     23 
     24    // Don't set a grip matrix yet
     25 
     26    // Must have a reference space to get input poses. eye-level doesn't apply
     27    // any transforms to the given matrix.
     28    session.requestReferenceSpace('local').then( (referenceSpace) => {
     29 
     30      function CheckInvalidGrip(time, xrFrame) {
     31        let source = session.inputSources[0];
     32        let grip_pose = xrFrame.getPose(source.gripSpace, referenceSpace);
     33 
     34        t.step( () => {
     35          // The input pose should be null when no grip matrix is provided.
     36          assert_equals(source.targetRayMode, "tracked-pointer");
     37          assert_equals(grip_pose, null);
     38        });
     39 
     40        input_source.setGripOrigin(VALID_GRIP_TRANSFORM);
     41 
     42        session.requestAnimationFrame(CheckValidGrip);
     43      }
     44 
     45      function CheckValidGrip(time, xrFrame) {
     46        let source = session.inputSources[0];
     47 
     48        let grip_pose = xrFrame.getPose(source.gripSpace, referenceSpace);
     49 
     50        let input_pose = xrFrame.getPose(source.targetRaySpace, referenceSpace);
     51 
     52        t.step( () => {
     53          // When a grip matrix is set, both the grip and pointer matrices
     54          // should yield their set values (i.e. the pointerOrigin is *not*
     55          // transformed by the gripOrigin).
     56          assert_not_equals(grip_pose, null);
     57          assert_matrix_approx_equals(grip_pose.transform.matrix, VALID_GRIP,
     58            FLOAT_EPSILON, "Grip matrix is not equal to input.");
     59          assert_matrix_approx_equals(input_pose.transform.matrix,
     60            IDENTITY_MATRIX, FLOAT_EPSILON,
     61            "Pointer matrix is not equal to its set value.");
     62        });
     63 
     64        input_source.setPointerOrigin(VALID_POINTER_TRANSFORM);
     65 
     66        session.requestAnimationFrame(CheckValidGripAndPointer);
     67      }
     68 
     69      function CheckValidGripAndPointer(time, xrFrame) {
     70        let source = session.inputSources[0];
     71 
     72        let grip_pose = xrFrame.getPose(source.gripSpace, referenceSpace);
     73        let input_pose = xrFrame.getPose(source.targetRaySpace, referenceSpace);
     74 
     75        t.step( () => {
     76          // Verify that changes to the pointer origin are properly reflected.
     77          assert_not_equals(grip_pose, null);
     78          assert_matrix_approx_equals(grip_pose.transform.matrix, VALID_GRIP,
     79            FLOAT_EPSILON, "Grip matrix is not equal to input valid grip.");
     80          assert_matrix_approx_equals(input_pose.transform.matrix,
     81            VALID_POINTER, FLOAT_EPSILON,
     82            "Pointer matrix not set properly.");
     83        });
     84 
     85        resolve();
     86      }
     87 
     88      // Can only request input poses in an xr frame.
     89      requestSkipAnimationFrame(session, CheckInvalidGrip);
     90    });
     91  });
     92 
     93 xr_session_promise_test(
     94  testName, testFunction, fakeDeviceInitParams, 'immersive-vr');
     95 
     96 </script>