If you think the Android project fun-gl listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.jcxavier.android.opengl.math;
/*www.java2s.com*/import android.opengl.Matrix;
/**
* Created on 11/03/2014.
*
* @author Joo Xavier <jcxavier@jcxavier.com>
*/publicfinalclass Matrix4 {
privatestaticfinalfloat[] TMP_MATRIX = newfloat[16];
publicfinalfloat[] m;
public Matrix4() {
m = newfloat[16];
Matrix.setIdentityM(m, 0);
}
publicvoid set(final Matrix4 matrix) {
System.arraycopy(matrix.m, 0, m, 0, 16);
}
public Matrix4 copy() {
Matrix4 copyMatrix = new Matrix4();
copyMatrix.set(this);
return copyMatrix;
}
publicvoid setIdentity() {
Matrix.setIdentityM(m, 0);
}
publicvoid translate(final Vector3 pos) {
Matrix.translateM(m, 0, pos.x, pos.y, pos.z);
}
publicvoid scale(final Vector3 scale) {
Matrix.scaleM(m, 0, scale.x, scale.y, scale.z);
}
publicvoid multiply(final Matrix4 matrix) {
Matrix.multiplyMM(TMP_MATRIX, 0, m, 0, matrix.m, 0);
System.arraycopy(TMP_MATRIX, 0, m, 0, 16);
}
/**
* Rotates the matrix around the x axis.
*
* @param degrees the rotation to apply, in degrees
*/publicvoid rotateX(finalfloat degrees) {
Matrix.rotateM(m, 0, degrees, 1, 0, 0);
}
/**
* Rotates the matrix around the y axis.
*
* @param degrees the rotation to apply, in degrees
*/publicvoid rotateY(finalfloat degrees) {
Matrix.rotateM(m, 0, degrees, 0, 1, 0);
}
/**
* Rotates the matrix around the z axis.
*
* @param degrees the rotation to apply, in degrees
*/publicvoid rotateZ(finalfloat degrees) {
Matrix.rotateM(m, 0, degrees, 0, 0, 1);
}
}