List of usage examples for com.badlogic.gdx.math Matrix4 scale
public Matrix4 scale(float scaleX, float scaleY, float scaleZ)
From source file:CB_UI_Base.graphics.GL_Matrix.java
License:Open Source License
/** * Preconcats the matrix with the specified scale. M' = M * S(x, y) *///w w w . ja va 2 s . c o m @Override public void preScale(float x, float y) { Matrix4 m = new Matrix4(); m.scale(x, y, 1); m.mul(this.matrix4); set(m); }
From source file:CB_UI_Base.graphics.GL_Matrix.java
License:Open Source License
@Override public void postScale(float rx, float ry) { Matrix4 m = new Matrix4(); m.scale(rx, ry, 1); m.mul(this.matrix4); set(m);// ww w .j av a2s . co m }
From source file:CB_UI_Base.graphics.Images.VectorDrawable.java
License:Open Source License
private void drawFbo(Batch batch, float x, float y, final float width, final float height, final Matrix4 oriMatrix, Matrix4 thisDrawMatrix) { final int fboScalerWidth = (int) (this.DEFAULT_WIDTH * FBO_SCALER); final int fboScalerHeight = (int) (this.DEFAULT_HEIGHT * FBO_SCALER); if (!RunOnGlSetted && m_fboEnabled && m_fboRegion == null) { RunOnGlSetted = true;// w w w .jav a 2 s . c o m GL.that.RunOnGL(new IRenderFBO() { @Override public void run() { synchronized (isDisposed) { if (isDisposed.get()) { return; } try { Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST); long start = System.currentTimeMillis(); m_fbo = new FrameBuffer(Format.RGBA8888, fboScalerWidth, fboScalerHeight, false); m_fboRegion = new TextureRegion(m_fbo.getColorBufferTexture()); m_fboRegion.flip(flipX, flipY); m_fbo.begin(); // clear screen Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); GL.batch.setColor(new Color(Color.WHITE)); GL.batch.begin(); Matrix4 matrix = new Matrix4().setToOrtho2D(0, 0, width, height); matrix.scale(FBO_SCALER, FBO_SCALER, 1); GL.batch.setProjectionMatrix(matrix); // draw Background GL.batch.disableBlending(); background.draw(GL.batch, 0, 0, fboScalerWidth, fboScalerHeight); GL.batch.enableBlending(); int count = 0; for (int i = 0, n = drawableList.size(); i < n; i++) { MatrixDrawable drw = drawableList.get(i); if (count++ > 2500) { GL.batch.flush(); count = 0; } matrix = new Matrix4().setToOrtho2D(0, 0, width, height); if (drw.matrix != null) { matrix.mul(drw.matrix.getMatrix4()); } GL.batch.setProjectionMatrix(matrix); drw.drawable.draw(GL.batch, 0, 0, width, height, 0); } if (m_fbo != null) { GL.batch.end(); m_fbo.end(); m_fboEnabled = false; } FBOisDrawed = true; FBO_DrawingTime = System.currentTimeMillis() - start; Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST); GL.batch.setProjectionMatrix(oriMatrix); m_fboEnabled = false; } catch (Exception e) { e.printStackTrace(); } } } }); } if (m_fboRegion != null) { // TODO clear and release the drawables that drawed on m_fboRegion // if first drawing of m_fboRegion batch.draw(m_fboRegion, x, y, width, height); } else { int count = 0; for (int i = 0, n = drawableList.size(); i < n; i++) { MatrixDrawable drw = drawableList.get(i); if (!drw.reaelDraw) continue; if (count++ > 2500) { GL.batch.flush(); count = 0; } Matrix4 matrix = thisDrawMatrix.cpy(); if (drw.matrix != null) matrix.mul(drw.matrix.getMatrix4()); GL.batch.setProjectionMatrix(matrix); drw.drawable.draw(GL.batch, 0, 0, width, height, 0); } } }
From source file:com.kotcrab.vis.runtime.system.render.TextRenderSystem.java
License:Apache License
private void updateText(int entityId) { Matrix4 translationMatrix = text.getTranslationMatrix(); GlyphLayout layout = text.getGlyphLayout(); if (text.isAutoSetOriginToCenter()) { origin.setOrigin(layout.width / 2, layout.height / 2); }/* w w w . j ava 2 s . c om*/ translationMatrix.idt(); translationMatrix.translate(transform.getX() + origin.getOriginX(), transform.getY() + origin.getOriginY(), 0); translationMatrix.rotate(0, 0, 1, transform.getRotation()); translationMatrix.scale(transform.getScaleX(), transform.getScaleY(), 1); translationMatrix.translate(-origin.getOriginX(), -origin.getOriginY(), 0); translationMatrix.translate(0, layout.height, 0); //assign vertices, similar to: (we can skip zeros) //Polygon polygon = new Polygon(new float[]{0, 0, // textLayout.width, 0, // textLayout.width, textLayout.height, // 0, textLayout.height}); polygonVerts[2] = layout.width; polygonVerts[4] = layout.width; polygonVerts[5] = layout.height; polygonVerts[7] = layout.height; polygon.setPosition(transform.getX(), transform.getY()); polygon.setRotation(transform.getRotation()); polygon.setScale(transform.getScaleX(), transform.getScaleY()); polygon.setOrigin(origin.getOriginX(), origin.getOriginY()); text.updateBounds(polygon.getBoundingRectangle()); }
From source file:com.mbrlabs.mundus.commons.g3d.MG3dModelLoader.java
License:Apache License
private ModelNode parseNodesRecursively(JsonValue json) { ModelNode jsonNode = new ModelNode(); String id = json.getString("id", null); if (id == null) throw new GdxRuntimeException("Node id missing."); jsonNode.id = id;//from ww w .j a v a 2 s. c om JsonValue translation = json.get("translation"); if (translation != null && translation.size != 3) throw new GdxRuntimeException("Node translation incomplete"); jsonNode.translation = translation == null ? null : new Vector3(translation.getFloat(0), translation.getFloat(1), translation.getFloat(2)); JsonValue rotation = json.get("rotation"); if (rotation != null && rotation.size != 4) throw new GdxRuntimeException("Node rotation incomplete"); jsonNode.rotation = rotation == null ? null : new Quaternion(rotation.getFloat(0), rotation.getFloat(1), rotation.getFloat(2), rotation.getFloat(3)); JsonValue scale = json.get("scale"); if (scale != null && scale.size != 3) throw new GdxRuntimeException("Node scale incomplete"); jsonNode.scale = scale == null ? null : new Vector3(scale.getFloat(0), scale.getFloat(1), scale.getFloat(2)); String meshId = json.getString("mesh", null); if (meshId != null) jsonNode.meshId = meshId; JsonValue materials = json.get("parts"); if (materials != null) { jsonNode.parts = new ModelNodePart[materials.size]; int i = 0; for (JsonValue material = materials.child; material != null; material = material.next, i++) { ModelNodePart nodePart = new ModelNodePart(); String meshPartId = material.getString("meshpartid", null); String materialId = material.getString("materialid", null); if (meshPartId == null || materialId == null) { throw new GdxRuntimeException("Node " + id + " part is missing meshPartId or materialId"); } nodePart.materialId = materialId; nodePart.meshPartId = meshPartId; JsonValue bones = material.get("bones"); if (bones != null) { nodePart.bones = new ArrayMap<String, Matrix4>(true, bones.size, String.class, Matrix4.class); int j = 0; for (JsonValue bone = bones.child; bone != null; bone = bone.next, j++) { String nodeId = bone.getString("node", null); if (nodeId == null) throw new GdxRuntimeException("Bone node ID missing"); Matrix4 transform = new Matrix4(); JsonValue val = bone.get("translation"); if (val != null && val.size >= 3) transform.translate(val.getFloat(0), val.getFloat(1), val.getFloat(2)); val = bone.get("rotation"); if (val != null && val.size >= 4) transform.rotate( tempQ.set(val.getFloat(0), val.getFloat(1), val.getFloat(2), val.getFloat(3))); val = bone.get("scale"); if (val != null && val.size >= 3) transform.scale(val.getFloat(0), val.getFloat(1), val.getFloat(2)); nodePart.bones.put(nodeId, transform); } } jsonNode.parts[i] = nodePart; } } JsonValue children = json.get("children"); if (children != null) { jsonNode.children = new ModelNode[children.size]; int i = 0; for (JsonValue child = children.child; child != null; child = child.next, i++) { jsonNode.children[i] = parseNodesRecursively(child); } } return jsonNode; }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DMapObjectParser.java
License:Apache License
/** transforms the given matrix according to the given orientation * @param mat the matrix to transform// w w w .j ava 2 s. c o m * @param orientation the orientation */ public void transform(Matrix4 mat, String orientation) { mat.idt(); if (orientation.equals(aliases.isometric)) { mat.scale((float) (Math.sqrt(2) / 2), (float) (Math.sqrt(2) / 4), 1); mat.rotate(0, 0, 1, -45); mat.translate(-1, 1, 0); mat.scale(unitScale * 2, unitScale * 2, unitScale * 2); } else if (orientation.equals(aliases.staggered)) { mat.scale(unitScale, unitScale, unitScale); int mapHeight = findProperty(aliases.height, 0, mapProperties, layerProperties); mat.translate(-tileWidth / 2, -tileHeight * (mapHeight / 2) + tileHeight / 2, 0); } else mat.scale(unitScale, unitScale, unitScale); }
From source file:ta.shape3D.mesh.MeshTA.java
License:Apache License
/** * draw all triangles of the Mesh in the OpenGL environment. * @param rendu the renderer which is used for drawing triangle, you don't need to call the begin() method of this renderer * before using this method./*from ww w .j a va 2 s . c om*/ * @param rendu * @param projectionMatrix The projection matrix in which the mesh will be represented */ final public void render(ImmediateModeRenderer20 rendu, Matrix4 projectionMatrix) { projectionMatrix.translate(tX, tY, tZ); projectionMatrix.rotateRad(Vector3.X, rX); projectionMatrix.rotateRad(Vector3.Y, rY); projectionMatrix.rotateRad(Vector3.Z, rZ); projectionMatrix.scale(scaleX, scaleY, scaleZ); if (image != null) { Gdx.gl20.glEnable(GL20.GL_TEXTURE_2D); Gdx.gl20.glBindTexture(image.glTarget, image.getTextureObjectHandle()); } rendu.begin(projectionMatrix, GL20.GL_TRIANGLES); for (Triangle3D t : triangles) { t.render(rendu); } rendu.end(); Gdx.gl20.glDisable(GL20.GL_TEXTURE_BINDING_2D); for (MeshTA m : sousMesh) { m.render(rendu, projectionMatrix); } projectionMatrix.scale(1 / scaleX, 1 / scaleY, 1 / scaleZ); projectionMatrix.rotateRad(Vector3.X, -rX); projectionMatrix.rotateRad(Vector3.Y, -rY); projectionMatrix.rotateRad(Vector3.Z, -rZ); projectionMatrix.translate(-tX, -tY, -tZ); }