Android examples for java.lang:Math Matrix
Calculates rotation matrix into given matrix array.
/*/*from w w w . j a va 2 s . c o m*/ Copyright 2012 Harri Smatt Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import android.opengl.Matrix; import android.util.FloatMath; public class Main{ /** * Calculates rotation matrix into given matrix array. * * @param m * Matrix float array * @param offset * Matrix start offset * @param rx * Rotation around x axis * @param ry * Rotation around y axis * @param rz * Rotation around z axis */ public static void setRotateM(float[] m, float rx, float ry, float rz) { float toRadians = (float) (Math.PI * 2 / 360); rx *= toRadians; ry *= toRadians; rz *= toRadians; float sin0 = FloatMath.sin(rx); float cos0 = FloatMath.cos(rx); float sin1 = FloatMath.sin(ry); float cos1 = FloatMath.cos(ry); float sin2 = FloatMath.sin(rz); float cos2 = FloatMath.cos(rz); android.opengl.Matrix.setIdentityM(m, 0); float sin1_cos2 = sin1 * cos2; float sin1_sin2 = sin1 * sin2; m[0] = cos1 * cos2; m[1] = cos1 * sin2; m[2] = -sin1; m[4] = (-cos0 * sin2) + (sin0 * sin1_cos2); m[5] = (cos0 * cos2) + (sin0 * sin1_sin2); m[6] = sin0 * cos1; m[8] = (sin0 * sin2) + (cos0 * sin1_cos2); m[9] = (-sin0 * cos2) + (cos0 * sin1_sin2); m[10] = cos0 * cos1; } }