summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webxr/xrReferenceSpace_originOffsetBounded.https.html
blob: fd961735ec756fc07fecc2481d293c4924a5fe80 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<!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>

const testName = "Updating XRBoundedReferenceSpace origin offset updates view, input matrices, and bounds geometry.";

const INITIAL_VIEW_OFFSET = {
  position: [1, 2, 3],
  orientation: [0,0,0,1]
};

const VIEWS_WITH_OFFSET = [{
    eye:"left",
    projectionMatrix: VALID_PROJECTION_MATRIX,
    viewOffset: INITIAL_VIEW_OFFSET,
    resolution: VALID_RESOLUTION
  }, {
    eye:"right",
    projectionMatrix: VALID_PROJECTION_MATRIX,
    viewOffset: INITIAL_VIEW_OFFSET,
    resolution: VALID_RESOLUTION
}];

const FLOOR_TRANSFORM = {
  position: [-0.1, -0.2, -0.3],
  orientation: [0, 0, 0, 1]
};

const fakeDeviceInitParams = {
  supportsImmersive: true,
  supportedModes: ["inline", "immersive-vr"],
  views: VIEWS_WITH_OFFSET,
  viewerOrigin: IDENTITY_TRANSFORM,
  floorOrigin: FLOOR_TRANSFORM,
  supportedFeatures: ALL_FEATURES,
  boundsCoordinates: [
    { x:  1, z: -1.5 },
    { x:  1, z:  1.5 },
    { x: -1, z:  1.5 },
    { x: -1, z: -1.5 }
  ]
};

