/** Returns whether the given bounding box is in the frustum. * @return Whether the bounding box is in the frustum */ public boolean boundsInFrustum (Vector3 center, Vector3 dimensions) { return boundsInFrustum(center.x, center.y, center.z, dimensions.x / 2, dimensions.y / 2, dimensions.z / 2); }
/** Checks if entity is inside camera frustum. * * @param entity An entity * @return True if entity is inside camera frustum */ private boolean entityInFrustum (BulletEntity entity) { entity.modelInstance.transform.getTranslation(tmpV1); return frustumCam.frustum.sphereInFrustum(tmpV1.add(entity.boundingBox.getCenter(tmpV2)), entity.boundingBoxRadius); }
@Override public void update (boolean updateFrustum) { float aspect = viewportWidth / viewportHeight; projection.setToProjection(Math.abs(near), Math.abs(far), fieldOfView, aspect); view.setToLookAt(position, tmp.set(position).add(direction), up); combined.set(projection); Matrix4.mul(combined.val, view.val); if (updateFrustum) { invProjectionView.set(combined); Matrix4.inv(invProjectionView.val); frustum.update(invProjectionView); } } }
@Override public void draw3dText (Vector3 location, String textString) { if (spriteBatch == null) { spriteBatch = new SpriteBatch(); } if (font == null) { font = new BitmapFont(); } // this check is necessary to avoid "mirrored" instances of the text if (camera.frustum.pointInFrustum(location)) { if (viewport != null) { camera.project(location, viewport.getScreenX(), viewport.getScreenY(), viewport.getScreenWidth(), viewport.getScreenHeight()); } else { camera.project(location); } shapeRenderer.end(); spriteBatch.begin(); // the text will be centered on the position font.draw(spriteBatch, textString, location.x, location.y, 0, textString.length(), 0, Align.center, false); spriteBatch.end(); shapeRenderer.begin(ShapeType.Line); } }
@Override public void draw3dText (Vector3 location, String textString) { if (spriteBatch == null) { spriteBatch = new SpriteBatch(); } if (font == null) { font = new BitmapFont(); } // this check is necessary to avoid "mirrored" instances of the text if (camera.frustum.pointInFrustum(location)) { if (viewport != null) { camera.project(location, viewport.getScreenX(), viewport.getScreenY(), viewport.getScreenWidth(), viewport.getScreenHeight()); } else { camera.project(location); } shapeRenderer.end(); spriteBatch.begin(); // the text will be centered on the position font.draw(spriteBatch, textString, location.x, location.y, 0, textString.length(), 0, Align.center, false); spriteBatch.end(); shapeRenderer.begin(ShapeType.Line); } }
/** Returns whether the given bounding box is in the frustum. * @return Whether the bounding box is in the frustum */ public boolean boundsInFrustum (Vector3 center, Vector3 dimensions) { return boundsInFrustum(center.x, center.y, center.z, dimensions.x / 2, dimensions.y / 2, dimensions.z / 2); }
@Override public void update (boolean updateFrustum) { float aspect = viewportWidth / viewportHeight; projection.setToProjection(Math.abs(near), Math.abs(far), fieldOfView, aspect); view.setToLookAt(position, tmp.set(position).add(direction), up); combined.set(projection); Matrix4.mul(combined.val, view.val); if (updateFrustum) { invProjectionView.set(combined); Matrix4.inv(invProjectionView.val); frustum.update(invProjectionView); } } }
@Override public <T extends RenderableProvider> void analyze (BaseLight light, Camera camera, Iterable<T> renderableProviders) { getRenderables(renderableProviders); prepareCamera(camera); bb1.inf(); for (Renderable renderable : renderables) { renderable.worldTransform.getTranslation(tmpV); tmpV.add(renderable.meshPart.center); if (camera.frustum.sphereInFrustum(tmpV, renderable.meshPart.radius)) { bb1.ext(tmpV, renderable.meshPart.radius); } } computeResult(bb1, camera); renderablesPool.flush(); renderables.clear(); }
@Override public void draw3dText (Vector3 location, String textString) { if (spriteBatch == null) { spriteBatch = new SpriteBatch(); } if (font == null) { font = new BitmapFont(); } // this check is necessary to avoid "mirrored" instances of the text if (camera.frustum.pointInFrustum(location)) { if (viewport != null) { camera.project(location, viewport.getScreenX(), viewport.getScreenY(), viewport.getScreenWidth(), viewport.getScreenHeight()); } else { camera.project(location); } shapeRenderer.end(); spriteBatch.begin(); // the text will be centered on the position font.draw(spriteBatch, textString, location.x, location.y, 0, textString.length(), 0, Align.center, false); spriteBatch.end(); shapeRenderer.begin(ShapeType.Line); } }
@Override public boolean filter (BaseLight light, Camera camera, Camera mainCamera) { Frustum f1 = mainCamera.frustum; Frustum f2 = camera.frustum; bb.inf(); for (int i = 0; i < f2.planePoints.length; i++) { bb.ext(f2.planePoints[i]); } if (f1.boundsInFrustum(bb)) { return true; } return false; } }
@Override public void update (boolean updateFrustum) { projection.setToOrtho(zoom * -viewportWidth / 2, zoom * (viewportWidth / 2), zoom * -(viewportHeight / 2), zoom * viewportHeight / 2, near, far); view.setToLookAt(position, tmp.set(position).add(direction), up); combined.set(projection); Matrix4.mul(combined.val, view.val); if (updateFrustum) { invProjectionView.set(combined); Matrix4.inv(invProjectionView.val); frustum.update(invProjectionView); } }
@Override public void render () { GL20 gl = Gdx.gl20; gl.glClearColor(0, 0, 0, 0); gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); gl.glEnable(GL20.GL_DEPTH_TEST); cam.update(); modelBatch.begin(cam); int visible = 0; for (int i = 0; i < instances.length; i++) { instances[i].transform.getTranslation(pos); if (cam.frustum.sphereInFrustum(pos, 1)) { ((ColorAttribute)instances[i].materials.get(0).get(ColorAttribute.Diffuse)).color.set(Color.WHITE); visible++; } else { ((ColorAttribute)instances[i].materials.get(0).get(ColorAttribute.Diffuse)).color.set(Color.RED); } modelBatch.render(instances[i]); } modelBatch.end(); 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); gl.glDisable(GL20.GL_DEPTH_TEST); batch.begin(); font.draw(batch, "visible: " + visible + "/100" + ", fps: " + Gdx.graphics.getFramesPerSecond(), 0, 20); batch.end(); }
private void renderDebug () { debugRenderer.setProjectionMatrix(camera.combined); debugRenderer.begin(ShapeType.Line); debugRenderer.setColor(Color.RED); debugRenderer.rect(koala.position.x, koala.position.y, Koala.WIDTH, Koala.HEIGHT); debugRenderer.setColor(Color.YELLOW); TiledMapTileLayer layer = (TiledMapTileLayer)map.getLayers().get("walls"); for (int y = 0; y <= layer.getHeight(); y++) { for (int x = 0; x <= layer.getWidth(); x++) { Cell cell = layer.getCell(x, y); if (cell != null) { if (camera.frustum.boundsInFrustum(x + 0.5f, y + 0.5f, 0, 1, 1, 0)) debugRenderer.rect(x, y, 1, 1); } } } debugRenderer.end(); }
@Override public void update (boolean updateFrustum) { projection.setToOrtho(zoom * -viewportWidth / 2, zoom * (viewportWidth / 2), zoom * -(viewportHeight / 2), zoom * viewportHeight / 2, near, far); view.setToLookAt(position, tmp.set(position).add(direction), up); combined.set(projection); Matrix4.mul(combined.val, view.val); if (updateFrustum) { invProjectionView.set(combined); Matrix4.inv(invProjectionView.val); frustum.update(invProjectionView); } }
for (int i = 0; i < instances.length; i++) { instances[i].transform.getTranslation(tmp); if (cam.frustum.sphereInFrustum(tmp, 1)) { ((ColorAttribute)instances[i].materials.get(0).get(ColorAttribute.Diffuse)).color.set(Color.WHITE); visible++;
/** Returns whether the given bounding box is in the frustum. * @return Whether the bounding box is in the frustum */ public boolean boundsInFrustum (Vector3 center, Vector3 dimensions) { return boundsInFrustum(center.x, center.y, center.z, dimensions.x / 2, dimensions.y / 2, dimensions.z / 2); }
@Override public void update (boolean updateFrustum) { float aspect = viewportWidth / viewportHeight; projection.setToProjection(Math.abs(near), Math.abs(far), fieldOfView, aspect); view.setToLookAt(position, tmp.set(position).add(direction), up); combined.set(projection); Matrix4.mul(combined.val, view.val); if (updateFrustum) { invProjectionView.set(combined); Matrix4.inv(invProjectionView.val); frustum.update(invProjectionView); } } }
public boolean isVisible(final Camera cam) { return cam.frustum.sphereInFrustum(point1.set(position,0), diagonal*.5f); }
if(frustum.boundsInFrustum(x, y, 0f, widthInc, -heightInc, 0f)) textFactory.draw(batch, entry.charValue, entry.floatValue, x, y);
@Override public void update (boolean updateFrustum) { projection.setToOrtho(zoom * -viewportWidth / 2, zoom * (viewportWidth / 2), zoom * -(viewportHeight / 2), zoom * viewportHeight / 2, near, far); view.setToLookAt(position, tmp.set(position).add(direction), up); combined.set(projection); Matrix4.mul(combined.val, view.val); if (updateFrustum) { invProjectionView.set(combined); Matrix4.inv(invProjectionView.val); frustum.update(invProjectionView); } }