I can’t tell from your question what you are trying to solve, but I’m guessing that you either want to use screenX()
or modelX()
(and Y, and Z).
If you could provide a very simple MCVE in which you draw your plane in P3D then it would be easier to give you more advice.
If this is actually object based problem, there are also approaches like the Picking library. Or if for some reason you can’t use screenX, you could implement something like ray tracing –
or you could try to just compute a simple line-plane intersection. This is untested:
…but you could follow this Java example approach using PVector.dot(). In order to project the line you need to know the camera location
The key fact there is that the default eyeZ is (height/2.0) / tan(PI*30.0 / 180.0)
– so your line works like this:
PVector ray1 = (width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0));
PVector ray2 = (pp1x, pp1y, 0); // eg mouseX, mouseY
…and then you solve for p1 using line-plane intersection, as per 3D Line-Plane Intersection - Stack Overflow
You might also be interested in this recent related post: