List of usage examples for com.badlogic.gdx.math Matrix4 cpy
public Matrix4 cpy()
From source file:CB_UI_Base.graphics.Images.VectorDrawable.java
License:Open Source License
@Override public void draw(Batch batch, float x, float y, float width, float height) {// Draw only not rotate if (isDisposed.get()) { return;/*from w ww.j a va 2 s . c o m*/ } final Matrix4 oriMatrix = GL.batch.getProjectionMatrix().cpy(); Matrix4 thisDrawMatrix = oriMatrix.cpy(); thisDrawMatrix.translate(x, y, 0); drawFbo(batch, x, y, width, height, oriMatrix, thisDrawMatrix); GL.batch.setProjectionMatrix(oriMatrix); }
From source file:CB_UI_Base.graphics.Images.VectorDrawable.java
License:Open Source License
public void draw(Batch batch, float x, float y, final float width, final float height, float rotated) { if (isDisposed.get()) { return;/*from w ww .ja va2 s. com*/ } final Matrix4 oriMatrix = GL.batch.getProjectionMatrix().cpy(); Matrix4 thisDrawMatrix = oriMatrix.cpy(); thisDrawMatrix.translate(x, y, 0); drawFbo(batch, x, y, width, height, oriMatrix, thisDrawMatrix); for (MatrixDrawable drw : rotateDrawableList) { Matrix4 matrix = thisDrawMatrix.cpy(); ext_Matrix drwMatrix = new GL_Matrix(drw.matrix); matrix.mul(drwMatrix.getMatrix4().cpy()); GL.batch.setProjectionMatrix(matrix); drw.drawable.draw(GL.batch, 0, 0, width, height, -rotated * MathUtils.degreesToRadians); } GL.batch.setProjectionMatrix(oriMatrix); }
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;//from ww w . j av a2 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.badlogic.gdx.ai.tests.utils.bullet.BulletEntity.java
License:Apache License
public BulletEntity(final Model model, final btCollisionObject body, final Matrix4 transform) { this(new ModelInstance(model, transform.cpy()), body); }
From source file:MeshBoneUtil.MeshBone.java
License:Open Source License
public void computeRestParentTransforms() { Vector3 cur_tangent = new Vector3(local_rest_dir.x, local_rest_dir.y, 0); Vector3 cur_binormal = new Vector3(local_binormal_dir.x, local_binormal_dir.y, local_binormal_dir.z); Vector3 cur_normal = new Vector3(local_rest_normal_dir.x, local_rest_normal_dir.y, 0); Matrix4 cur_translate = new Matrix4(); cur_translate.setTranslation(local_rest_end_pt.x, local_rest_end_pt.y, 0); Matrix4 cur_rotate = new Matrix4(); /*//from w ww . j a v a 2 s. com cur_rotate.Right = cur_tangent; cur_rotate.Up = cur_normal; cur_rotate.Backward = cur_binormal; */ cur_rotate.set(cur_tangent, cur_normal, cur_binormal, new Vector3(0, 0, 0)); cur_rotate.tra(); //Matrix4 cur_final = cur_translate * cur_rotate; Matrix4 cur_final = cur_translate.cpy().mul(cur_rotate); //rest_world_mat = rest_parent_mat * cur_final; rest_world_mat = rest_parent_mat.cpy().mul(cur_final); rest_world_inv_mat = rest_world_mat.cpy(); rest_world_inv_mat.inv(); //Matrix4.Invert(ref rest_world_mat, out rest_world_inv_mat); Vector3 world_rest_dir = getWorldRestEndPt().cpy().sub(getWorldRestStartPt()); world_rest_dir.nor(); world_rest_angle = Utils.angleVec4(world_rest_dir); world_rest_pos = getWorldRestStartPt(); Matrix4 bind_translate = new Matrix4(); bind_translate.setTranslation(getWorldRestStartPt().x, getWorldRestStartPt().y, 0); Matrix4 bind_rotate = Utils.calcRotateMat(getWorldRestEndPt().cpy().sub(getWorldRestStartPt())); //Matrix4 cur_bind_final = bind_translate * bind_rotate; Matrix4 cur_bind_final = bind_translate.cpy().mul(bind_rotate); bind_world_mat = cur_bind_final.cpy(); bind_world_inv_mat = bind_world_mat.cpy(); bind_world_inv_mat.inv(); //Matrix4.Invert(ref bind_world_mat, out bind_world_inv_mat); for (int i = 0; i < children.size(); i++) { MeshBone cur_bone = children.get(i); cur_bone.setRestParentMat(rest_world_mat, rest_world_inv_mat); cur_bone.computeRestParentTransforms(); } }
From source file:MeshBoneUtil.MeshBone.java
License:Open Source License
public void computeParentTransforms() { Matrix4 translate_parent = new Matrix4(); translate_parent.setTranslation(getWorldEndPt().x, getWorldEndPt().y, 0); Matrix4 rotate_parent = Utils.calcRotateMat(getWorldEndPt().cpy().sub(getWorldStartPt())); // Matrix4 final_transform = translate_parent * rotate_parent; Matrix4 final_transform = translate_parent.cpy().mul(rotate_parent); Matrix4 final_inv_transform = final_transform.cpy(); final_inv_transform.inv(); //Matrix4.Invert(ref final_transform, out final_inv_transform); for (int i = 0; i < children.size(); i++) { MeshBone cur_bone = children.get(i); cur_bone.setParentWorldMat(final_transform); cur_bone.setParentWorldInvMat(final_inv_transform); cur_bone.computeParentTransforms(); }/*from ww w. j a v a2s. com*/ }
From source file:MeshBoneUtil.MeshBone.java
License:Open Source License
public void computeWorldDeltaTransforms() { Tuple<Vector3, Vector3> calc = computeDirs(world_start_pt, world_end_pt); Vector3 cur_tangent = new Vector3(calc.x.x, calc.x.y, 0); Vector3 cur_normal = new Vector3(calc.y.x, calc.y.y, 0); Vector3 cur_binormal = new Vector3(local_binormal_dir.x, local_binormal_dir.y, local_binormal_dir.z); Matrix4 cur_rotate = new Matrix4(); /*/* w w w . j a v a 2 s. c o m*/ cur_rotate.Right = cur_tangent; cur_rotate.Up = cur_normal; cur_rotate.Backward = cur_binormal; */ cur_rotate.set(cur_tangent, cur_normal, cur_binormal, new Vector3(0, 0, 0)); cur_rotate.tra(); Matrix4 cur_translate = new Matrix4(); cur_translate.setTranslation(world_start_pt.x, world_start_pt.y, 0); /* world_delta_mat = (cur_translate * cur_rotate) * bind_world_inv_mat; */ world_delta_mat = (cur_translate.cpy().mul(cur_rotate)).mul(bind_world_inv_mat); //world_delta_mat = bind_world_inv_mat.cpy().mul(cur_rotate.cpy().mul(cur_translate)); // Quaternion cur_quat = XnaGeometry.Quaternion.CreateFromRotationMatrix(world_delta_mat); Quaternion cur_quat = new Quaternion().setFromMatrix(world_delta_mat); if (cur_quat.z < 0) { //cur_quat = -cur_quat; } Vector3 tmp_pos = new Vector3(); world_delta_mat.getTranslation(tmp_pos); world_dq = new dualQuat(cur_quat, tmp_pos); for (int i = 0; i < children.size(); i++) { MeshBone cur_bone = children.get(i); cur_bone.computeWorldDeltaTransforms(); } }
From source file:MeshBoneUtil.Utils.java
License:Open Source License
public static Matrix4 mulMat(Matrix4 mat_in, float factor) { Matrix4 ret_mat = mat_in.cpy(); float val[] = ret_mat.getValues(); for (int i = 0; i < 16; i++) { val[i] *= factor; }/* ww w. j ava2s. c om*/ ret_mat.set(val); return ret_mat; }