【问题标题】:Z-Axis Coordination in WebGL and Three.jsWebGL 和 Three.js 中的 Z 轴坐标
【发布时间】:2011-10-31 09:08:27
【问题描述】:

我正在试验 WebGL 和 Three.js, 但是移动鼠标时如何计算Z轴坐标呢?

我将它用于 X 和 Y:

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

如何获得 Z 坐标?

编辑:我找到了这个例子,但我自己无法弄清楚...... https://github.com/mrdoob/three.js/blob/master/examples/webgl_interactive_voxelpainter.html

谢谢

【问题讨论】:

标签: javascript canvas mouse webgl three.js


【解决方案1】:

这就是答案...

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 );
...

【讨论】:

  • 你知道你可以接受你自己的答案吗?请这样做。 :)
猜你喜欢
  • 2019-04-25
  • 2014-12-02
  • 2017-11-21
  • 1970-01-01
  • 2012-08-07
  • 1970-01-01
  • 1970-01-01
  • 2014-02-07
  • 2021-05-11
相关资源
最近更新 更多