Android – 获取矩阵的当前旋转

我需要能够设置矩阵的旋转而不是添加它。 我认为设置旋转的唯一方法是知道矩阵的当前旋转。

注意: matrix.setRotate()不会这样做,因为矩阵需要保留其信息。

你可以做的是调用getValues并缓存值。 稍后当你想要它们时,只需在矩阵上调用setValues

更新

这里很好地解释了旋转矩阵和变换矩阵关系

 float[] v = new float[9]; matrix.getValues(v); // translation is simple float tx = v[Matrix.MTRANS_X]; float ty = v[Matrix.MTRANS_Y]; // calculate real scale float scalex = v[Matrix.MSCALE_X]; float skewy = v[Matrix.MSKEW_Y]; float rScale = (float) Math.sqrt(scalex * scalex + skewy * skewy); // calculate the degree of rotation float rAngle = Math.round(Math.atan2(v[Matrix.MSKEW_X], v[Matrix.MSCALE_X]) * (180 / Math.PI)); 

从这里http://judepereira.com/blog/calculate-the-real-scale-factor-and-the-angle-of-rotation-from-an-android-matrix/

我担心我无法帮助你进行集成(我只在Flash中完成此操作),但听起来你应该尝试自己进行矩阵计算,这最好使用“四元数”来完成,这使得添加轮换很琐碎。 有关示例Java实现,请参见http://introcs.cs.princeton.edu/java/32class/Quaternion.java.html 。 您可能需要创建第二个四元数矩阵来描述您的旋转变化,并将其添加(在这种情况下, plus )到当前矩阵。