While many people are interested in converting camera position to screen position, my question is how to achieve the opposite.
Currently, I am trying to set the position of the "door" as a percentage of the screen, with the necessary calculations already done and the final screen X, Y (px) position known. The current Z offset is set at 250 for the camera.
I came across this code for converting camera position to screen position:
var vector = projector.projectVector(door.position.clone(), camera);
vector.x = (vector.x + 1) / 2 * window.innerWidth;
vector.y = -(vector.y - 1) / 2 * window.innerHeight;
I attempted to reverse this process with the following code, but it did not yield the expected result:
var mouseX = ((perc.x) / window.innerWidth) * 2 - 1,
mouseY = -((perc.y) / window.innerHeight) * 2 + 1;
var vector = new THREE.Vector3(mouseX, mouseY, 1);
projector.unprojectVector(vector, camera);
return vector.sub(camera.position).normalize()
I have tried various methods and searched online, but have not found a solution.
Q: How can I convert screen position to camera position?