/** Transforms the specified screen coordinate to world coordinates. * @return The vector that was passed in, transformed to world coordinates. * @see Camera#unproject(Vector3) */ public Vector3 unproject (Vector3 screenCoords) { camera.unproject(screenCoords, screenX, screenY, screenWidth, screenHeight); return screenCoords; }
/** Transforms the specified screen coordinate to world coordinates. * @return The vector that was passed in, transformed to world coordinates. * @see Camera#unproject(Vector3) */ public Vector3 unproject (Vector3 screenCoords) { camera.unproject(screenCoords, screenX, screenY, screenWidth, screenHeight); 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 viewport is assumed to span the whole screen and is fetched from {@link Graphics#getWidth()} and * {@link Graphics#getHeight()}. 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. * @param screenCoords the point in screen coordinates * @return the mutated and unprojected screenCoords {@link Vector3} */ public Vector3 unproject (Vector3 screenCoords) { unproject(screenCoords, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); return screenCoords; }
/** Transforms the specified screen coordinate to world coordinates. * @return The vector that was passed in, transformed to world coordinates. * @see Camera#unproject(Vector3) */ public Vector2 unproject (Vector2 screenCoords) { tmp.set(screenCoords.x, screenCoords.y, 1); camera.unproject(tmp, screenX, screenY, screenWidth, screenHeight); screenCoords.set(tmp.x, tmp.y); return screenCoords; }
/** Transforms the specified screen coordinate to world coordinates. * @return The vector that was passed in, transformed to world coordinates. * @see Camera#unproject(Vector3) */ public Vector2 unproject (Vector2 screenCoords) { tmp.set(screenCoords.x, screenCoords.y, 1); camera.unproject(tmp, screenX, screenY, screenWidth, screenHeight); screenCoords.set(tmp.x, tmp.y); 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 viewport is assumed to span the whole screen and is fetched from {@link Graphics#getWidth()} and * {@link Graphics#getHeight()}. 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. * @param screenCoords the point in screen coordinates * @return the mutated and unprojected screenCoords {@link Vector3} */ public Vector3 unproject (Vector3 screenCoords) { unproject(screenCoords, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); return screenCoords; }
/** Creates a picking {@link Ray} from the coordinates given in screen coordinates. It is assumed that the viewport spans the * whole screen. The screen coordinates origin is assumed to be in the top left corner, its y-axis pointing down, the x-axis * pointing to the right. The returned instance is not a new instance but an internal member only accessible via this function. * @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 picking Ray. */ public Ray getPickRay (float screenX, float screenY, float viewportX, float viewportY, float viewportWidth, float viewportHeight) { unproject(ray.origin.set(screenX, screenY, 0), viewportX, viewportY, viewportWidth, viewportHeight); unproject(ray.direction.set(screenX, screenY, 1), viewportX, viewportY, viewportWidth, viewportHeight); ray.direction.sub(ray.origin).nor(); return ray; }
/** Creates a picking {@link Ray} from the coordinates given in screen coordinates. It is assumed that the viewport spans the * whole screen. The screen coordinates origin is assumed to be in the top left corner, its y-axis pointing down, the x-axis * pointing to the right. The returned instance is not a new instance but an internal member only accessible via this function. * @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 picking Ray. */ public Ray getPickRay (float screenX, float screenY, float viewportX, float viewportY, float viewportWidth, float viewportHeight) { unproject(ray.origin.set(screenX, screenY, 0), viewportX, viewportY, viewportWidth, viewportHeight); unproject(ray.direction.set(screenX, screenY, 1), viewportX, viewportY, viewportWidth, viewportHeight); ray.direction.sub(ray.origin).nor(); return ray; }
/** Transforms the specified screen coordinate to world coordinates. * @return The vector that was passed in, transformed to world coordinates. * @see Camera#unproject(Vector3) */ public Vector3 unproject (Vector3 screenCoords) { camera.unproject(screenCoords, screenX, screenY, screenWidth, screenHeight); return screenCoords; }
/** Transforms the specified screen coordinate to world coordinates. * @return The vector that was passed in, transformed to world coordinates. * @see Camera#unproject(Vector3) */ public Vector2 unproject (Vector2 screenCoords) { tmp.set(screenCoords.x, screenCoords.y, 1); camera.unproject(tmp, screenX, screenY, screenWidth, screenHeight); screenCoords.set(tmp.x, tmp.y); return screenCoords; }
/** * Helper function to get the actual coordinates in my world * @param x * @param y */ private void translateScreenToWorldCoordinates(int x, int y) { getCamera().unproject(touchPoint.set(x, y, 0)); }
/** 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 viewport is assumed to span the whole screen and is fetched from {@link Graphics#getWidth()} and * {@link Graphics#getHeight()}. 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. * @param screenCoords the point in screen coordinates * @return the mutated and unprojected screenCoords {@link Vector3} */ public Vector3 unproject (Vector3 screenCoords) { unproject(screenCoords, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); return screenCoords; }
@Override public boolean touchDragged(int x, int y, int pointer) { viewport.getCamera().unproject(point.set(x, y, 0)); if(Gdx.input.isButtonPressed(Buttons.LEFT)) { light.setPosition(point.x, point.y); } return false; }
@Override public boolean touchDown (int screenX, int screenY, int pointer, int button) { if (button == Input.Buttons.LEFT) { //Translate screen coordinates into world units viewport.getCamera().unproject(point.set(screenX, screenY, 0)); light.setPosition(point.x, point.y); light.setActive(true); return true; } return false; }
@Override public boolean mouseMoved(int screenX, int screenY) { viewport.getCamera().unproject(point.set(screenX, screenY, 0)); pointerBody.setTransform(point.x, point.y, pointerBody.getAngle() + 5 * MathUtils.degreesToRadians); return true; }
@Override public boolean touchDragged (int x, int y, int pointer) { // To keep the object responsive after clicking the first time // It will just update the target coordinates if (mouseJoint != null) { viewport.getCamera().unproject(point.set(x, y, 0)); mouseJoint.setTarget(target.set(point.x, point.y)); } return false; }
@Override public boolean touchDragged (int x, int y, int pointer) { // To keep the object responsive after clicking the first time // It will just update the target coordinates if (mouseJoint != null) { viewport.getCamera().unproject(point.set(x, y, 0)); mouseJoint.setTarget(target.set(point.x, point.y)); } return false; }
@Override public boolean touchDragged(int x, int y, int pointer) { viewport.getCamera().unproject(point.set(x, y, 0)); if(Gdx.input.isButtonPressed(Buttons.LEFT)) { if(p1.x != point.x && p1.y != point.y) { p2.set(point.x, point.y); world.rayCast(callback, p1, p2); return true; } } return false; }
@Override public boolean touchDown (int x, int y, int pointer, int button) { // Screen coordinates to World coordinates viewport.getCamera().unproject(point.set(x, y, 0)); if (button == Input.Buttons.LEFT) { p1.set(point.x, point.y); p2.set(point.x, point.y+0.00001f); // +.00001 because otherwise it will crash normal.set(Vector2.Zero); collision.set(Vector2.Zero); world.rayCast(callback, p1, p2); return true; } return false; }
@Override public boolean touchDown (int x, int y, int pointer, int button) { // Screen coordinates to world coordinates viewport.getCamera().unproject(point.set(x, y, 0)); if (button == Input.Buttons.LEFT) { float force = 100f * player1.getBody().getMass(); Vector2 target = new Vector2(point.x, point.y); Vector2 direction = target.sub(player1.getBody().getPosition()); player1.getBody().applyForceToCenter(direction.scl(force), true); } return false; }