/** @return a copy of this ray. */ public Ray cpy () { return new Ray(this.origin, this.direction); }
intersection.set(ray.origin); } else { ray.getEndPoint(intersection, t);
/** * Make a ray test along the up/down axis using a ray with origin at the given point and spanning down toward the ground * for the specified distance. * * @param testPoint The origin to the ray * @param distance The length of the ray toward the ground * @param allowedMeshParts Which mesh parts to test. * @return The triangle, or null if ray did not hit any triangles. */ public Triangle groundRayTest(Vector3 testPoint, float distance, Bits allowedMeshParts) { tmpRayVerticalRayTest.set( tmpVerticalRayTest1.set(testPoint), tmpVerticalRayTest2.set(Constants.V3_DOWN)); return rayTest(tmpRayVerticalRayTest, distance, allowedMeshParts); }
intersection.set(ray.origin); } else { ray.getEndPoint(intersection, t);
@Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { lastTouchDown.set(screenX, screenY); lastDragProcessed.set(screenX, screenY); if (button == Input.Buttons.LEFT) { touchDownRay.set(viewport.getPickRay(screenX, screenY)); cameraController.processTouchDownLeft(touchDownRay); } else if (button == Input.Buttons.RIGHT) { cameraController.processTouchDownRight(); } return true; }
/** @return a copy of this ray. */ public Ray cpy () { return new Ray(this.origin, this.direction); }
public Vector3 getRayIntersection(Vector3 out, Ray ray) { // TODO improve performance. use binary search float curDistance = 2; int rounds = 0; ray.getEndPoint(out, curDistance); boolean isUnder = isUnderTerrain(out); while (true) { rounds++; ray.getEndPoint(out, curDistance); boolean u = isUnderTerrain(out); if (u != isUnder || rounds == 10000) { return out; } curDistance += u ? -0.1f : 0.1f; } }
@Override public boolean mouseMoved(int screenX, int screenY) { movedRay.set(viewport.getPickRay(screenX, screenY)); Entity e = engine.rayTest(movedRay, mouseNavMeshPos, GameEngine.NAVMESH_FLAG, GameEngine.NAVMESH_FLAG, GameSettings.CAMERA_PICK_RAY_DST, null); if (e == null) mouseNavMeshPos.set(Float.NaN, Float.NaN, Float.NaN); notifyCursorWorldPosition(mouseNavMeshPos.x, mouseNavMeshPos.y, mouseNavMeshPos.z); mouseScreenPos.set(screenX, screenY); return true; }
/** @return a copy of this ray. */ public Ray cpy () { return new Ray(this.origin, this.direction); }
intersection.set(ray.origin); } else { ray.getEndPoint(intersection, t);
public void setRay(Ray ray, float rayDistance) { this.ray.set(ray); this.rayDistance = rayDistance; rayFrom.set(ray.origin); rayTo.set(ray.direction).scl(rayDistance).add(rayFrom); setRayFromWorld(rayFrom); setRayToWorld(rayTo); }
public static boolean intersectRayWithTriangle(Vector3 r1, Vector3 r2, Vector3 t1, Vector3 t2, Vector3 t3) { Ray ray = new Ray(r1, r2); return Intersector.intersectRayTriangle(ray, t1, t2, t3, null); }
Vector3 rayEnd = getProjectManager().current().currScene.currentSelection.getLocalPosition(temp0); float dst = getProjectManager().current().currScene.cam.position.dst(rayEnd); rayEnd = ray.getEndPoint(rayEnd, dst);
public void setWorldBoundingBox(BoundingBox worldBoundingBox) { this.worldBoundingBox = new BoundingBox(worldBoundingBox); Vector3 min = new Vector3(); Vector3 max = new Vector3(); // Set height of bounding box to zero (y dimension) this.worldBoundingBox.getMax(max).y = 0; this.worldBoundingBox.getMin(min).y = 0; this.worldBoundingBox.set(min, max); ray.set(camera.targetPosition, camera.targetDirection); if (!Intersector.intersectRayBounds(ray, this.worldBoundingBox, worldGroundTarget)) { // TODO: What happens if the center of camera is not aimed at bounding box? // Probably move the camera until it is... } }
public Ray getCameraRay(int mx, int my) { return getCameraRay(mx, my, new Ray()); }
@Override public boolean touchDragged(int screenX, int screenY, int pointer) { dragCurrent.set(screenX, screenY); if (dragCurrent.dst2(lastTouchDown) > GameSettings.MOUSE_DRAG_THRESHOLD) { isDragging = true; if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) { dragCurrentRay.set(viewport.getPickRay(dragCurrent.x, dragCurrent.y)); lastDragProcessedRay.set(viewport.getPickRay(lastDragProcessed.x, lastDragProcessed.y)); cameraController.processDragPan(dragCurrentRay, lastDragProcessedRay); } else if (Gdx.input.isButtonPressed(Input.Buttons.RIGHT)) { cursorDelta.set(lastDragProcessed).sub(screenX, screenY).scl(GameSettings.MOUSE_SENSITIVITY); cameraController.processDragRotation(cursorDelta); } lastDragProcessed.set(screenX, screenY); } mouseMoved(screenX, screenY); return true; }
/** * Checks if the planet p is hit by the screen position x and y. * * @param p * The planet * @return Whether an intersection has occurred */ public static boolean intersectScreenSphere(Planet p, ICamera camera, int sx, int sy, Vector3 v0, Vector3 v1, Vector3 vec, Vector3 intersection) { p.translation.put(vec); v0.set(sx, sy, 0f); v1.set(sx, sy, 0.5f); camera.getCamera().unproject(v0); camera.getCamera().unproject(v1); Ray ray = new Ray(v0, v1.sub(v0).nor()); return Intersector.intersectRaySphere(ray, vec, (float) p.getRadius(), intersection); }
/** * Make a ray test at this point, using a ray spanning from far up in the sky, to far down in the ground, * along the up axis. * * @param testPoint The test point * @param out The point of intersection between ray and triangle * @param allowedMeshParts Which mesh parts to test. Null if all meshparts should be tested. * @return The triangle, or null if ray did not hit any triangles. */ public Triangle verticalRayTest(Vector3 testPoint, Vector3 out, Bits allowedMeshParts) { tmpRayVerticalRayTest.set( tmpVerticalRayTest1.set(Constants.V3_UP).scl(500).add(testPoint), tmpVerticalRayTest2.set(Constants.V3_DOWN)); Triangle hitTri = rayTest(tmpRayVerticalRayTest, 1000, allowedMeshParts); if (hitTri == null) { // TODO: Perhaps this should be Nan? out.set(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY); return null; } else { Intersector.intersectRayTriangle(tmpRayVerticalRayTest, hitTri.a, hitTri.b, hitTri.c, out); return hitTri; } }
Ray ray = new Ray(tmp1.set(V3_UP).scl(1000).add(start), tmp2.set(V3_DOWN)); if (!Intersector.intersectRayTriangle(ray, startTri.a, startTri.b, startTri.c, null)) { float minDst = Float.POSITIVE_INFINITY;
@Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { if (!isDragging) { touchUpRay.set(viewport.getPickRay(screenX, screenY)); Entity hitEntity = engine.rayTest( touchUpRay, tmp, GameEngine.ALL_FLAG, GameEngine.ALL_FLAG, GameSettings.CAMERA_PICK_RAY_DST, visibleLayers); Gdx.app.debug(TAG, "Hit entity " + hitEntity); if (hitEntity instanceof GameCharacter) { characterController.handleCharacterSelection((GameCharacter) hitEntity); } else if (hitEntity == engine.getScene().navmeshBody) { characterController.handleMovementRequest(touchUpRay, visibleLayers); } } isDragging = false; dragCurrent.setZero(); lastDragProcessed.setZero(); return true; }