开发者

Z-Axis Coordination in WebGL and Three.js

开发者 https://www.devze.com 2023-03-29 07:09 出处:网络
I\'m experimenting with WebGL and Three.js, But how to calculate the Z-Axis coordination while moving mouse?

I'm experimenting with WebGL and Three.js, But how to calculate the Z-Axis coordination while moving mouse?

I use this for X and Y:

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

how to get Z coordination?

Edit: I find this example, but can't figure it out mysel开发者_运维问答f... 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 );
...
0

精彩评论

暂无评论...
验证码 换一张
取 消