public Vector3 calculatePos(int x, int y, Object3D object3D) { Matrix4 mViewMatrix = getCurrentCamera().getViewMatrix(); Matrix4 mProjectionMatrix = getCurrentCamera().getProjectionMatrix(); double[] mNearPos4 = new double[4]; double[] mFarPos4 = new double[4]; Vector3 mNearPos = new Vector3(); Vector3 mFarPos = new Vector3(); Vector3 mNewObjPos = new Vector3(); int[] mViewport = new int[] {0, 0, getViewportWidth(), getViewportHeight()}; GLU.gluUnProject( x, getViewportHeight() - y, 0, mViewMatrix.getDoubleValues(), 0, mProjectionMatrix.getDoubleValues(), 0, mViewport, 0, mNearPos4, 0); GLU.gluUnProject( x, getViewportHeight() - y, 1.f, mViewMatrix.getDoubleValues(), 0, mProjectionMatrix.getDoubleValues(), 0, mViewport, 0, mFarPos4, 0); mNearPos.setAll( mNearPos4[0] / mNearPos4[3], mNearPos4[1] / mNearPos4[3], mNearPos4[2] / mNearPos4[3]); mFarPos.setAll( mFarPos4[0] / mFarPos4[3], mFarPos4[1] / mFarPos4[3], mFarPos4[2] / mFarPos4[3]); double factor = (Math.abs(object3D.getZ()) + mNearPos.z) / (getCurrentCamera().getFarPlane() - getCurrentCamera().getNearPlane()); mNewObjPos.setAll(mFarPos); mNewObjPos.subtract(mNearPos); mNewObjPos.multiply(factor); mNewObjPos.add(mNearPos); return mNewObjPos; }
public Point2D transferTo2D(Vector3 point) { point = point.clone(); point.subtract(planeOrigin); point.rotateBy(planeZRotation); return new Point2D(point.x, point.y); }