/** 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(); }
/** 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(); }
/** 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 boolean zoom (float amount) { if (!alwaysScroll && activateKey != 0 && !activatePressed) return false; camera.translate(tmpV1.set(camera.direction).scl(amount)); if (scrollTarget) target.add(tmpV1); if (autoUpdate) camera.update(); return true; }
public boolean zoom (float amount) { if (!alwaysScroll && activateKey != 0 && !activatePressed) return false; camera.translate(tmpV1.set(camera.direction).scl(amount)); if (scrollTarget) target.add(tmpV1); if (autoUpdate) camera.update(); return true; }
/** 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(); } }
public void update (final Vector3 center, final Vector3 forward) { // cam.position.set(10,10,10); cam.position.set(direction).scl(-halfDepth).add(center); cam.direction.set(direction).nor(); // cam.up.set(forward).nor(); cam.normalizeUp(); cam.update(); }
public void update (final Vector3 center, final Vector3 forward) { // cam.position.set(10,10,10); cam.position.set(direction).scl(-halfDepth).add(center); cam.direction.set(direction).nor(); // cam.up.set(forward).nor(); cam.normalizeUp(); cam.update(); }
public void draw () { Camera camera = viewport.getCamera(); camera.update(); if (!root.isVisible()) return; Batch batch = this.batch; batch.setProjectionMatrix(camera.combined); batch.begin(); root.draw(batch, 1); batch.end(); if (debug) drawDebug(); }
public void draw () { Camera camera = viewport.getCamera(); camera.update(); if (!root.isVisible()) return; Batch batch = this.batch; batch.setProjectionMatrix(camera.combined); batch.begin(); root.draw(batch, 1); batch.end(); if (debug) drawDebug(); }
@Override public void update () { for (ObjectMap.Entry<SpotLight, LightProperties> e : spotCameras) { e.value.camera.position.set(e.key.position); e.value.camera.direction.set(e.key.direction); nearFarAnalyzer.analyze(e.key, e.value.camera, renderableProviders); } for (ObjectMap.Entry<DirectionalLight, LightProperties> e : dirCameras) { directionalAnalyzer.analyze(e.key, e.value.camera, camera).update(); } for (ObjectMap.Entry<PointLight, PointLightProperties> e : pointCameras) { for (ObjectMap.Entry<CubemapSide, LightProperties> c : e.value.properties) { c.value.camera.position.set(e.key.position); nearFarAnalyzer.analyze(e.key, c.value.camera, renderableProviders); } } }
/** Set viewport according to allocator. * @param lp LightProperties to process. * @param cameraViewport Set camera viewport if true. */ protected void processViewport (LightProperties lp, boolean cameraViewport) { Camera camera = lp.camera; ShadowMapRegion r = allocator.nextResult(currentLight); if (r == null) return; TextureRegion region = lp.region; region.setTexture(frameBuffers[currentPass].getColorBufferTexture()); // We don't use HdpiUtils // gl commands related to shadow map size and not to screen size Gdx.gl.glViewport(r.x, r.y, r.width, r.height); Gdx.gl.glScissor(r.x + 1, r.y + 1, r.width - 2, r.height - 2); region.setRegion(r.x, r.y, r.width, r.height); if (cameraViewport) { camera.viewportHeight = r.height; camera.viewportWidth = r.width; camera.update(); } }
public void update () { if (rotateRightPressed || rotateLeftPressed || forwardPressed || backwardPressed) { final float delta = Gdx.graphics.getDeltaTime(); if (rotateRightPressed) camera.rotate(camera.up, -delta * rotateAngle); if (rotateLeftPressed) camera.rotate(camera.up, delta * rotateAngle); if (forwardPressed) { camera.translate(tmpV1.set(camera.direction).scl(delta * translateUnits)); if (forwardTarget) target.add(tmpV1); } if (backwardPressed) { camera.translate(tmpV1.set(camera.direction).scl(-delta * translateUnits)); if (forwardTarget) target.add(tmpV1); } if (autoUpdate) camera.update(); } }
public void update () { if (rotateRightPressed || rotateLeftPressed || forwardPressed || backwardPressed) { final float delta = Gdx.graphics.getDeltaTime(); if (rotateRightPressed) camera.rotate(camera.up, -delta * rotateAngle); if (rotateLeftPressed) camera.rotate(camera.up, delta * rotateAngle); if (forwardPressed) { camera.translate(tmpV1.set(camera.direction).scl(delta * translateUnits)); if (forwardTarget) target.add(tmpV1); } if (backwardPressed) { camera.translate(tmpV1.set(camera.direction).scl(-delta * translateUnits)); if (forwardTarget) target.add(tmpV1); } if (autoUpdate) camera.update(); } }
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; }
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; }
@Override public void create () { texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), true); // Create material attributes. Each material can contain x-number of attributes. textureAttribute = new TextureAttribute(TextureAttribute.Diffuse, texture); colorAttribute = new ColorAttribute(ColorAttribute.Diffuse, Color.ORANGE); blendingAttribute = new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); ModelBuilder builder = new ModelBuilder(); model = builder.createBox(1, 1, 1, new Material(), Usage.Position | Usage.Normal | Usage.TextureCoordinates); model.manageDisposable(texture); modelInstance = new ModelInstance(model); modelInstance.transform.rotate(Vector3.X, 45); material = modelInstance.materials.get(0); builder.begin(); MeshPartBuilder mpb = builder.part("back", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates, new Material( textureAttribute)); mpb.rect(-2, -2, -2, 2, -2, -2, 2, 2, -2, -2, 2, -2, 0, 0, 1); backModel = builder.end(); background = new ModelInstance(backModel); modelBatch = new ModelBatch(); camera = new PerspectiveCamera(45, 4, 4); camera.position.set(0, 0, 3); camera.direction.set(0, 0, -1); camera.update(); Gdx.input.setInputProcessor(this); }
@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(); }
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 (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); } }