Orthographic view versus a perspective view

What is the correct way to un-project from an orthographic view? I have seen tons of examples for un-projecting with a perspective camera but the approach used does not work for an orthographic camera.

So Vector3.unproject() does not work if you pass in an orthographic camera? Can you please demonstrate the issue with a live example?

To run the example, you have to hold down the ctrl key and attempt to select a rectangular region. The code for a perspective camera has been commented out so the orthographic camera is in use. After you have selected the region, you will see two planes that should be close to parallel. In the orthorgraphic case that doesn’t happen but it does in the perspective.

More importantly, if you look at the code you will see a code comment that shows where to place a break point
and examine the variables



I accidentally hit reply. Let me continue, If you examine the variables and compare them to the camera position which can be found in the vecNear variable you will see that the coordinates are nowhere near the camera in the case of the orthographic camera but in the case of the perspective camera the coordinate values are reasonably close as expected.

Why do you have a negative value for the near property of OrthographicCamera? Both near and far should be greater than zero so the frustum is in front of the camera.

You are correct. I didn’t catch that in the documentation. I changed the near value to a positive value.
I have converted the example to a codepen so that review is easier. To run the example, you have to hold down the ctrl key and attempt to select a rectangular region. You may not see anything but look at the console. You will see for that the perspective camera that the important vectors are nearby which is correct but this is not the case for the orthographic camera.

The name of the vectors in the console represent the vertices of a rectangle as shown below


When I reference the “console”, I mean the console in codepen and not the browser console.

Sry, I don’t understand what you are doing in your codepen. If it’s actually a math issue, then please break down the problem into a smaller test case. Right now, I assume the problem is related to your app logic.

I have removed some code and also added comments to the logic that is important to this discussion. The code in SelectionBox.prototype.createFrustum is the only thing that requires focus. What I’m trying to demonstrate is that after the unproject for an orthographic camera that the coordinates are not in the vicinity of the camera whereas the perspective camera correctly unprojects.

There’s no graphics output only numerical output which can be seen in the codepen console. There I print out the important vector positions. I appreciate your effort.

Any thoughts on this matter? As you can see, I only have to change camera types, and there are two different results. Again, I ask are there extra considerations when un-projecting with an orthographic camera?

This is a problem that I 'm still researching. As I look into it, I have a question about the definition of the projection matrices used in ThreeJS. Can you confirm that they are defined as such: