Example usage for android.opengl Matrix scaleM

List of usage examples for android.opengl Matrix scaleM

Introduction

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

Prototype

public static void scaleM(float[] m, int mOffset, float x, float y, float z) 

Source Link

Document

Scales matrix m in place by sx, sy, and sz.

Usage

From source file:Main.java

public static float[] scaleModel(float[] animateResult, float[] mvpMatrix) {
    float[] newMatrix = copyMatrix(mvpMatrix);
    if (animateResult != null) {
        Matrix.scaleM(newMatrix, 0, animateResult[0], animateResult[1], animateResult[2]);
    }/* www.  java  2 s .  c  o m*/
    return newMatrix;
}

From source file:Main.java

/**
 * Returns layout transformation matrix that applies an optional mirror effect and compensates
 * for video vs display aspect ratio./*from   ww w.  j  av  a  2s.  co  m*/
 */
public static float[] getLayoutMatrix(boolean mirror, float videoAspectRatio, float displayAspectRatio) {
    float scaleX = 1;
    float scaleY = 1;
    // Scale X or Y dimension so that video and display size have same aspect ratio.
    if (displayAspectRatio > videoAspectRatio) {
        scaleY = videoAspectRatio / displayAspectRatio;
    } else {
        scaleX = displayAspectRatio / videoAspectRatio;
    }
    // Apply optional horizontal flip.
    if (mirror) {
        scaleX *= -1;
    }
    final float matrix[] = new float[16];
    Matrix.setIdentityM(matrix, 0);
    Matrix.scaleM(matrix, 0, scaleX, scaleY, 1);
    adjustOrigin(matrix);
    return matrix;
}

From source file:com.google.fpl.liquidfunpaint.ParticleRenderer.java

public void onSurfaceChanged(int width, int height) {

    // Set up the transform
    float ratio = (float) height / width;
    Matrix.setIdentityM(mTransformFromTexture, 0);
    Matrix.scaleM(mTransformFromTexture, 0, 1, 1 / ratio, 1);

    Matrix.setIdentityM(mTransformFromWorld, 0);
    Matrix.translateM(mTransformFromWorld, 0, -1, -ratio, 0);
    Matrix.scaleM(mTransformFromWorld, 0, 2f / Renderer.getInstance().sRenderWorldWidth,
            2 * ratio / Renderer.getInstance().sRenderWorldHeight, 1);
}

From source file:com.projecttango.examples.java.modelcorrespondence.ModelCorrespondenceActivity.java

/**
 * Calculate the transform needed to place the model in the upper left corner of the camera,
 * and rotate it to show the next point to make the correspondence.
 *//*from  w w  w.  jav a  2s . c o m*/
private float[] calculateModelTransformFixedToCam(int mDisplayRotation) {
    // Translate to the upper left corner and ahead of the cam if the device is in landscape
    // mode or to the upper center if it is in portrait mode.
    float[] rgbTHouse = new float[16];
    Matrix.setIdentityM(rgbTHouse, 0);
    if (mDisplayRotation == Surface.ROTATION_0 || mDisplayRotation == Surface.ROTATION_180) {
        Matrix.translateM(rgbTHouse, 0, 0f, 1.2f, -4);
    } else {
        Matrix.translateM(rgbTHouse, 0, -1.5f, 0.3f, -4);
    }

    // Rotate it 180 degrees around the Z axis to show the front of the house as default
    // orientation.
    Matrix.rotateM(rgbTHouse, 0, 180, 0, 0, 1);
    // Rotate it around the X axis so it looks better as seen from above.
    Matrix.rotateM(rgbTHouse, 0, 70, 1, 0, 0);
    // Rotate it around the Z axis to show the next correspondence point to be added.
    Matrix.rotateM(rgbTHouse, 0, -mModelZRotation, 0, 0, 1);
    // Scale it to a proper size.
    Matrix.scaleM(rgbTHouse, 0, 0.03f, 0.03f, 0.03f);
    return rgbTHouse;
}

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.
 *///from  w w  w . ja v a2  s. c  o  m
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);
}

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

/**
 * Loads a bitmap into OpenGL./*w  ww.  ja va  2s .c o  m*/
 *
 * @param texIndex the desired texture index
 * @param bitmap   the bitmap to put into OpenGL
 */
private void loadTextureInternal(int texIndex, Bitmap bitmap, boolean recycle) {

    GLES20.glGenTextures(1, mTextureIds, texIndex);

    Log.d(TAG, "loading texture: " + texIndex + " -> " + mTextureIds[texIndex]);

    if (mTextureIds[texIndex] != INVALID_TEXTURE && bitmap != null && !bitmap.isRecycled()) {

        // Set the active texture unit
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + texIndex);

        Matrix.setIdentityM(mImageRect[texIndex], 0);
        Matrix.scaleM(mImageRect[texIndex], 0, 1f, (float) bitmap.getHeight() / bitmap.getWidth(), 1f);

        // Bind to the texture in OpenGL
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureIds[texIndex]);

        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

        // Set filtering
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);

        // Load the bitmap into the bound texture.
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

        mRectTextureIds[texIndex] = mTextureIds[texIndex];
    } else {
        Log.w(TAG, "Failed to load: " + texIndex);
    }

    if (mTextureIds[texIndex] == INVALID_TEXTURE) {
        Log.e(TAG, "Error loading texture.");
    }
}

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

private void updateTexture(int texIndex, Bitmap bitmap) {
    if (mTextureIds[texIndex] != INVALID_TEXTURE && bitmap != null && !bitmap.isRecycled()) {

        // Set the active texture unit
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + texIndex);

        Matrix.setIdentityM(mImageRect[texIndex], 0);
        Matrix.scaleM(mImageRect[texIndex], 0, 1f, (float) bitmap.getHeight() / bitmap.getWidth(), 1f);

        // Bind to the texture in OpenGL
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureIds[texIndex]);

        // Load the bitmap into the bound texture.
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
    } else {/*from   w  w  w . j a  v a  2s .  c om*/
        Log.w(TAG, "Failed to update: " + texIndex + " val: " + mTextureIds[texIndex]);
    }
}