javascript - aframe 相机在 VR 模式下不 move

标签 javascript camera move aframe virtual-reality

我想在一个框架游戏中连续 move 到相机的视口(viewport)。我使用了 here 中的代码:

在我的桌面浏览器(不是 VR 模式)中,它运行得很好,但是当我切换到 VR 模式时, move 不起作用......

这是我所拥有的示例:

    <!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>360° Image Browser</title>
    <script src="https://aframe.io/releases/0.7.1/aframe.min.js"></script>
    <script src="https://unpkg.com/aframe-extras.ocean@3.13.1/dist/aframe-extras.ocean.min.js"></script>


</head>

<body>
    <a-scene>
        <!-- sky + ocean -->
        <a-sky radius="100" src="http://2.bp.blogspot.com/-ELqPrSgPbGU/Vcnw54n7Q1I/AAAAAAAAGdk/rcfkvjlMNqI/s1600/PANO_360Test09.jpg"
            position="0 -6 0 "></a-sky>
        <a-ocean width="200" depth="200" density="200" position="0 0 0"></a-ocean>

        <!-- camera + cursor. -->
        <a-camera id="camera" position="0 20 80" fly wasd-controls-enabled="false" look>
            <a-cursor id="cursor" color="black"></a-cursor>
        </a-camera>
    </a-scene>
    <script>
        // document.querySelector("a-scene").enterVR();
        AFRAME.registerComponent("fly", {
            schema: {
                stepFactor: { type: "number", default: 0.1 },
                isFlying: { type: "boolean", default: true }
            },
            tick: function () {
                if (this.data.isFlying) {
                    this.el.components.camera.camera.parent.position.add(
                        this.el.components.camera.camera
                            .getWorldDirection()
                            .multiplyScalar(this.data.stepFactor)
                    );
                }
            }
        });
    </script>

</body>

</html>

您可以通过删除提交来打开脚本中的 VR 模式

有人有想法吗?

最佳答案

我不完全确定当你切换到 VR 模式时会发生什么(关于相机元素),但尝试 setAttribute 似乎可以使它工作:

https://glitch.com/edit/#!/a-frame-move-camera

tick: function () {
    if (this.data.isFlying) {
        let newP = this.el.components.camera.camera.parent.position.add(this.el.components.camera.camera.getWorldDirection().multiplyScalar(this.data.stepFactor));
        this.el.setAttribute('position', newP)
    }
}

关于javascript - aframe 相机在 VR 模式下不 move ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48815937/

相关文章:

JavaScript 重定向防止 IE 上的 CSS 覆盖

android - 排列可 move 的 UI 组件

PHP:将文件从域 move 到子域

swift - 慢人脸检测 Firebase MLKit

android - 启动 Activity 时相机预览崩溃

c++ - 为什么在这种情况下调用 move 构造函数?

javascript - jquery中解析JSON数据的问题

javascript - 使用 react 调用api的正确方法

Javascript cookies - 检查cookie是否存在

c++ - 使用opencv检测相机运动