summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webxr/xrRigidTransform_inverse.https.html
blob: d4fdc15396d25223ab07d473a0039434b4c58761 (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
<!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_math_utils.js"></script>
<script src="resources/webxr_test_constants.js"></script>
<script src="resources/webxr_test_asserts.js"></script>
<script>

let testName = "XRRigidTransform inverse works";
let fakeDeviceInitParams = TRACKED_IMMERSIVE_DEVICE;

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

  // An identity transform should be equal to it's inverse.
  let identity_transform = new XRRigidTransform();
  t.step(() => {
    assert_transform_approx_equals(identity_transform, identity_transform.inverse);
  });

  // Inversed transforms should yield the expected results
  let transform = new XRRigidTransform(
      { x: 1.0, y: 2.0, z: 3.0 },
      { x: 0.0, y: 0.0, z: 0.0, w: 1.0 });
  let inverse_transform = transform.inverse;
  let expected_inverse = new XRRigidTransform(
      { x: -1.0, y: -2.0, z: -3.0 },
      { x: 0.0, y: 0.0, z: 0.0, w: 1.0 });
  t.step(() => {
    assert_transform_approx_equals(inverse_transform, expected_inverse);
  });

  transform = new XRRigidTransform(
      { x: 0.0, y: 0.0, z: 0.0 },
      { x: 1.0, y: 0.0, z: 0.0, w: 1.0 });
  inverse_transform = transform.inverse;
  expected_inverse = new XRRigidTransform(
      { x: 0.0, y: 0.0, z: 0.0 },
      { x: -1.0, y: 0.0, z: 0.0, w: 1.0 });
  t.step(() => {
    assert_transform_approx_equals(inverse_transform, expected_inverse);
  });

  transform = new XRRigidTransform(
      { x: 1.0, y: 2.0, z: 3.0 },
      { x: 0.0, y: 1.0, z: 0.0, w: 1.0 });
  inverse_transform = transform.inverse;
  expected_inverse = new XRRigidTransform(
      { x: 3.0, y: -2.0, z: -1.0 },
      { x: 0.0, y: -1.0, z: 0.0, w: 1.0 });
  t.step(() => {
    assert_transform_approx_equals(inverse_transform, expected_inverse);
  });

  // Transforms should be equal to the inverse of their inverse.
  transform = new XRRigidTransform(
      { x: 1.0, y: 2.0, z: 3.0 },
      { x: 1.0, y: 2.0, z: 3.0, w: 4.0 });
  inverse_transform = transform.inverse;
  t.step(() => {
    assert_transform_approx_equals(transform, inverse_transform.inverse);
  });

  transform = new XRRigidTransform(
      { x: -9.0, y: 8.0, z: -7.0 },
      { x: 6.0, y: -5.0, z: 4.0, w: 3.0 });
  inverse_transform = transform.inverse;
  t.step(() => {
    assert_transform_approx_equals(transform, inverse_transform.inverse);
  });

  transform = new XRRigidTransform(
      { x: -2.0, y: 1.0, z: -4.0 },
      { x: 0.0, y: 1.0, z: 0.0, w: 1.0 });
  inverse_transform = transform.inverse;
  t.step(() => {
    assert_transform_approx_equals(transform, inverse_transform.inverse);
  });

  transform = new XRRigidTransform(
      { x: 2.0, y: -1.0, z: 4.0 },
      { x: 1.0, y: 0.0, z: 0.0, w: 1.0 });
  inverse_transform = transform.inverse;
  t.step(() => {
    assert_transform_approx_equals(transform, inverse_transform.inverse);
  });

  // Inverse should always return the same object, and calling inverse on that
  // object should return the original object.
  transform = new XRRigidTransform(
      { x: 1.0, y: -2.0, z: 3.0 },
      { x: 0.0, y: 0.0, z: 1.0, w: 1.0 });
  inverse_transform = transform.inverse;
  t.step(() => {
    assert_equals(transform.inverse, inverse_transform);
    assert_equals(inverse_transform.inverse, transform);
    assert_equals(transform.inverse.inverse, transform);
    assert_equals(transform.inverse.inverse.inverse, inverse_transform);
  });

  resolve();
});

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

</script>