【发布时间】:2011-09-03 03:50:50
【问题描述】:
我需要能够设置矩阵的旋转而不是添加到它。我相信设置旋转的唯一方法是知道矩阵的当前旋转。
注意:matrix.setRotate() 不行,因为矩阵需要保留它的信息。
【问题讨论】:
我需要能够设置矩阵的旋转而不是添加到它。我相信设置旋转的唯一方法是知道矩阵的当前旋转。
注意:matrix.setRotate() 不行,因为矩阵需要保留它的信息。
【问题讨论】:
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));
【讨论】:
【讨论】:
恐怕我无法帮助您进行集成(我只在 Flash 中完成了此操作),但听起来您应该尝试自己进行矩阵计算,最好使用“四元数”来完成,这使得添加旋转非常简单。有关 Java 实现的示例,请参阅 http://introcs.cs.princeton.edu/java/32class/Quaternion.java.html。您可能希望创建第二个四元数矩阵来描述您的旋转变化并将其添加(在本例中为plus)到您当前的矩阵中。
【讨论】: