summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webxr/xrReferenceSpace_originOffset_viewer.https.html
blob: 8a9fb344a385a3dea05774f9308f420a6d9923bf (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
<!DOCTYPE html>
<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 = "Creating XRReferenceSpace origin offset off of `viewer` space works.";

let fakeDeviceInitParams = {
  supportsImmersive: true,
  supportedModes: ["inline", "immersive-vr"],
  viewerOrigin: VALID_POSE_TRANSFORM,
  views: VALID_VIEWS,
  supportedFeatures: ALL_FEATURES
};

let originOffsetPosition = new DOMPointReadOnly(0, 0, 1);

let testFunction =
  (session, fakeDeviceController, t) => new Promise((resolve) => {

    session.requestReferenceSpace('local').then( (localSpace) => {
      session.requestReferenceSpace('viewer').then( (viewerSpace) => {

        let offsetSpace = viewerSpace.getOffsetReferenceSpace(
          new XRRigidTransform(originOffsetPosition));

        function OnFrame(time, frame) {
          let viewerPose = frame.getPose(viewerSpace, localSpace);
          let offsetPose = frame.getPose(offsetSpace, localSpace);

          let viewerPose2 = frame.getPose(localSpace ,viewerSpace);
          let offsetPose2 = frame.getPose(localSpace, offsetSpace);

          t.step(() => {
            assert_point_significantly_not_equals(viewerPose.transform.position, offsetPose.transform.position);
            assert_point_significantly_not_equals(viewerPose2.transform.position, offsetPose2.transform.position);
          });

          resolve();
        }

        // Can only request input poses in an xr frame.
        session.requestAnimationFrame(OnFrame);
      });
    });
  });

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

</script>