blob: ce0cdeef197c29a82b44a88f2bde590d85d88c16 [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/device/vr/public/mojom/vr_service.mojom.js"></script>
<script src="../external/wpt/resources/chromium/webxr-test.js"></script>
<script src="../external/wpt/webxr/resources/webxr_test_constants.js"></script>
<script src="../xr/resources/xr-internal-device-mocking.js"></script>
<script src="../xr/resources/xr-test-utils.js"></script>
<canvas id="webgl-canvas"></canvas>
<script>
let testName = "XRInputSources produce valid target rays";
let fakeDeviceInitParams = { supportsImmersive: true };
let requestSessionOptions = [{ mode: 'immersive-vr' }];
let testFunction =
(session, t, fakeDeviceController) => new Promise((resolve) => {
// Session must have a baseLayer or frame requests will be ignored.
session.updateRenderState({ baseLayer: new XRWebGLLayer(session, gl) });
// Need to have a valid pose or input events don't process.
fakeDeviceController.setXRPresentationFrameData(VALID_POSE_MATRIX, [{
eye:"left",
projectionMatrix: VALID_PROJECTION_MATRIX,
viewMatrix: VALID_VIEW_MATRIX
}, {
eye:"right",
projectionMatrix: VALID_PROJECTION_MATRIX,
viewMatrix: VALID_VIEW_MATRIX
}]);
let input_source = new MockXRInputSource();
input_source.targetRayMode = "tracked-pointer";
input_source.handedness = "right";
input_source.grip = VALID_GRIP;
fakeDeviceController.addInputSource(input_source);
// Must have a reference space to get input poses. eye-level doesn't apply
// any transforms to the given matrix.
session.requestReferenceSpace({ type: "stationary", subtype: "eye-level" }).then( (referenceSpace) => {
function CheckTargetRayNoOffset(time, xrFrame) {
let source = session.getInputSources()[0];
let grip_pose = xrFrame.getPose(source.gripSpace, referenceSpace);
assert_not_equals(grip_pose, null);
let input_pose = xrFrame.getPose(source.targetRaySpace, referenceSpace);
assert_not_equals(input_pose, null);
let targetRay = new XRRay(input_pose.transform);
t.step( () => {
assert_matrices_approx_equal(targetRay.matrix,
grip_pose.transform.matrix, FLOAT_EPSILON,
"Target ray matrix is incorrect.");
assert_equals(targetRay.origin.x, 4.0);
assert_equals(targetRay.origin.y, 3.0);
assert_equals(targetRay.origin.z, 2.0);
assert_equals(targetRay.origin.w, 1.0);
assert_equals(targetRay.direction.x, 0.0);
assert_equals(targetRay.direction.y, 0.0);
assert_equals(targetRay.direction.z, -1.0);
assert_equals(targetRay.direction.w, 0.0);
}, "Target ray computed properly with no pointer offset");
input_source.pointerOffset = VALID_POINTER_OFFSET;
session.requestAnimationFrame(CheckTargetRayOffset);
}
function CheckTargetRayOffset(time, xrFrame) {
let source = session.getInputSources()[0];
let grip_pose = xrFrame.getPose(source.gripSpace, referenceSpace);
assert_not_equals(grip_pose, null);
let input_pose = xrFrame.getPose(source.targetRaySpace, referenceSpace);
assert_not_equals(input_pose, null);
let targetRay = new XRRay(input_pose.transform);
t.step( () => {
assert_matrices_approx_equal(targetRay.matrix,
VALID_GRIP_WITH_POINTER_OFFSET, FLOAT_EPSILON,
"Target ray matrix is not offset properly.");
assert_equals(targetRay.origin.x, 4.0);
assert_equals(targetRay.origin.y, 3.0);
assert_equals(targetRay.origin.z, 3.0);
assert_equals(targetRay.origin.w, 1.0);
assert_equals(targetRay.direction.x, 0.0);
assert_equals(targetRay.direction.y, 0.0);
assert_equals(targetRay.direction.z, -1.0);
assert_equals(targetRay.direction.w, 0.0);
}, "Target ray computed properly with a pointer offset");
resolve();
}
// Can only request input poses in an xr frame.
session.requestAnimationFrame(CheckTargetRayNoOffset);
});
});
xr_session_promise_test(
testFunction, fakeDeviceInitParams, requestSessionOptions, testName);
</script>