summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webxr/xrFrame_getViewerPose_getPose.https.html
blob: 05cbf785237b7c7d2177976ea16b31a4060e3a1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<body>
  <script src=/resources/testharness.js></script>
  <script src=/resources/testharnessreport.js></script>
  <script src="resources/webxr_util.js"></script>
  <script src="resources/webxr_test_constants.js"></script>
  <script src="resources/webxr_test_asserts.js"></script>

  <script>

    let testName = "XRFrame getViewerPose(refSpace) matches getPose(viewer, refSpace).";

    // Used for viewer origin, the actual values should not matter for the test.
    const poseTransform = {
        position: [1, 2, 3],
        orientation: [0.5, 0.5, 0.5, 0.5] // 120 degrees around [1, 1, 1] axis
    };

    // Use the same device as tracked immersive device, but modify the viewer origin.
    const deviceInitParams = Object.assign({}, TRACKED_IMMERSIVE_DEVICE, {viewerOrigin: poseTransform});

    // Used when creating a reference space that is offset from local space.
    // Actual values should not matter for the test.
    const offsetSpaceTransform = new XRRigidTransform(
      { x: 1.00, y: -1.50, z: 10.00, w: 1.0 },
      { x: 0.27, y:  0.00, z:  0.27, w: 0.92},  // 45 degrees around [1, 0, 1] axis
    );

    const testFunction = function(session, fakeDeviceController, t) {
      return Promise.all([
        session.requestReferenceSpace('local'),
        session.requestReferenceSpace('viewer'),
      ]).then(([referenceSpace, viewerRefSpace]) => new Promise((resolve, reject) => {
        const offsetRefSpace = referenceSpace.getOffsetReferenceSpace(offsetSpaceTransform);

        function onFrame(time, frame){
          t.step(() => {
            const pose1 = frame.getViewerPose(referenceSpace);
            const pose2 = frame.getPose(viewerRefSpace, referenceSpace);
            assert_not_equals(pose1, null);
            assert_not_equals(pose2, null);
            assert_matrix_approx_equals(pose1.transform.matrix, pose2.transform.matrix);

            const pose3 = frame.getViewerPose(offsetRefSpace);
            const pose4 = frame.getPose(viewerRefSpace, offsetRefSpace);
            assert_not_equals(pose3, null);
            assert_not_equals(pose4, null);
            assert_matrix_approx_equals(pose3.transform.matrix, pose4.transform.matrix);
          });

          resolve();
        }

        session.requestAnimationFrame(onFrame);
      }));
    };

    xr_session_promise_test(testName, testFunction,
      deviceInitParams, 'immersive-vr');

  </script>
</body>