javascript - threeJS get real worl position without mesh on cursor? -


code.js

// ... this.width  = 2000 this.height = 2000 // ... this.camera = new three.orthographiccamera(this.width / -2, this.width / 2, this.height / 2, this.height / -2, 1, 1000 ); this.camera.position.z = 100; this.camera.position.x = 600; this.camera.position.y = -900; this.raycaster = new three.raycaster(); // ... this.renderer = new three.webglrenderer({alpha: true, antialias: true}); // ... this.mouse.x = ( event.clientx / this.renderer.domelement.width) * 2 - 1; this.mouse.y = - ( event.clienty / this.renderer.domelement.height ) * 2 + 1; // ... this.raycaster.setfromcamera( this.mouse, this.camera );   this.intersects = this.raycaster.intersectobjects( this.allelements );   if (this.intersects.length == 0) {  // todo: how real world position if don't have mesh on cursor? 

js return real pixel position, this.mouse return local position -1..1, how real world position x: 250, y: 250 not -1,1,etc if i'am don't have mesh on cursor use camera offset. use this: mouse.x - camerapos.x, mouse.y + camerapos.y , incorrect position.

p.s. sorry bad english.

this code work me:

let x = e.clientx - 400 + this.camera.position.x - camerastartpos.x let y = e.clienty - 100 + -this.camera.position.y - camerastartpos.y 

400 , 100 i'am don't know, mb magic!


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -