Example usage for com.badlogic.gdx.math Affine2 Affine2

List of usage examples for com.badlogic.gdx.math Affine2 Affine2

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Affine2 Affine2.

Prototype

public Affine2() 

Source Link

Document

Constructs an identity matrix.

Usage

From source file:com.trgk.touchwave.tgengine.ui.TGPrimitive.java

License:Open Source License

public static void drawLine(Batch batch, float x0, float y0, float x1, float y1, float lineWidth, Color color) {
    batch.setColor(color);/*  ww  w.ja v a 2s  . c o m*/

    float dv_perp_x = -(y1 - y0);
    float dv_perp_y = x1 - x0;
    float dv_perp_length = (float) Math.sqrt(dv_perp_x * dv_perp_x + dv_perp_y * dv_perp_y);
    dv_perp_x /= dv_perp_length;
    dv_perp_y /= dv_perp_length;

    Affine2 transform = new Affine2();
    transform.m00 = x1 - x0;
    transform.m10 = y1 - y0;
    transform.m01 = dv_perp_x * lineWidth * 2;
    transform.m11 = dv_perp_y * lineWidth * 2;
    transform.m02 = x0 - dv_perp_x * lineWidth;
    transform.m12 = y0 - dv_perp_y * lineWidth;
    batch.draw(TGResources.getInstance().rectTextureRegion, 1, 1, transform);
}

From source file:com.trgk.touchwave.tgengine.ui.TGText.java

License:Open Source License

@Override
public void draw(Batch batch, float parentAlpha) {
    Matrix4 oldTransform = new Matrix4(batch.getTransformMatrix());
    Affine2 localTransform = new Affine2();
    localTransform.setToTrnScl(getX() + getOriginX(), getY() + getOriginY(), getScaleX(), getScaleY());
    localTransform.translate(-getOriginX(), -getOriginY());
    localTransform.scale(1f / TGResources.baseFontSize, 1f / TGResources.baseFontSize);

    Matrix4 localTransformMatrix = new Matrix4();
    localTransformMatrix.set(localTransform);

    Matrix4 newTransform = new Matrix4(oldTransform);
    newTransform.mul(localTransformMatrix);
    batch.setTransformMatrix(newTransform);

    Color alphaMultipliedColor = new Color(getColor());
    alphaMultipliedColor.a *= parentAlpha;
    drawCache.tint(alphaMultipliedColor);
    drawCache.draw(batch);/*from w  ww .java 2 s .c om*/

    batch.setTransformMatrix(oldTransform);
}