Refine search
/** Calculates a scissor rectangle in OpenGL ES window coordinates from a {@link Camera}, a transformation {@link Matrix4} and * an axis aligned {@link Rectangle}. The rectangle will get transformed by the camera and transform matrices and is then * projected to screen coordinates. Note that only axis aligned rectangles will work with this method. If either the Camera or * the Matrix4 have rotational components, the output of this method will not be suitable for * {@link GL20#glScissor(int, int, int, int)}. * @param camera the {@link Camera} * @param batchTransform the transformation {@link Matrix4} * @param area the {@link Rectangle} to transform to window coordinates * @param scissor the Rectangle to store the result in */ public static void calculateScissors (Camera camera, float viewportX, float viewportY, float viewportWidth, float viewportHeight, Matrix4 batchTransform, Rectangle area, Rectangle scissor) { tmp.set(area.x, area.y, 0); tmp.mul(batchTransform); camera.project(tmp, viewportX, viewportY, viewportWidth, viewportHeight); scissor.x = tmp.x; scissor.y = tmp.y; tmp.set(area.x + area.width, area.y + area.height, 0); tmp.mul(batchTransform); camera.project(tmp, viewportX, viewportY, viewportWidth, viewportHeight); scissor.width = tmp.x - scissor.x; scissor.height = tmp.y - scissor.y; }
/** 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; }
/** Rotates the direction and up vector of this camera by the given angle around the given axis, with the axis attached to given * point. The direction and up vector will not be orthogonalized. * * @param point the point to attach the axis to * @param axis the axis to rotate around * @param angle the angle, in degrees */ public void rotateAround (Vector3 point, Vector3 axis, float angle) { tmpVec.set(point); tmpVec.sub(position); translate(tmpVec); rotate(axis, angle); tmpVec.rotate(axis, angle); translate(-tmpVec.x, -tmpVec.y, -tmpVec.z); }
protected boolean process (float deltaX, float deltaY, int button) { if (button == rotateButton) { tmpV1.set(camera.direction).crs(camera.up).y = 0f; camera.rotateAround(target, tmpV1.nor(), deltaY * rotateAngle); camera.rotateAround(target, Vector3.Y, deltaX * -rotateAngle); } else if (button == translateButton) { camera.translate(tmpV1.set(camera.direction).crs(camera.up).nor().scl(-deltaX * translateUnits)); camera.translate(tmpV2.set(camera.up).scl(-deltaY * translateUnits)); if (translateTarget) target.add(tmpV1).add(tmpV2); } else if (button == forwardButton) { camera.translate(tmpV1.set(camera.direction).scl(deltaY * translateUnits)); if (forwardTarget) target.add(tmpV1); } if (autoUpdate) camera.update(); return true; }
public void update (float deltaTime) { if (keys.containsKey(FORWARD)) { tmp.set(camera.direction).nor().scl(deltaTime * velocity); camera.position.add(tmp); } if (keys.containsKey(BACKWARD)) { tmp.set(camera.direction).nor().scl(-deltaTime * velocity); camera.position.add(tmp); } if (keys.containsKey(STRAFE_LEFT)) { tmp.set(camera.direction).crs(camera.up).nor().scl(-deltaTime * velocity); camera.position.add(tmp); } if (keys.containsKey(STRAFE_RIGHT)) { tmp.set(camera.direction).crs(camera.up).nor().scl(deltaTime * velocity); camera.position.add(tmp); } if (keys.containsKey(UP)) { tmp.set(camera.up).nor().scl(deltaTime * velocity); camera.position.add(tmp); } if (keys.containsKey(DOWN)) { tmp.set(camera.up).nor().scl(-deltaTime * velocity); camera.position.add(tmp); } camera.update(true); } }
public void update(long now) { if (up && !down) { camera.position.y += speed; camera.update(); camera.update(); camera.position.add(ortho); camera.update(); camera.position.add(ortho); camera.update(); camera.rotate(Vector3.Y, -turnSpeed); camera.update(); camera.rotate(Vector3.Y, turnSpeed); camera.update(); d.scl(speed); camera.position.add(d); camera.update(); d.scl(-speed); camera.position.add(d); camera.update();
/** 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 world coordinate to screen coordinates. * @return The vector that was passed in, transformed to screen coordinates. * @see Camera#project(Vector3) */ public Vector2 project (Vector2 worldCoords) { tmp.set(worldCoords.x, worldCoords.y, 1); camera.project(tmp, screenX, screenY, screenWidth, screenHeight); worldCoords.set(tmp.x, tmp.y); return worldCoords; }
/** Applies the viewport to the camera and sets the glViewport. * @param centerCamera If true, the camera position is set to the center of the world. */ public void apply (boolean centerCamera) { HdpiUtils.glViewport(screenX, screenY, screenWidth, screenHeight); camera.viewportWidth = worldWidth; camera.viewportHeight = worldHeight; if (centerCamera) camera.position.set(worldWidth / 2, worldHeight / 2, 0); camera.update(); }
public void setupCamera(float[] up, float[] lookAt) { camera.up.set(-up[0], up[2], up[1]); forwardVector.x = -lookAt[0]; forwardVector.y = lookAt[2]; forwardVector.z = lookAt[1]; camera.lookAt(forwardVector); camera.update(); ray = camera.getPickRay(w / 2, h / 2); }
/** Compute final result. * @param bb BoundingBox encompassing instances * @param camera Camera to compute */ protected void computeResult (BoundingBox bb, Camera camera) { // Radius float radius = bb1.getDimensions(tmpV).len() * 0.5f; // Center bb1.getCenter(tmpV); // Computation float distance = tmpV.dst(camera.position); float near = distance - radius; float far = distance + radius; if (near <= 0) near = CAMERA_NEAR; if (far <= 0) far = CAMERA_FAR; camera.near = near; camera.far = far; camera.update(); } }
private final Camera mCamera = new Camera(); private final Matrix mMatrix = new Matrix(); double degree = 90 - (180 / Math.PI) * radians; mCamera.save(); mCamera.translate(0, 0, radius - translateZ); mCamera.rotateX((float) degree); // remove this line.. if (distanceY < 0) { degree = 360 - degree; mCamera.rotateY((float) degree); // and change this to rotateX() to get a mCamera.getMatrix(mMatrix); mCamera.restore();
Gdx.gl.glEnable(GL20.GL_DEPTH_TEST); cam.update(); if (Gdx.input.isKeyPressed(Keys.A)) cam.rotate(20 * Gdx.graphics.getDeltaTime(), 0, 1, 0); if (Gdx.input.isKeyPressed(Keys.D)) cam.rotate(-20 * Gdx.graphics.getDeltaTime(), 0, 1, 0); for (int i = 0; i < instances.length; i++) { instances[i].transform.getTranslation(tmp); cam.project(tmp); if (tmp.z < 0) continue; batch.draw(logo, tmp.x, tmp.y);
/** Transforms the specified world coordinate to screen coordinates. * @return The vector that was passed in, transformed to screen coordinates. * @see Camera#project(Vector3) */ public Vector3 project (Vector3 worldCoords) { camera.project(worldCoords, screenX, screenY, screenWidth, screenHeight); return worldCoords; }
/** Initialize camera before computation. * @param camera Camera to compute. */ protected void prepareCamera (Camera camera) { camera.near = AABBNearFarAnalyzer.CAMERA_NEAR; camera.far = AABBNearFarAnalyzer.CAMERA_FAR; camera.update(); }