VRFieldOfView

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.

Giao diện VRFieldOfView của WebVR API biểu diễn một trường nhìn được xác định bởi 4 giá trị góc khác nhau mô tả tầm nhìn từ một điểm trung tâm.

Note: Giao diện này là một phần của WebVR API cũ. Nó đã được thay thế bởi WebXR Device API.

Thuộc tính phiên bản

VRFieldOfView.upDegrees Deprecated Read only Non-standard

Số độ mà trường nhìn mở rộng lên trên.

VRFieldOfView.rightDegrees Deprecated Read only Non-standard

Số độ mà trường nhìn mở rộng sang phải.

VRFieldOfView.downDegrees Deprecated Read only Non-standard

Số độ mà trường nhìn mở rộng xuống dưới.

VRFieldOfView.leftDegrees Deprecated Read only Non-standard

Số độ mà trường nhìn mở rộng sang trái.

Ví dụ

js
const info = document.querySelector("p");
const list = document.querySelector("ul");
let vrDisplay;

if (navigator.getVRDisplays) {
  reportFieldOfView();
} else {
  info.textContent = "WebVR API not supported by this browser.";
}

function reportFieldOfView() {
  navigator.getVRDisplays().then((displays) => {
    vrDisplay = displays[0];
    const lEye = vrDisplay.getEyeParameters("left");
    const rEye = vrDisplay.getEyeParameters("right");
    // lEye and rEye are VREyeParameters objects

    const lFOV = lEye.fieldOfView;
    const rFOV = rEye.fieldOfView;
    // lFOV and rFOV are VRFieldOfView objects

    const listitem1 = document.createElement("li");
    const listitem2 = document.createElement("li");

    listitem1.innerText = `
Offset: ${lEye.offset}
Render width: ${lEye.renderWidth}
Render height: ${lEye.renderHeight}
Up degrees: ${lFOV.upDegrees}
Right degrees: ${lFOV.rightDegrees}
Down degrees: ${lFOV.downDegrees}
Left degrees: ${lFOV.leftDegrees}`;
    listitem1.insertBefore(
      document.createElement("strong"),
      listitem1.firstChild,
    ).textContent = "Left eye parameters";

    listitem2.innerText = `
Offset: ${rEye.offset}
Render width: ${rEye.renderWidth}
Render height: ${rEye.renderHeight}
Up degrees: ${rFOV.upDegrees}
Right degrees: ${rFOV.rightDegrees}
Down degrees: ${rFOV.downDegrees}
Left degrees: ${rFOV.leftDegrees}`;
    listitem2.insertBefore(
      document.createElement("strong"),
      listitem2.firstChild,
    ).textContent = "Right eye parameters";

    list.appendChild(listitem1);
    list.appendChild(listitem2);
  });
}

Thông số kỹ thuật

Giao diện này là một phần của WebVR API cũ đã được thay thế bởi WebXR Device API. Nó không còn được theo dõi để trở thành tiêu chuẩn.

Cho đến khi tất cả trình duyệt triển khai WebXR APIs mới, nên dựa vào các framework như A-Frame, Babylon.js, hoặc Three.js, hoặc một polyfill, để phát triển ứng dụng WebXR hoạt động trên tất cả trình duyệt.

Tương thích trình duyệt

Xem thêm