goal.ignorecollision = true;
// rotate to align major axis -- this probably needs to be done by a human.
- goal.transform(new Matrix(new Vec(0, 0, 1), (float)(Math.PI/2)));
+ goal.transform(Matrix.rotate(new Vec(0, 0, 1), (float)(Math.PI/2)));
float goal_width = goal.diagonal().dot(new Vec(1, 0, 0));
float goal_height = goal.diagonal().dot(new Vec(0, 1, 0));
translations = new Matrix[] {
- new Matrix(new Vec(lshift, depth, halfup)),
- new Matrix(new Vec(rshift, depth, halfup)),
- new Matrix(new Vec(lshift, -depth, halfup)),
- new Matrix(new Vec(rshift, -depth, halfup)),
+ Matrix.translate(new Vec(lshift, depth, halfup)),
+ Matrix.translate(new Vec(rshift, depth, halfup)),
+ Matrix.translate(new Vec(lshift, -depth, halfup)),
+ Matrix.translate(new Vec(rshift, -depth, halfup)),
/*
- new Matrix(new Vec(0, depth, halfup)),
- new Matrix(new Vec(0, -depth, halfup)),
+ Matrix.translate(new Vec(0, depth, halfup)),
+ Matrix.translate(new Vec(0, -depth, halfup)),
*/
- new Matrix(new Vec(lshift, 0, height)),
- new Matrix(new Vec(rshift, 0, height)),
- new Matrix(new Vec(lshift, 0, -height)),
- new Matrix(new Vec(rshift, 0, -height)),
+ Matrix.translate(new Vec(lshift, 0, height)),
+ Matrix.translate(new Vec(rshift, 0, height)),
+ Matrix.translate(new Vec(lshift, 0, -height)),
+ Matrix.translate(new Vec(rshift, 0, -height)),
- new Matrix(new Vec( width, 0, 0)),
- new Matrix(new Vec(-width, 0, 0)),
+ Matrix.translate(new Vec( width, 0, 0)),
+ Matrix.translate(new Vec(-width, 0, 0)),
};
goal.transform(Matrix.scale(factor));
// translate to match centroid
- goal.transform(new Matrix(tile.centroid().minus(goal.centroid())));
+ goal.transform(Matrix.translate(tile.centroid().minus(goal.centroid())));
//tx.e2.shatter();
//tx.e3.shatter();
*/
public final float a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p;
+ /** the zero matrix */
public static final Matrix ZERO = new Matrix(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
+
+ /** the identity matrix */
public static final Matrix ONE = new Matrix(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);
- public static Matrix scale(float scale) { return new Matrix(scale, 0, 0, 0, 0, scale, 0, 0, 0, 0, scale, 0, 0, 0, 0, 1); }
+ /** a scaling matrix (uniform in all dimensions) */
+ public static Matrix scale(float scale) { return scale(scale, scale, scale); }
+
+ /** a scaling matrix */
+ public static Matrix scale(float scalex, float scaley, float scalez) {
+ return new Matrix(scalex, 0, 0, 0, 0, scaley, 0, 0, 0, 0, scalez, 0, 0, 0, 0, 1); }
- public Matrix(float scalex, float scaley, float scalez) {
- a = scalex;
- f = scaley;
- k = scalez;
- l = h = d = e = b = i = c = j = g = 0;
- m = n = o = 0;
- p = 1;
- }
- public Matrix(Vec translate) {
- d = translate.x; h = translate.y; l = translate.z;
- a = f = k = 1;
- b = c = e = g = i = j = 0;
- m = n = o = 0;
- p = 1;
- }
public Matrix(float a, float b, float c, float d, float e, float f, float g,
float h, float i, float j, float k, float l, float m, float n, float o, float p) {
this.a = a; this.b = b; this.c = c; this.d = d; this.e = e; this.f = f; this.g = g; this.h = h; this.i = i;
this.j = j; this.k = k; this.l = l; this.m = m; this.n = n; this.o = o; this.p = p;
}
+
+ public static Matrix translate(Vec translate) {
+ return new Matrix(1, 0, 0, translate.x,
+ 0, 1, 0, translate.y,
+ 0, 0, 1, translate.z,
+ 0, 0, 0, 1);
+ }
+
public Matrix plus(Matrix x) {
return new Matrix(a+x.a, b+x.b, c+x.c, d+x.d, e+x.e, f+x.f, g+x.g, h+x.h, i+x.i, j+x.j, k+x.k, l+x.l, m+x.m, n+x.n, o+x.o, p+x.p);
}
return ret;
}
- public Matrix(Vec axis, float angle) {
- double q = Math.cos(angle);
- double s = Math.sin(angle);
- double t = 1.0 - q;
- a = (float)(q + axis.x*axis.x*t);
- f = (float)(q + axis.y*axis.y*t);
- k = (float)(q + axis.z*axis.z*t);
- double tmp1 = axis.x*axis.y*t;
- double tmp2 = axis.z*s;
- e = (float)(tmp1 + tmp2);
- b = (float)(tmp1 - tmp2);
+ public static Matrix rotate(Vec axis, float angle) {
+ float q = (float)Math.cos(angle);
+ float s = (float)Math.sin(angle);
+ float t = 1 - q;
+ float a = (float)(q + axis.x*axis.x*t);
+ float f = (float)(q + axis.y*axis.y*t);
+ float k = (float)(q + axis.z*axis.z*t);
+ float tmp1 = axis.x*axis.y*t;
+ float tmp2 = axis.z*s;
+ float e = (float)(tmp1 + tmp2);
+ float b = (float)(tmp1 - tmp2);
tmp1 = axis.x*axis.z*t;
tmp2 = axis.y*s;
- i = (float)(tmp1 - tmp2);
- c = (float)(tmp1 + tmp2);
+ float i = (float)(tmp1 - tmp2);
+ float c = (float)(tmp1 + tmp2);
tmp1 = axis.y*axis.z*t;
tmp2 = axis.x*s;
- j = (float)(tmp1 + tmp2);
- g = (float)(tmp1 - tmp2);
- d = h = l = 0;
- m = n = o = 0;
- p = 1;
+ float j = (float)(tmp1 + tmp2);
+ float g = (float)(tmp1 - tmp2);
+ return new Matrix(a, b, c, 0,
+ e, f, g, 0,
+ i, j, k, 0,
+ 0, 0, 0, 1);
}
public Point times(Point p) {
// discards bottom row