function testFunction(session, fakeDeviceController, t) {
  const INITIAL_GRIP_TRANSFORM = {
    position: [1, 2, 3],
    orientation: [0, 0, 0, 1]
  };

  const LOCAL_POINTER_TRANSFORM = {
    position: [1.01, 2.02, 3.03],
    orientation: [0, 0, 0, 1]
  }

  let input_source = fakeDeviceController.simulateInputSourceConnection({
    handedness: "right",
    targetRayMode: "tracked-pointer",
    pointerOrigin: LOCAL_POINTER_TRANSFORM,
    gripOrigin: INITIAL_GRIP_TRANSFORM,
    profiles: []
  });

  return new Promise((resolve, reject) => {
    session.requestReferenceSpace('bounded-floor').then((referenceSpace) => {
      requestSkipAnimationFrame(session, (time, frame) => {
        let input_source = session.inputSources[0];

        function CheckState(
          reference_space,
          expected_view_matrix,
          expected_grip_matrix,
          expected_ray_matrix,
          expected_bounds_geometry
        ) {
          t.step(() => {
            let pose = frame.getViewerPose(reference_space);
            let grip_pose = frame.getPose(input_source.gripSpace, reference_space);
            let input_pose = frame.getPose(input_source.targetRaySpace, reference_space);

            let view_matrix = pose.views[0].transform.inverse.matrix;
            let grip_matrix = grip_pose.transform.matrix;
            let ray_matrix = input_pose.transform.matrix;

            assert_matrix_approx_equals(view_matrix, expected_view_matrix);
            assert_matrix_approx_equals(grip_matrix, expected_grip_matrix);
            assert_matrix_approx_equals(ray_matrix, expected_ray_matrix);

            assert_equals(reference_space.boundsGeometry.length, expected_bounds_geometry.length);
            for (var i = 0; i < reference_space.boundsGeometry.length; ++i) {
              assert_point_approx_equals(reference_space.boundsGeometry[i], expected_bounds_geometry[i]);
            }
          });
        }

        const EXPECTED_VIEW_MATRIX_1 = [
           1,    0,    0,   0,
           0,    1,    0,   0,
           0,    0,    1,   0,
          -1.1, -2.2, -3.3, 1,
        ];
        const EXPECTED_GRIP_MATRIX_1 = [
          1,   0,   0,   0,
          0,   1,   0,   0,
          0,   0,   1,   0,
          1.1, 2.2, 3.3, 1,
        ];
        const EXPECTED_RAY_MATRIX_1 =  [
          1,    0,    0,    0,
          0,    1,    0,    0,
          0,    0,    1,    0,
          1.11, 2.22, 3.33, 1,
        ];

        const EXPECTED_BOUNDS_GEOMETRY_1 = [
          {x:  1, y: 0, z: -1.5, w: 1},
          {x:  1, y: 0, z:  1.5, w: 1},
          {x: -1, y: 0, z:  1.5, w: 1},
          {x: -1, y: 0, z: -1.5, w: 1},
        ];

        // Check state after initialization
        CheckState(
          referenceSpace,
          EXPECTED_VIEW_MATRIX_1,
          EXPECTED_GRIP_MATRIX_1,
          EXPECTED_RAY_MATRIX_1,
          EXPECTED_BOUNDS_GEOMETRY_1
        );

        const RADIANS_90D = Math.PI / 2;

        // Perform arbitrary transformation to reference space originOffset
        const new_position1 = {
          x: 10, // Translate 10 units along the x-axis
          y: -3, // Translate -3 units along the y-axis
          z:  5, // Translate 5 units along the z-axis
        };
        const new_orientation1 = {
          x: Math.sin(RADIANS_90D / 2), // Rotate 90 degrees around the x-axis
          y: 0,
          z: 0,
          w: Math.cos(RADIANS_90D / 2),
        };
        referenceSpace = referenceSpace.getOffsetReferenceSpace(new XRRigidTransform(new_position1, new_orientation1));

        const EXPECTED_VIEW_MATRIX_2 = [
          1,    0,   0,   0,
          0,    0,   1,   0,
          0,   -1,   0,   0,
          8.9, -5.2, 1.7, 1,
        ];
        const EXPECTED_GRIP_MATRIX_2 = [
           1,    0,    0,   0,
           0,    0,   -1,   0,
           0,    1,    0,   0,
          -8.9, -1.7, -5.2, 1,
        ];
        const EXPECTED_RAY_MATRIX_2 = [
           1,     0,     0,    0,
           0,     0,    -1,    0,
           0,     1,     0,    0,
          -8.89, -1.67, -5.22, 1,
        ];

        const EXPECTED_BOUNDS_GEOMETRY_2 = [
          {x:  -9, y: -6.5, z: -3, w: 1},
          {x:  -9, y: -3.5, z: -3, w: 1},
          {x: -11, y: -3.5, z: -3, w: 1},
          {x: -11, y: -6.5, z: -3, w: 1},
        ];

        // Check state after transformation
        CheckState(
          referenceSpace,
          EXPECTED_VIEW_MATRIX_2,
          EXPECTED_GRIP_MATRIX_2,
          EXPECTED_RAY_MATRIX_2,
          EXPECTED_BOUNDS_GEOMETRY_2
        );

        // Perform arbitrary transformation to reference space originOffset
        const new_position2 = {
          x: 5, // Translate 5 units along the x-axis
          y: 2, // Translate 2 units along the y-axis
          z: 0,
        };
        const new_orientation2 = {
          x: 0,
          y: Math.sin(RADIANS_90D / 2), // Rotate 90 degrees about the y-axis
          z: 0,
          w: Math.cos(RADIANS_90D / 2),
        };
        referenceSpace = referenceSpace.getOffsetReferenceSpace(new XRRigidTransform(new_position2, new_orientation2));

        const EXPECTED_VIEW_MATRIX_3 = [
           0,    1,   0,   0,
           0,    0,   1,   0,
           1,    0,   0,   0,
          13.9, -5.2, 3.7, 1,
        ];
        const EXPECTED_GRIP_MATRIX_3 = [
          0,    0,     1,   0,
          1,    0,     0,   0,
          0,    1,     0,   0,
          5.2, -3.7, -13.9, 1,
        ];
        const EXPECTED_RAY_MATRIX_3 = [
          0,     0,      1,    0,
          1,     0,      0,    0,
          0,     1,      0,    0,
          5.22, -3.67, -13.89, 1,
        ];

        const EXPECTED_BOUNDS_GEOMETRY_3 = [
          {x: 3, y: -8.5, z: -14, w: 1},
          {x: 3, y: -5.5, z: -14, w: 1},
          {x: 3, y: -5.5, z: -16, w: 1},
          {x: 3, y: -8.5, z: -16, w: 1},
        ];

        // Check state after transformation
        CheckState(
          referenceSpace,
          EXPECTED_VIEW_MATRIX_3,
          EXPECTED_GRIP_MATRIX_3,
          EXPECTED_RAY_MATRIX_3,
          EXPECTED_BOUNDS_GEOMETRY_3
        );

        resolve();
      });
    });
  });
};

xr_session_promise_test(
  testName, testFunction, fakeDeviceInitParams, 'immersive-vr', { 'requiredFeatures': ['bounded-floor'] });

</script>