Android - Getting The Current Rotation Of A Matrix
I need to be able to set the rotation of a matrix rather than add to it. I believe the only way to set the rotation is to know the current rotation of the matrix. Note: matrix.setR
Solution 1:
float[] v = newfloat[9];
matrix.getValues(v);
// translation is simplefloat tx = v[Matrix.MTRANS_X];
float ty = v[Matrix.MTRANS_Y];
// calculate real scalefloat scalex = v[Matrix.MSCALE_X];
float skewy = v[Matrix.MSKEW_Y];
float rScale = (float) Math.sqrt(scalex * scalex + skewy * skewy);
// calculate the degree of rotationfloat rAngle = Math.round(Math.atan2(v[Matrix.MSKEW_X], v[Matrix.MSCALE_X]) * (180 / Math.PI));
Solution 2:
What you can do is call getValues
and cache the values. Later when you want them back just call setValues
on the matrix.
Update
The rotation matrix and transform matrix relation well explained here
Solution 3:
I'm afraid I can't help you with the integration (I've done this in Flash only), but it sounds like you should try to do your matrix calculations yourself, which is best done using "quaternions", which makes adding rotations pretty trivial. See http://introcs.cs.princeton.edu/java/32class/Quaternion.java.html for an example Java implementation. You would want to create a second quaternion matrix that describes your change in rotation and add (in this case, plus
) it to your current matrix.
Post a Comment for "Android - Getting The Current Rotation Of A Matrix"