/** * 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); }
@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; }
@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; }
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 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... } }
@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; }
/** * 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; } }
@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; }
if (hitEntityLow instanceof GameObject) { stationarityRayColor = Color.RED; stationarityRayHigh.set(stationarityRayLow); stationarityRayHigh.origin.add(0, .8f, 0); Entity hitEntityHigh = GameScreen.screen.engine.rayTest(stationarityRayHigh, null, GameEngine.ALL_FLAG, GameEngine.PC_FLAG, stationarityRayLength, null);