PositionSensorVRDevice: getImmediateState() method
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.
Phương thức getImmediateState() của giao diện VRDisplay trả về trạng thái cảm biến vị trí tức thì hiện tại. Phương thức này chỉ dành để sử dụng hiếm khi, cho một số mục đích đặc biệt nhất định, ví dụ như lấy mẫu vị trí tức thì của cảm biến hướng tay.
Đối với hầu hết các mục đích tiêu chuẩn, bạn có thể muốn sử dụng PositionSensorVRDevice.getState thay thế.
Cú pháp
getImmediateState()
Tham số
Không có.
Giá trị trả về
Một đối tượng VRPose.
Ví dụ
Demo sau sử dụng WebVR API để cập nhật view của một cảnh CanvasRenderingContext2D đơn giản trên mỗi frame của vòng lặp requestAnimationFrame. Hàm chính cập nhật dữ liệu view như sau:
function setView() {
const posState = gPositionSensor.getImmediateState();
if (posState.hasPosition) {
posPara.textContent = `Position: x${roundToTwo(
posState.position.x,
)} y${roundToTwo(posState.position.y)} z${roundToTwo(posState.position.z)}`;
xPos = -posState.position.x * WIDTH * 2;
yPos = posState.position.y * HEIGHT * 2;
zPos = -posState.position.z > 0.01 ? -posState.position.z : 0.01;
}
if (posState.hasOrientation) {
orientPara.textContent = `Orientation: x${roundToTwo(
posState.orientation.x,
)} y${roundToTwo(posState.orientation.y)} z${roundToTwo(
posState.orientation.z,
)}`;
xOrient = posState.orientation.x * WIDTH;
yOrient = -posState.orientation.y * HEIGHT * 2;
zOrient = posState.orientation.z * 180;
}
}