簡體   English   中英

如何獲取框架中附加到相機的光標的世界位置

[英]how to get the world position of cursor which is attached to camera in aframe

我想獲取光標的世界位置,以幫助我創建360游覽的熱點,因為我創建了一個返回光標位置的組件。 該組件工作正常,但它返回了光標的相對位置,所以我應該怎么做才能獲得光標的世界位置

鏈接到glich項目

您可以使用以下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)

這個小提琴中檢查一下。


在自定義組件中使用它。

有這樣的設置

<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
   }
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM