/** Projects the {@link Vector3} given in world space to screen coordinates. It's the same as GLU gluProject with one small * deviation: The viewport is assumed to span the whole screen. The screen coordinate system has its origin in the * <b>bottom</b> left, with the y-axis pointing <b>upwards</b> and the x-axis pointing to the right. This makes it easily * useable in conjunction with {@link Batch} and similar classes. This method allows you to specify the viewport position and * dimensions in the coordinate system expected by {@link GL20#glViewport(int, int, int, int)}, with the origin in the bottom * left corner of the screen. * @param viewportX the coordinate of the bottom left corner of the viewport in glViewport coordinates. * @param viewportY the coordinate of the bottom left corner of the viewport in glViewport coordinates. * @param viewportWidth the width of the viewport in pixels * @param viewportHeight the height of the viewport in pixels * @return the mutated and projected worldCoords {@link Vector3} */ public Vector3 project (Vector3 worldCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight) { worldCoords.prj(combined); worldCoords.x = viewportWidth * (worldCoords.x + 1) / 2 + viewportX; worldCoords.y = viewportHeight * (worldCoords.y + 1) / 2 + viewportY; worldCoords.z = (worldCoords.z + 1) / 2; return worldCoords; }
/** Projects the {@link Vector3} given in world space to screen coordinates. It's the same as GLU gluProject with one small * deviation: The viewport is assumed to span the whole screen. The screen coordinate system has its origin in the * <b>bottom</b> left, with the y-axis pointing <b>upwards</b> and the x-axis pointing to the right. This makes it easily * useable in conjunction with {@link Batch} and similar classes. This method allows you to specify the viewport position and * dimensions in the coordinate system expected by {@link GL20#glViewport(int, int, int, int)}, with the origin in the bottom * left corner of the screen. * @param viewportX the coordinate of the bottom left corner of the viewport in glViewport coordinates. * @param viewportY the coordinate of the bottom left corner of the viewport in glViewport coordinates. * @param viewportWidth the width of the viewport in pixels * @param viewportHeight the height of the viewport in pixels * @return the mutated and projected worldCoords {@link Vector3} */ public Vector3 project (Vector3 worldCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight) { worldCoords.prj(combined); worldCoords.x = viewportWidth * (worldCoords.x + 1) / 2 + viewportX; worldCoords.y = viewportHeight * (worldCoords.y + 1) / 2 + viewportY; worldCoords.z = (worldCoords.z + 1) / 2; return worldCoords; }
/** Function to translate a point given in screen coordinates to world space. It's the same as GLU gluUnProject, but does not * rely on OpenGL. The x- and y-coordinate of vec are assumed to be in screen coordinates (origin is the top left corner, y * pointing down, x pointing to the right) as reported by the touch methods in {@link Input}. A z-coordinate of 0 will return a * point on the near plane, a z-coordinate of 1 will return a point on the far plane. This method allows you to specify the * viewport position and dimensions in the coordinate system expected by {@link GL20#glViewport(int, int, int, int)}, with the * origin in the bottom left corner of the screen. * @param screenCoords the point in screen coordinates (origin top left) * @param viewportX the coordinate of the bottom left corner of the viewport in glViewport coordinates. * @param viewportY the coordinate of the bottom left corner of the viewport in glViewport coordinates. * @param viewportWidth the width of the viewport in pixels * @param viewportHeight the height of the viewport in pixels * @return the mutated and unprojected screenCoords {@link Vector3} */ public Vector3 unproject (Vector3 screenCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight) { float x = screenCoords.x, y = screenCoords.y; x = x - viewportX; y = Gdx.graphics.getHeight() - y - 1; y = y - viewportY; screenCoords.x = (2 * x) / viewportWidth - 1; screenCoords.y = (2 * y) / viewportHeight - 1; screenCoords.z = 2 * screenCoords.z - 1; screenCoords.prj(invProjectionView); return screenCoords; }
/** Function to translate a point given in screen coordinates to world space. It's the same as GLU gluUnProject, but does not * rely on OpenGL. The x- and y-coordinate of vec are assumed to be in screen coordinates (origin is the top left corner, y * pointing down, x pointing to the right) as reported by the touch methods in {@link Input}. A z-coordinate of 0 will return a * point on the near plane, a z-coordinate of 1 will return a point on the far plane. This method allows you to specify the * viewport position and dimensions in the coordinate system expected by {@link GL20#glViewport(int, int, int, int)}, with the * origin in the bottom left corner of the screen. * @param screenCoords the point in screen coordinates (origin top left) * @param viewportX the coordinate of the bottom left corner of the viewport in glViewport coordinates. * @param viewportY the coordinate of the bottom left corner of the viewport in glViewport coordinates. * @param viewportWidth the width of the viewport in pixels * @param viewportHeight the height of the viewport in pixels * @return the mutated and unprojected screenCoords {@link Vector3} */ public Vector3 unproject (Vector3 screenCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight) { float x = screenCoords.x, y = screenCoords.y; x = x - viewportX; y = Gdx.graphics.getHeight() - y - 1; y = y - viewportY; screenCoords.x = (2 * x) / viewportWidth - 1; screenCoords.y = (2 * y) / viewportHeight - 1; screenCoords.z = 2 * screenCoords.z - 1; screenCoords.prj(invProjectionView); return screenCoords; }
check(vec, fvecs, 3, 5); vec.prj(mat1); Matrix4.prj(mat1.val, fvec); Matrix4.prj(mat1.val, fvecs, 0, 3, 5);
/** Projects the {@link Vector3} given in world space to screen coordinates. It's the same as GLU gluProject with one small * deviation: The viewport is assumed to span the whole screen. The screen coordinate system has its origin in the * <b>bottom</b> left, with the y-axis pointing <b>upwards</b> and the x-axis pointing to the right. This makes it easily * useable in conjunction with {@link Batch} and similar classes. This method allows you to specify the viewport position and * dimensions in the coordinate system expected by {@link GL20#glViewport(int, int, int, int)}, with the origin in the bottom * left corner of the screen. * @param viewportX the coordinate of the bottom left corner of the viewport in glViewport coordinates. * @param viewportY the coordinate of the bottom left corner of the viewport in glViewport coordinates. * @param viewportWidth the width of the viewport in pixels * @param viewportHeight the height of the viewport in pixels * @return the mutated and projected worldCoords {@link Vector3} */ public Vector3 project (Vector3 worldCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight) { worldCoords.prj(combined); worldCoords.x = viewportWidth * (worldCoords.x + 1) / 2 + viewportX; worldCoords.y = viewportHeight * (worldCoords.y + 1) / 2 + viewportY; worldCoords.z = (worldCoords.z + 1) / 2; return worldCoords; }
protected Vector2 project(Vector3 worldCoordinates, Vector2 out) { this.worldCoords.set(worldCoordinates); this.worldCoords.prj(camera.combined); out.x = w * (this.worldCoords.x + 1) / 2 + x; out.y = h * (this.worldCoords.y + 1) / 2 + y; return out; }
/** Function to translate a point given in screen coordinates to world space. It's the same as GLU gluUnProject, but does not * rely on OpenGL. The x- and y-coordinate of vec are assumed to be in screen coordinates (origin is the top left corner, y * pointing down, x pointing to the right) as reported by the touch methods in {@link Input}. A z-coordinate of 0 will return a * point on the near plane, a z-coordinate of 1 will return a point on the far plane. This method allows you to specify the * viewport position and dimensions in the coordinate system expected by {@link GL20#glViewport(int, int, int, int)}, with the * origin in the bottom left corner of the screen. * @param screenCoords the point in screen coordinates (origin top left) * @param viewportX the coordinate of the bottom left corner of the viewport in glViewport coordinates. * @param viewportY the coordinate of the bottom left corner of the viewport in glViewport coordinates. * @param viewportWidth the width of the viewport in pixels * @param viewportHeight the height of the viewport in pixels * @return the mutated and unprojected screenCoords {@link Vector3} */ public Vector3 unproject (Vector3 screenCoords, float viewportX, float viewportY, float viewportWidth, float viewportHeight) { float x = screenCoords.x, y = screenCoords.y; x = x - viewportX; y = Gdx.graphics.getHeight() - y - 1; y = y - viewportY; screenCoords.x = (2 * x) / viewportWidth - 1; screenCoords.y = (2 * y) / viewportHeight - 1; screenCoords.z = 2 * screenCoords.z - 1; screenCoords.prj(invProjectionView); return screenCoords; }
v = v.prj(batch.getTransformMatrix());