简体   繁体   English

WebGL和Three.js中的Z轴协调

[英]Z-Axis Coordination in WebGL and Three.js

I'm experimenting with WebGL and Three.js, But how to calculate the Z-Axis coordination while moving mouse? 我正在尝试使用WebGL和Three.js,但是如何在移动鼠标时计算Z轴坐标?

I use this for X and Y: 我将其用于X和Y:

  function getCoord(e) {
      X = e.layerX - canvas.offsetLeft;
      Y = e.layerY - canvas.offsetTop;
  }

how to get Z coordination? 如何获得Z坐标?

Edit: I find this example, but can't figure it out myself... https://github.com/mrdoob/three.js/blob/master/examples/webgl_interactive_voxelpainter.html 编辑:我找到了这个例子,但我自己却无法解决... https://github.com/mrdoob/three.js/blob/master/examples/webgl_interactive_voxelpainter.html

Thanks 谢谢

Here is the answer... 这是答案...

function onDocumentMouseMove( event ) {
     event.preventDefault();
     mouse2D.x = ( event.clientX / window.innerWidth ) * 2 - 1;
     mouse2D.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
}

function render() {
     mouse3D = projector.unprojectVector( mouse2D.clone(), camera );
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM