Example usage for android.opengl Matrix setRotateM

List of usage examples for android.opengl Matrix setRotateM

Introduction

In this page you can find the example usage for android.opengl Matrix setRotateM.

Prototype

public static void setRotateM(float[] rm, int rmOffset, float a, float x, float y, float z) 

Source Link

Document

Creates a matrix for rotation by angle a (in degrees) around the axis (x, y, z).

Usage

From source file:Main.java

/**
 * Returns texture matrix that will have the effect of rotating the frame |rotationDegree|
 * clockwise when rendered.//from w  w  w  .ja va  2  s .  com
 */
public static float[] rotateTextureMatrix(float[] textureMatrix, float rotationDegree) {
    final float[] rotationMatrix = new float[16];
    Matrix.setRotateM(rotationMatrix, 0, rotationDegree, 0, 0, 1);
    adjustOrigin(rotationMatrix);
    return multiplyMatrices(textureMatrix, rotationMatrix);
}

From source file:com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.java

/**
 * Find a new random position for the object.
 *
 * <p>We'll rotate it around the Y-axis so it's out of sight, and then up or down by a little bit.
 *///  w  w  w. ja  v  a  2  s .  com
private void hideObject() {
    float[] rotationMatrix = new float[16];
    float[] posVec = new float[4];

    // First rotate in XZ plane, between 90 and 270 deg away, and scale so that we vary
    // the object's distance from the user.
    float angleXZ = (float) Math.random() * 180 + 90;
    Matrix.setRotateM(rotationMatrix, 0, angleXZ, 0f, 1f, 0f);
    float oldObjectDistance = objectDistance;
    objectDistance = (float) Math.random() * (MAX_MODEL_DISTANCE - MIN_MODEL_DISTANCE) + MIN_MODEL_DISTANCE;
    float objectScalingFactor = objectDistance / oldObjectDistance;
    Matrix.scaleM(rotationMatrix, 0, objectScalingFactor, objectScalingFactor, objectScalingFactor);
    Matrix.multiplyMV(posVec, 0, rotationMatrix, 0, modelCube, 12);

    float angleY = (float) Math.random() * 80 - 40; // Angle in Y plane, between -40 and 40.
    angleY = (float) Math.toRadians(angleY);
    float newY = (float) Math.tan(angleY) * objectDistance;

    modelPosition[0] = posVec[0];
    modelPosition[1] = newY;
    modelPosition[2] = posVec[2];

    updateModelPosition();
}

From source file:com.tumblr.cardboard.Tumblr3DActivity.java

private static void placePhoto(float[][] modelRects, float[][] imageRects, int texIndex, float scale,
        float azimuth, float inclination, float yTranslate) {
    float[] azimuthMatrix = new float[16];
    Matrix.setRotateM(azimuthMatrix, 0, azimuth, 0, 1, 0);

    float[] inclinationMatrix = new float[16];
    Matrix.setRotateM(inclinationMatrix, 0, inclination, 1, 0, 0);

    float[] rotationMatrix = new float[16];
    Matrix.multiplyMM(rotationMatrix, 0, azimuthMatrix, 0, inclinationMatrix, 0);

    Matrix.multiplyMM(modelRects[texIndex], 0, imageRects[texIndex], 0, rotationMatrix, 0);
    Matrix.translateM(modelRects[texIndex], 0, 0f, 0f, yTranslate);
    Matrix.scaleM(modelRects[texIndex], 0, scale, scale, 1f);
}