Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.opengl.Matrix;

public class Main {
    public static float[] animateObject(float[] animateResult, float[] mvpMatrix) {
        float[] newMatrix = copyMatrix(mvpMatrix);
        if (animateResult != null) {
            Matrix.translateM(newMatrix, 0, animateResult[2], animateResult[3], animateResult[4]);
            rotateModel(newMatrix, null, null, animateResult[0], true, 20f, // TODO
                    // values
                    30f, 0f);
        }
        return newMatrix;
    }

    private static float[] copyMatrix(float[] matrix) {
        float[] copyM = new float[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            copyM[i] = matrix[i];
        }
        return copyM;
    }

    public static void rotateModel(float[] mModelMatrix, Float x, Float y, Float z, boolean rotateAroundCenter,
            Float width, Float length, Float height) {
        // translation for rotating the model around its center
        if (rotateAroundCenter) {
            Matrix.translateM(mModelMatrix, 0, length / 2f, width / 2f, height / 2f);
        }
        if (x != null) {
            Matrix.rotateM(mModelMatrix, 0, x, 1.0f, 0.0f, 0.0f);
        }
        if (y != null) {
            Matrix.rotateM(mModelMatrix, 0, y, 0.0f, 1.0f, 0.0f);
        }
        if (z != null) {
            Matrix.rotateM(mModelMatrix, 0, z, 0.0f, 0.0f, 1.0f);
        }

        // translation back to the origin
        if (rotateAroundCenter) {
            Matrix.translateM(mModelMatrix, 0, -length / 2, -width / 2f, -height / 2f);
        }
    }
}