Hey guys,
I am currently moving a particle system around my scene on click. It seems to be working great until I move the camera around. I basically need to know where I am touching the screen regardless of camera direction so the effect is scaled properly and where I am tapping.
This is the relevant part of my onMouseDown(event) function
var mouse = new THREE.Vector2();
if(event.type == "click"){
event.preventDefault();
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
}else{
mouse.x = (event.touches[0].clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.touches[0].clientY / window.innerHeight) * 2 + 1;
}
And then basically if the raycast returns nothing, it grabs the mouse.x and mouse.y and converts to screen position, at least I thought it did?
function convertWorldTouchToScreenPos(x,y){
var vector = new THREE.Vector3(x, y, 0.5);
vector.unproject(_this.camera);
var dir = vector.sub(_this.camera.position).normalize();
var distance = -_this.camera.position.z / dir.z;
var pos = _this.camera.position.clone().add(dir.multiplyScalar(distance));
return pos;
}
Thoughts? Thanks guys!