1

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 myself... https://github.com/mrdoob/three.js/blob/master/examples/webgl_interactive_voxelpainter.html

Thanks

2
  • 2
    I find the answer, but Stackoverflow doesn't allow me to answer my question...here is the answer: catchvar.com/threejs-game-transforming-isometric-screen-co Commented Aug 20, 2011 at 22:03
  • Strange that SO doesn't let you answer your question. Maybe you have to have a certain amount of rep first? Commented Aug 21, 2011 at 3:48

1 Answer 1

1

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 );
...
Sign up to request clarification or add additional context in comments.

1 Comment

You do realize you can accept your own answer? Please do so. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.