+
+ /** 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); }
+
+ /** a translation matrix */
+ 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);
+ }
+
+ /** a rotation matrix, <tt>angle</tt> degrees around <tt>axis</tt> */
+ 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;
+ float i = (float)(tmp1 - tmp2);
+ float c = (float)(tmp1 + tmp2);
+ tmp1 = axis.y*axis.z*t;
+ tmp2 = axis.x*s;
+ 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);
+ }
+