summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webxr/xrFrame_getViewerPose_getPose_identities.https.html
blob: ba2269147e4cd8bfaca58756d8b47f6c7a354f9a (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!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(viewerSpace) & getPose(space, space) return identity even during tracking loss";

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

    // 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 expectMatrix = function(pose, expectedMatrix, poseName) {
      assert_not_equals(pose, null,
                        poseName + " should not be null!");
      assert_matrix_approx_equals(pose.transform.matrix, expectedMatrix,
                                  poseName + "'s matrix should match expectations!");
      assert_false(pose.emulatedPosition,
                   poseName + ".emulatedPosition should be false!");
    }

    const expectIdentity = function(pose, poseName) {
      assert_not_equals(pose, null,
                        poseName + " should not be null!");
      assert_matrix_approx_equals(pose.transform.matrix, IDENTITY_MATRIX,
                                  poseName + "'s matrix should equal identity!");
      assert_false(pose.emulatedPosition,
                   poseName + ".emulatedPosition should be false!");
    }

    const testFunction = function(session, fakeDeviceController, t) {
      return Promise.all([
        session.requestReferenceSpace('local'),
        session.requestReferenceSpace('viewer'),
        session.requestReferenceSpace('local-floor'),
        session.requestReferenceSpace('bounded-floor'),
        session.requestReferenceSpace('unbounded'),
        session.requestReferenceSpace('local'),
      ]).then((allSpaces) => new Promise((resolve, reject) => {
        const [
          localSpace1,
          viewerSpace,
          localFloorSpace,
          boundedFloorSpace,
          unboundedSpace,
          localSpace2] = allSpaces;

        const offsetLocalSpace1 = localSpace1.getOffsetReferenceSpace(offsetSpaceTransform);
        const offsetLocalSpace2 = localSpace2.getOffsetReferenceSpace(offsetSpaceTransform);
        const offsetViewerSpace = viewerSpace.getOffsetReferenceSpace(offsetSpaceTransform);

        // Throw in an offset space:
        allSpaces.push(offsetLocalSpace1);

        function onFrame(time, frame) {
          // Expect identities:
          const viewerFromViewer1 = frame.getViewerPose(viewerSpace);

          const localFromLocalDifferentAddress = frame.getPose(localSpace1, localSpace2);
          const offsetFromOffsetDifferentAddress = frame.getPose(offsetLocalSpace1, offsetLocalSpace2);

          t.step(() => {
            expectIdentity(viewerFromViewer1, "viewerFromViewer1");
            expectIdentity(localFromLocalDifferentAddress, "localFromLocalDifferentAddress");
            expectIdentity(offsetFromOffsetDifferentAddress, "offsetFromOffsetDifferentAddress");
          });

          // Expect offsetSpaceTransform:
          const viewerFromViewer2 = frame.getViewerPose(offsetViewerSpace);

          const viewerFromOffset2 = frame.getPose(offsetViewerSpace, viewerSpace);
          const localFromOffset1 = frame.getPose(offsetLocalSpace1, localSpace1);
          const localFromOffset2 = frame.getPose(offsetLocalSpace2, localSpace1);

          t.step(() => {
            expectMatrix(viewerFromViewer2, offsetSpaceTransform.matrix, "viewerFromViewer2");
            expectMatrix(viewerFromOffset2, offsetSpaceTransform.matrix, "viewerFromOffset2");
            expectMatrix(localFromOffset1, offsetSpaceTransform.matrix, "localFromOffset1");
            expectMatrix(localFromOffset2, offsetSpaceTransform.matrix, "localFromOffset2");
          });

          // Expect identities:
          allSpaces.forEach((space, index) => {
            const pose = frame.getPose(space, space);
            t.step(() => {
              expectIdentity(pose, "pose[" + index +"]");
            });
          });

          resolve();
        }

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

    xr_session_promise_test(testName, testFunction,
      deviceInitParams, 'immersive-vr', {
        requiredFeatures: ["local", "local-floor", "bounded-floor", "unbounded"]
      });

  </script>
</body>