Back to project page touchgloid.
The source code is released under:
MIT License
If you think the Android project touchgloid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package rucamzu.opengl; // w ww . ja v a2s . c om import static android.opengl.Matrix.multiplyMM; import static android.opengl.Matrix.multiplyMV; import static android.opengl.Matrix.orthoM; import static android.opengl.Matrix.rotateM; import static android.opengl.Matrix.scaleM; import static android.opengl.Matrix.setIdentityM; import static android.opengl.Matrix.translateM; public class Transform { private final float[] elements; private Transform() { elements = new float[16]; } private Transform(float[] elements) { this.elements = elements; } public static Transform createIdentity() { Transform identity = new Transform(); setIdentityM(identity.getElements(), 0); return identity; } public static Transform createRotation(float degrees, float axisX, float axisY, float axisZ) { Transform rotation = createIdentity(); rotateM(rotation.getElements(), 0, degrees, axisX, axisY, axisZ); return rotation; } public static Transform createRotation(float degrees, Vector axis) { Transform rotation = createIdentity(); rotateM(rotation.getElements(), 0, degrees, axis.x(), axis.y(), axis.z()); return rotation; } public static Transform createScale(float x, float y, float z) { Transform scale = createIdentity(); scaleM(scale.getElements(), 0, x, y, z); return scale; } public static Transform createTranslation(float x, float y, float z) { Transform translation = createIdentity(); translateM(translation.getElements(), 0, x, y, z); return translation; } public static Transform createTranslation(Vector vector) { Transform translation = createIdentity(); translateM(translation.getElements(), 0, vector.x(), vector.y(), vector.z()); return translation; } public static Transform createProjectionOrtho(float width, float height) { Transform ortho = createIdentity(); final float aspect = width > height ? width / height : height / width; if (width > height) { // Landscape orthoM(ortho.getElements(), 0, -aspect, aspect, -1f, 1f, -1f, 1f); } else { // Portrait or square orthoM(ortho.getElements(), 0, -1f, 1f, -aspect, aspect, -1f, 1f); } return ortho; } public static Transform compose(Transform transform1, Transform transform2) { Transform result = new Transform(); multiplyMM(result.getElements(), 0, transform1.getElements(), 0, transform2.getElements(), 0); return result; } public static Vector apply(Transform transform, Vector vector) { Vector result = Vector.create(); multiplyMV(result.getElements(), 0, transform.getElements(), 0, vector.getElements(), 0); return result; } public float[] getElements() { return elements; } }