/** Unprojects screen position into world space; 0,0,0 is center of screen * * @param x {@code double} x value, cartesian coordinates relative to center of sceen. * @param y {@code double} y value, cartesian coordinates relative to center of sceen. * @param z {@code double} z value, cartesian coordinates relative to center of sceen. */ public Vector3 unProject(double x, double y, double z) { final double[] in = new double[4], out = new double[4]; Matrix4 projectionMatrix = getCurrentCamera().getProjectionMatrix().clone(); Matrix4 MVPMatrix = projectionMatrix.multiply(getCurrentCamera().getViewMatrix()); MVPMatrix.inverse(); in[0] = x; in[1] = y; in[2] = z; in[3] = 1; Matrix.multiplyMV(out, 0, MVPMatrix.getDoubleValues(), 0, in, 0); if (out[3] == 0) return null; out[3] = 1 / out[3]; return new Vector3(out[0] * out[3], out[1] * out[3], out[2] * out[3]); }
mPMatrix = mCamera.getProjectionMatrix();
double screenPositionPixels_x, screenPositionPixels_y; Camera camera = mRenderer.getCurrentScene().getCamera(); Matrix4 viewMatrix = camera.getViewMatrix().clone(), projMatrix = camera.getProjectionMatrix().clone();
public Vector3 unProject(double x, double y, double z) { x = mDefaultViewportWidth - x; y = mDefaultViewportHeight - y; final double[] in = new double[4], out = new double[4]; Matrix4 MVPMatrix = getCurrentCamera().getProjectionMatrix().multiply(getCurrentCamera().getViewMatrix()); MVPMatrix.inverse(); in[0] = (x / mDefaultViewportWidth) * 2 - 1; in[1] = (y / mDefaultViewportHeight) * 2 - 1; in[2] = 2 * z - 1; in[3] = 1; Matrix.multiplyMV(out, 0, MVPMatrix.getDoubleValues(), 0, in, 0); if (out[3] == 0) return null; out[3] = 1 / out[3]; return new Vector3(out[0] * out[3], out[1] * out[3], out[2] * out[3]); }
mPMatrix = mCamera.getProjectionMatrix();
double screenPositionPixels_x, screenPositionPixels_y; Camera camera = mRenderer.getCurrentScene().getCamera(); Matrix4 viewMatrix = camera.getViewMatrix().clone(), projMatrix = camera.getProjectionMatrix().clone();