@Override public Matrix4 getTransformMatrix () { return (adjustNeeded ? virtualMatrix : super.getTransformMatrix()); }
@Override public Matrix4 getTransformMatrix () { return (adjustNeeded ? virtualMatrix : super.getTransformMatrix()); }
@Override public void create () { texture = new Texture(Gdx.files.internal("data/black_marked_0.png")); region = new TextureRegion(texture); batch = new SpriteBatch(); batch.getTransformMatrix().setToTranslation(30.5f, 30.5f, 0); }
/** Sets the transform matrix to be used by this Batch. Even if this is called inside a {@link #begin()}/{@link #end()} block, * the current batch is <em>not</em> flushed to the GPU. Instead, for every subsequent draw() the vertices will be transformed * on the CPU to match the original batch matrix. This adjustment must be performed until the matrices are realigned by * restoring the original matrix, or by calling {@link #flushAndSyncTransformMatrix()} or {@link #end()}. */ public void setTransformMatrix (Affine2 transform) { Matrix4 realMatrix = super.getTransformMatrix(); if (checkEqual(realMatrix, transform)) { adjustNeeded = false; } else { virtualMatrix.setAsAffine(transform); if (isDrawing()) { adjustNeeded = true; // adjust = inverse(real) x virtual // real x adjust x vertex = virtual x vertex if (haveIdentityRealMatrix) { adjustAffine.set(transform); } else { adjustAffine.set(realMatrix).inv().mul(transform); } } else { realMatrix.setAsAffine(transform); haveIdentityRealMatrix = checkIdt(realMatrix); } } }
/** Sets the transform matrix to be used by this Batch. Even if this is called inside a {@link #begin()}/{@link #end()} block, * the current batch is <em>not</em> flushed to the GPU. Instead, for every subsequent draw() the vertices will be transformed * on the CPU to match the original batch matrix. This adjustment must be performed until the matrices are realigned by * restoring the original matrix, or by calling {@link #flushAndSyncTransformMatrix()} or {@link #end()}. */ public void setTransformMatrix (Affine2 transform) { Matrix4 realMatrix = super.getTransformMatrix(); if (checkEqual(realMatrix, transform)) { adjustNeeded = false; } else { virtualMatrix.setAsAffine(transform); if (isDrawing()) { adjustNeeded = true; // adjust = inverse(real) x virtual // real x adjust x vertex = virtual x vertex if (haveIdentityRealMatrix) { adjustAffine.set(transform); } else { adjustAffine.set(realMatrix).inv().mul(transform); } } else { realMatrix.setAsAffine(transform); haveIdentityRealMatrix = checkIdt(realMatrix); } } }
/** Sets the transform matrix to be used by this Batch. Even if this is called inside a {@link #begin()}/{@link #end()} block, * the current batch is <em>not</em> flushed to the GPU. Instead, for every subsequent draw() the vertices will be transformed * on the CPU to match the original batch matrix. This adjustment must be performed until the matrices are realigned by * restoring the original matrix, or by calling {@link #flushAndSyncTransformMatrix()}. */ @Override public void setTransformMatrix (Matrix4 transform) { Matrix4 realMatrix = super.getTransformMatrix(); if (checkEqual(realMatrix, transform)) { adjustNeeded = false; } else { if (isDrawing()) { virtualMatrix.setAsAffine(transform); adjustNeeded = true; // adjust = inverse(real) x virtual // real x adjust x vertex = virtual x vertex if (haveIdentityRealMatrix) { adjustAffine.set(transform); } else { tmpAffine.set(transform); adjustAffine.set(realMatrix).inv().mul(tmpAffine); } } else { realMatrix.setAsAffine(transform); haveIdentityRealMatrix = checkIdt(realMatrix); } } }
/** Sets the transform matrix to be used by this Batch. Even if this is called inside a {@link #begin()}/{@link #end()} block, * the current batch is <em>not</em> flushed to the GPU. Instead, for every subsequent draw() the vertices will be transformed * on the CPU to match the original batch matrix. This adjustment must be performed until the matrices are realigned by * restoring the original matrix, or by calling {@link #flushAndSyncTransformMatrix()}. */ @Override public void setTransformMatrix (Matrix4 transform) { Matrix4 realMatrix = super.getTransformMatrix(); if (checkEqual(realMatrix, transform)) { adjustNeeded = false; } else { if (isDrawing()) { virtualMatrix.setAsAffine(transform); adjustNeeded = true; // adjust = inverse(real) x virtual // real x adjust x vertex = virtual x vertex if (haveIdentityRealMatrix) { adjustAffine.set(transform); } else { tmpAffine.set(transform); adjustAffine.set(realMatrix).inv().mul(tmpAffine); } } else { realMatrix.setAsAffine(transform); haveIdentityRealMatrix = checkIdt(realMatrix); } } }
HdpiUtils.glViewport(0, 0, screenWidth, screenHeight); batch.getProjectionMatrix().idt().setToOrtho2D(0, 0, screenWidth, screenHeight); batch.getTransformMatrix().idt(); batch.begin(); float leftGutterWidth = scalingViewport.getLeftGutterWidth();
} else { batch.getProjectionMatrix().setToOrtho2D(0, 0, 24, 12); batch.getTransformMatrix().idt(); batch.disableBlending(); batch.begin();
@Override public Matrix4 getTransformMatrix () { return (adjustNeeded ? virtualMatrix : super.getTransformMatrix()); }
public void setClip(int x, int y, int w, int h) { Rectangle scissors = new Rectangle(); Rectangle clipBounds = new Rectangle(x, y, w, h); ScissorStack.calculateScissors(orthographicCamera, batch.getTransformMatrix(), clipBounds, scissors); ScissorStack.pushScissors(scissors); }
@Override public void handle (Object source, Type type, Order order) { if (!isEnabled()) return; SpriteBatch batch = GameEvents.gameRenderer.batch; if (type == GameRendererEvent.Type.BatchDebug) { // render everything scaled for (DebugRenderable r : renderables) { if (renderFlags.contains(r.getFlag())) r.renderBatch(batch); } // save original transform matrix xform = batch.getTransformMatrix(); batch.setTransformMatrix(idt); // render static debug information unscaled render(batch); // restore original matrix batch.setTransformMatrix(xform); } else if (type == GameRendererEvent.Type.Debug) { if (renderFlags.contains(RenderFlags.BoundingBoxes3D)) { renderBoundingBoxes(GameEvents.gameRenderer.camPersp); } if (renderFlags.contains(RenderFlags.Box2DWireframe)) { b2drenderer.render(box2dWorld, GameEvents.gameRenderer.mtxOrthographicMvpMt); } for (DebugRenderable r : renderables) { if (renderFlags.contains(r.getFlag())) r.render(); } } } };
@Override public void calculateScissors (Rectangle localRect, Rectangle scissorRect) { ScissorStack.calculateScissors(cameraUI, viewport.getScreenX(), viewport.getScreenY(), viewport.getScreenWidth(), viewport.getScreenHeight(), batch.getTransformMatrix(), localRect, scissorRect); Matrix4 transformMatrix; if (shapeRenderer != null && shapeRenderer.isDrawing()) transformMatrix = shapeRenderer.getTransformMatrix(); else transformMatrix = batch.getTransformMatrix(); ScissorStack.calculateScissors(cameraUI, viewport.getScreenX(), viewport.getScreenY(), viewport.getScreenWidth(), viewport.getScreenHeight(), transformMatrix, localRect, scissorRect); }
public SpriteBatch spriteBatch; private int posX = 100; private int posY = 100; private float angle = 45; private String text = "Hello, World!"; private BitmapFont font; private Matrix4 oldTransformMatrix; Matrix4 mx4Font = new Matrix4(); @Override public void show() { font = new BitmapFont(Gdx.files.internal("someFont.ttf")); oldTransformMatrix = spriteBatch.getTransformMatrix().cpy(); mx4Font.rotate(new Vector3(0, 0, 1), angle); mx4Font.trn(posX, posY, 0); } @Override public void render() { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); spriteBatch.setTransformMatrix(mx4Font); spriteBatch.begin(); font.draw(spriteBatch, text, 0, 0); spriteBatch.end(); spriteBatch.setTransformMatrix(oldTransformMatrix); }
@Override public void drawSpriteCache(SpriteCache spriteCache, int cacheId) { beginRendering(); spriteCache.getProjectionMatrix().set(spriteBatch.getProjectionMatrix().cpy()); spriteCache.getTransformMatrix().set(spriteBatch.getTransformMatrix().cpy()); Gdx.gl.glEnable(GL20.GL_BLEND); spriteCache.begin(); spriteCache.draw(cacheId); spriteCache.end(); }
/** Sets the transform matrix to be used by this Batch. Even if this is called inside a {@link #begin()}/{@link #end()} block, * the current batch is <em>not</em> flushed to the GPU. Instead, for every subsequent draw() the vertices will be transformed * on the CPU to match the original batch matrix. This adjustment must be performed until the matrices are realigned by * restoring the original matrix, or by calling {@link #flushAndSyncTransformMatrix()} or {@link #end()}. */ public void setTransformMatrix (Affine2 transform) { Matrix4 realMatrix = super.getTransformMatrix(); if (checkEqual(realMatrix, transform)) { adjustNeeded = false; } else { virtualMatrix.setAsAffine(transform); if (isDrawing()) { adjustNeeded = true; // adjust = inverse(real) x virtual // real x adjust x vertex = virtual x vertex if (haveIdentityRealMatrix) { adjustAffine.set(transform); } else { adjustAffine.set(realMatrix).inv().mul(transform); } } else { realMatrix.setAsAffine(transform); haveIdentityRealMatrix = checkIdt(realMatrix); } } }
/** Sets the transform matrix to be used by this Batch. Even if this is called inside a {@link #begin()}/{@link #end()} block, * the current batch is <em>not</em> flushed to the GPU. Instead, for every subsequent draw() the vertices will be transformed * on the CPU to match the original batch matrix. This adjustment must be performed until the matrices are realigned by * restoring the original matrix, or by calling {@link #flushAndSyncTransformMatrix()}. */ @Override public void setTransformMatrix (Matrix4 transform) { Matrix4 realMatrix = super.getTransformMatrix(); if (checkEqual(realMatrix, transform)) { adjustNeeded = false; } else { if (isDrawing()) { virtualMatrix.setAsAffine(transform); adjustNeeded = true; // adjust = inverse(real) x virtual // real x adjust x vertex = virtual x vertex if (haveIdentityRealMatrix) { adjustAffine.set(transform); } else { tmpAffine.set(transform); adjustAffine.set(realMatrix).inv().mul(tmpAffine); } } else { realMatrix.setAsAffine(transform); haveIdentityRealMatrix = checkIdt(realMatrix); } } }
Matrix4 tm = batch.getTransformMatrix(); tmp.set(tm);
@Override public void draw(SpriteBatch batch, float x, float y, float scaleX, float scaleY, float rotation, Color tint) { float finalScaleX = EngineAssetManager.getInstance().getScale() * scaleX; float finalScaleY = EngineAssetManager.getInstance().getScale() * scaleY; if (effect.getEmitters().size > 0) { Matrix4 tm = batch.getTransformMatrix(); tmp.set(tm); if (tmpPosX != x / finalScaleX || tmpPosY != y / finalScaleY) { tmpPosX = x / finalScaleX; tmpPosY = y / finalScaleY; effect.setPosition(tmpPosX, tmpPosY); } tm.rotate(0, 0, 1, rotation).scale(finalScaleX, finalScaleY, 1); batch.setTransformMatrix(tm); if (tint != null) batch.setColor(tint); effect.draw(batch); if (tint != null) batch.setColor(Color.WHITE); batch.setTransformMatrix(tmp); } else { x = x - getWidth() / 2 * finalScaleX; RectangleRenderer.draw(batch, x, y, getWidth() * finalScaleX, getHeight() * finalScaleY, Color.RED); } }
@Override public void draw(SpriteBatch batch, float x, float y, float scaleX, float scaleY, float rotation, Color tint) { SkeletonCacheEntry cs = (SkeletonCacheEntry) currentSource; if (cs != null && cs.skeleton != null) { Matrix4 tm = batch.getTransformMatrix(); tmp.set(tm); float originX = cs.skeleton.getRootBone().getX(); float originY = cs.skeleton.getRootBone().getY(); tm.translate(x, y, 0).rotate(0, 0, 1, rotation).scale(scaleX, scaleY, 1).translate(originX, originY, 0); // cs.skeleton.setX(x / scale); // cs.skeleton.setY(y / scale); batch.setTransformMatrix(tm); if (tint != null) cs.skeleton.setColor(tint); renderer.draw(batch, cs.skeleton); if (tint != null) batch.setColor(Color.WHITE); batch.setTransformMatrix(tmp); } else { float dx = getAlignDx(getWidth(), orgAlign); float dy = getAlignDy(getHeight(), orgAlign); RectangleRenderer.draw(batch, x + dx * scaleX, y + dy * scaleY, getWidth() * scaleX, getHeight() * scaleY, Color.RED); } }