0
votes

Can anybody make it clear to me why i am getting like {x:Infinity, y:-Infinity, z:-Infinity} from my position values like {x:0.50516157, y:-0.62950189, z:0} when i am trying to project my position vector onto the camera. I have found a similar query Converting World coordinates to Screen coordinates in Three.js using Projection on this but the solution does not solve my problem. It would be really help full and time saving if someone can help me.

var screenvector = new THREE.Vector3();
var position = new THREE.Vector3();
position = convertLatLontoVec3(lat, lng).multiplyScalar(radius);
//convertLatLontoVec3(returns new THREE.Vector3(x, y, z);)
screenvector.copy(position);
//till here during debugging i can find the values of position.x, .y, .z 
screenvector.project(camera); //But once this step is executed all the values are becoming infintiy. I don't understand why is it happening. 
1
check camera.projectionMatrix and whether camera.matrixWorld is invertible (that is new THREE.Matrix4().getInverse(camera.matrixWorld)) we cannot answer you without knowing how your camera is set upDerte Trdelnik
umm, is this projection or unprojection? Just a wild guess without bothering to open a diagram of the NDC but i think you should be getting infinity if you are behind the camera. A screen vector you probably want to unprojectpailhead
Thank you for your response, for better understanding here is my code please have a look at it and if there is anything wrong pastebin.com/ei7T0mXrsravan
After some struggle here i got the answer. Before projecting my screenvector onto the camera i have forgot to update my camera.updateMatrixWorld(); and now i have the valid coordinates..sravan

1 Answers

3
votes

If you are projecting a "screen space" vector, you are most likely right at the camera's origin in view/worldSpace, (z==0 in the diagram). Infinity makes sense here. You probably want to unproject.

projecting from camera position

Starting from z==0, anything behind the camera is just infinity (i think).