Vec3 { public Vec3 multiplyByMatrix(Matrix4 matrix) { if (matrix == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Vec3", "multiplyByMatrix", "missingMatrix")); } double[] m = matrix.m; double x = (m[0] * this.x) + (m[1] * this.y) + (m[2] * this.z) + m[3]; double y = (m[4] * this.x) + (m[5] * this.y) + (m[6] * this.z) + m[7]; double z = (m[8] * this.x) + (m[9] * this.y) + (m[10] * this.z) + m[11]; double w = (m[12] * this.x) + (m[13] * this.y) + (m[14] * this.z) + m[15]; this.x = x / w; this.y = y / w; this.z = z / w; return this; } Vec3();  Vec3(double x, double y, double z);  Vec3(Vec3 vector); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); float[] toArray(float[] result, int offset); double magnitude(); double magnitudeSquared(); double distanceTo(Vec3 vector); double distanceToSquared(Vec3 vector); Vec3 set(double x, double y, double z); Vec3 set(Vec3 vector); Vec3 swap(Vec3 vector); Vec3 add(Vec3 vector); Vec3 subtract(Vec3 vector); Vec3 multiply(double scalar); Vec3 multiplyByMatrix(Matrix4 matrix); Vec3 divide(double divisor); Vec3 negate(); Vec3 normalize(); double dot(Vec3 vector); Vec3 cross(Vec3 vector); Vec3 cross(Vec3 a, Vec3 b); Vec3 mix(Vec3 vector, double weight); public double x; public double y; public double z; }
@Test public void testMultiplyByMatrix() throws Exception { double theta = 30d; double x = 2; double y = 3; double z = 0; Matrix4 m = new Matrix4().multiplyByRotation(0, 0, 1, theta).setTranslation(x, y, z); Vec3 u = new Vec3(1, 0, 0).multiplyByMatrix(m); assertEquals("acos u.x", theta, Math.toDegrees(Math.acos(u.x - x)), 1e-10); assertEquals("asin u.y", theta, Math.toDegrees(Math.asin(u.y - y)), 1e-10); }