Example usage for com.badlogic.gdx.math Matrix4 rotate

List of usage examples for com.badlogic.gdx.math Matrix4 rotate

Introduction

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

Prototype

public Matrix4 rotate(float axisX, float axisY, float axisZ, float degrees) 

Source Link

Document

Postmultiplies this matrix with a (counter-clockwise) rotation matrix.

Usage

From source file:br.com.raphaelbruno.game.zombieinvaders.vr.model.GameObject.java

License:Apache License

public void lookAt(Vector3 point) {
    Vector3 from = transform.getTranslation(new Vector3()).cpy();
    Vector3 to = point.cpy();//from w w  w . j av  a  2 s .  co  m
    Vector3 direction = to.sub(from).nor();
    direction.set(-direction.x, -direction.y, -direction.z);

    Quaternion quaternion = new Quaternion();
    Matrix4 instanceRotation = transform.cpy().mul(transform);

    instanceRotation.setToLookAt(direction, new Vector3(0, -1, 0));
    instanceRotation.rotate(0, 0, 1, 180);
    instanceRotation.getRotation(quaternion);

    transform.set(from, quaternion);
}

From source file:CB_UI_Base.graphics.GL_Matrix.java

License:Open Source License

/**
 * Postconcats the matrix with the specified rotation. M' = R(degrees) * M
 *//*from  ww  w.ja  v  a2s  .  c  o  m*/
@Override
public void postRotate(float angle) {
    Matrix4 m = new Matrix4();
    m.rotate(0, 0, 1, angle);
    m.mul(this.matrix4);
    set(m);
}

From source file:CB_UI_Base.graphics.GL_Matrix.java

License:Open Source License

@Override
public void preRotate(float angle) {
    Matrix4 m = new Matrix4();
    m.rotate(0, 0, 1, angle);
    m.mul(this.matrix4);
    set(m);/*from w  w w. j  a va 2  s . c  o m*/
}

From source file:CB_UI_Base.graphics.GL_Matrix.java

License:Open Source License

@Override
public void preRotate(Float angle, Float px, Float py) {

    // ## native android ##
    // const SkScalar oneMinusCosV = 1 - cosV;
    ////from  ww w .jav a  2s .  c  om
    // fMat[kMScaleX] = cosV;
    // fMat[kMSkewX] = -sinV;
    // fMat[kMTransX] = sdot(sinV, py, oneMinusCosV, px);
    //
    // fMat[kMSkewY] = sinV;
    // fMat[kMScaleY] = cosV;
    // fMat[kMTransY] = sdot(-sinV, px, oneMinusCosV, py);
    //
    // fMat[kMPersp0] = fMat[kMPersp1] = 0;
    // fMat[kMPersp2] = 1;

    Matrix4 m = new Matrix4();
    m.rotate(0, 0, 1, angle);
    float oneMinusCosV = 1 - m.val[Matrix4.M00];
    float sinV = m.val[Matrix4.M10];
    m.val[Matrix4.M03] = sdot(sinV, py, oneMinusCosV, px);
    m.val[Matrix4.M13] = sdot(-sinV, px, oneMinusCosV, py);

    this.matrix4.mul(m);
}

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);
    }/*from  w  ww .j av a  2 s  . c  o m*/

    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.lyeeedar.Roguelike3D.Game.LevelObjects.Door.java

License:Open Source License

@Override
public void update(float delta, Camera cam) {

    if (particleEffect != null) {
        particleEffect.update(delta, cam);
    }/* www. j  a  v a2s  . c  o m*/

    if (moving) {
        if (!open) {
            angle += delta * 100;

            if (angle > 90) {
                angle = 90;
                solid = false;
                open = true;
                moving = false;
            }

            Matrix4 hinge = new Matrix4();
            hinge.translate(-hingex, 0, -hingez);
            hinge.rotate(0, 1, 0, angle);
            hinge.translate(hingex, 0, hingez);

            vo.attributes.getRotation().set(hinge);
        } else {
            solid = true;
            angle -= delta * 100;

            if (angle < 0) {
                open = false;
                angle = 0;
                moving = false;
            }

            Matrix4 hinge = new Matrix4();
            hinge.translate(-hingex, 0, -hingez);
            hinge.rotate(0, 1, 0, angle);
            hinge.translate(hingex, 0, hingez);

            vo.attributes.getRotation().set(hinge);
        }
    }

}

From source file:com.qualcomm.vuforia.samples.Vuforia.VuforiaCamera.java

License:Apache License

@Override
public void update(boolean updateFrustum) {
    float aspect = viewportWidth / viewportHeight;

    float[] ViewMatrix = DataHolder.getInstance().getData();
    float[] ProjMatrix = DataHolder.getInstance().getData2();

    if (ViewMatrix != null && ProjMatrix != null) {

        Matrix4 temp = new Matrix4(ViewMatrix.clone());
        Matrix4 temp2 = new Matrix4(ProjMatrix.clone());

        temp.rotate(1, 0, 0, 90);

        projection.set(temp2);//w w w . jav a  2s .  c  o m
        view.set(temp);

        //            projection.setToProjection(Math.abs(near), Math.abs(far), fieldOfView, aspect);
        //            view.setToLookAt(position, tmp.set(position).add(direction), up);

        combined.set(projection);
        Matrix4.mul(combined.val, view.val);

        if (updateFrustum) {
            invProjectionView.set(combined);
            Matrix4.inv(invProjectionView.val);
            frustum.update(invProjectionView);
        }

    }

}

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  . java 2 s.  c  om*/
 *  @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:vault.clockwork.editor.props.PlankProp.java

License:Open Source License

/**
 * @param gizmo //  w w  w.  j  av  a2 s.  c  om
 */
@Override
public void draw(ShapeRenderer gizmo) {
    Matrix4 transform = new Matrix4();
    transform.translate(position.x, position.y, 0);
    transform.rotate(0, 0, 1, angle);

    gizmo.setTransformMatrix(transform);
    gizmo.rect(-width, -height, width * 2, height * 2);
    gizmo.setTransformMatrix(new Matrix4());
    gizmo.setColor(Color.CYAN);
    gizmo.line(position, position.cpy().add(new Vector2(move_direction_x, move_direction_y).nor().scl(64.f)));
    gizmo.setColor(Color.YELLOW);
}

From source file:vault.clockwork.editor.props.StaticPlankProp.java

License:Open Source License

/**
 * @param gizmo /*  w  w w .j  a  va  2 s.c o  m*/
 */
@Override
public void draw(ShapeRenderer gizmo) {
    Matrix4 transform = new Matrix4();
    transform.translate(position.x, position.y, 0);
    transform.rotate(0, 0, 1, angle);

    gizmo.setTransformMatrix(transform);
    gizmo.rect(-width, -height, width * 2, height * 2);
    gizmo.setTransformMatrix(new Matrix4());

    gizmo.setColor(Color.ORANGE);
    gizmo.line(position, position.cpy().add(new Vector2(width, height).nor().scl(64.f)));
}