【问题标题】:how to get the world position of cursor which is attached to camera in aframe如何在框架中获取附加到相机的光标的世界位置
【发布时间】:2019-06-09 19:45:03
【问题描述】:

我想获取光标的世界位置,以帮助我为 360 度游览创建热点,因为我创建了一个返回光标位置的组件。该组件工作正常,但它返回光标的相对位置,所以我应该怎么做才能获得光标的世界位置

link to glich project

【问题讨论】:

    标签: javascript jquery aframe webvr


    【解决方案1】:

    您可以使用以下THREE.js 方法之一:

    // set a vector from the cursors matrix world
    vec3.setFromMatrixPosition(cursorEl.object3D.matrixWorld);
    
    // fill a vector using the getWorldPosition
    cursorEl.object3D.getWorldPosition(vec3)
    

    查看this fiddle。


    在自定义组件中使用它。

    有这样的设置

    <a-camera>
       <a-cursor my-component></a-cursor>
    </a-camera>
    

    你可以有这样的组件:

    AFRAME.registerComponent("my-component", {
       init: function() {
           this.vec = new THREE.Vector3()
       },
       tick: function() {
           this.vec.setFromMatrixPosition(this.el.object3D.matrixWorld);
           // do something with this.vec
       }
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-15
      • 1970-01-01
      • 2016-12-21
      相关资源
      最近更新 更多