Adding matrix class methods.

Change-Id: I597b1b3955e29921394909f302800034571e6a50
This commit is contained in:
Alex Sakhartchouk
2010-08-04 10:48:30 -07:00
parent 0d523e09bd
commit cf9a44cdf3
2 changed files with 155 additions and 0 deletions

View File

@@ -51,6 +51,52 @@ public class Matrix2f {
System.arraycopy(mMat, 0, src, 0, 4);
}
public void loadRotate(float rot) {
float c, s;
rot *= (float)(java.lang.Math.PI / 180.0f);
c = (float)java.lang.Math.cos(rot);
s = (float)java.lang.Math.sin(rot);
mMat[0] = c;
mMat[1] = -s;
mMat[2] = s;
mMat[3] = c;
}
public void loadScale(float x, float y) {
loadIdentity();
mMat[0] = x;
mMat[3] = y;
}
public void loadMultiply(Matrix2f lhs, Matrix2f rhs) {
for (int i=0 ; i<2 ; i++) {
float ri0 = 0;
float ri1 = 0;
for (int j=0 ; j<2 ; j++) {
float rhs_ij = rhs.get(i,j);
ri0 += lhs.get(j,0) * rhs_ij;
ri1 += lhs.get(j,1) * rhs_ij;
}
set(i,0, ri0);
set(i,1, ri1);
}
}
public void multiply(Matrix2f rhs) {
Matrix2f tmp = new Matrix2f();
tmp.loadMultiply(this, rhs);
load(tmp);
}
public void rotate(float rot) {
Matrix2f tmp = new Matrix2f();
tmp.loadRotate(rot);
multiply(tmp);
}
public void scale(float x, float y) {
Matrix2f tmp = new Matrix2f();
tmp.loadScale(x, y);
multiply(tmp);
}
final float[] mMat;
}