Having some trouble. My camera spins around a point. If I don't have the camera near a certain position the points are all wrong.
This is the code I'm using:
private static int Z_PLANE = 0;
public SimpleVector getTouchVector(int xPos,int yPos){
final SimpleVector dir = Interact2D.reproject2D3DWS(world.getCamera(), frameBuffer, xPos, yPos).normalize();
final SimpleVector pos = world.getCamera().getPosition();
final float a = (Z_PLANE - pos.z) / dir.z;
final float xn = pos.x + a * dir.x;
final float yn = pos.y + a * dir.y;
return SimpleVector.create(xn, yn,(float) Z_PLANE);
}
Correct output(camera is is that certain spot):
Touch-- x:117 y:138 (top left)
Point in world space-- x:-26.990156 y:-24.963928 z:0.0
Wrong output (camera is spinned around 90 degrees):
Touch-- x:113 y:126 (top left)
point-- x:-35.060413 y:-65.494 z:0.0