@Override public ResultSample doRotateTest2(final int count, final int maxCount, final long timeOutMS) { final Matrix4 m1 = a3dMatrixRandom(); final double a = MathUtils.HALF_PI; final long start = System.currentTimeMillis(); int loopCount = 0; while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) { ++loopCount; for (int i = 0; i < count; ++i) { m1.applyRotationX(a); } } return populateResult(System.currentTimeMillis() - start, loopCount, m1.toArray(null)); }
@Test public void testInvert() { final Matrix4 mat4A = new Matrix4().applyRotationX(MathUtils.QUARTER_PI).applyTranslationPost(1, 2, 3); final Matrix4 inverted = mat4A.invert(null); assertEquals(Matrix4.IDENTITY, mat4A.multiply(inverted, null)); assertEquals(mat4A, inverted.invertLocal()); }
@Test public void testApplyVector4() { final Matrix4 mat4 = new Matrix4().applyRotationX(MathUtils.HALF_PI); final Vector4 vec4 = new Vector4(0, 1, 0, 1); final Vector4 result = mat4.applyPost(vec4, null); assertTrue(Math.abs(new Vector4(0, 0, 1, 1).distance(result)) <= MathUtils.EPSILON); vec4.set(0, 1, 1, 1); mat4.applyPost(vec4, result); assertTrue(Math.abs(new Vector4(0, -1, 1, 1).distance(result)) <= MathUtils.EPSILON); vec4.set(0, 1, 1, 1); mat4.applyPre(vec4, result); assertTrue(Math.abs(new Vector4(0, 1, -1, 1).distance(result)) <= MathUtils.EPSILON); vec4.set(1, 1, 1, 1); assertTrue(Math.abs(new Vector4(1, 1, -1, 1).distance(mat4.applyPre(vec4, null))) <= MathUtils.EPSILON); }
@Test public void testApplyVector3() { final Matrix4 mat4 = new Matrix4().applyRotationX(MathUtils.HALF_PI).applyTranslationPre(1, 2, 3); final Vector3 vec3 = new Vector3(0, 1, 0); final Vector3 result = mat4.applyPostPoint(vec3, null); assertTrue(Math.abs(new Vector3(1, 2, 4).distance(result)) <= MathUtils.EPSILON); vec3.set(0, 1, 1); mat4.applyPostPoint(vec3, result); assertTrue(Math.abs(new Vector3(1, 1, 4).distance(result)) <= MathUtils.EPSILON); vec3.set(0, 1, 1); mat4.applyPostVector(vec3, result); assertTrue(Math.abs(new Vector3(0, -1, 1).distance(result)) <= MathUtils.EPSILON); vec3.set(1, 1, 1); assertTrue(Math.abs(new Vector3(1, -1, 1).distance(mat4.applyPostVector(vec3, null))) <= MathUtils.EPSILON); } }
@Test public void testRotations() { final Vector4 rotated = new Vector4(); final Vector4 expected = new Vector4(); final Matrix4 worker = new Matrix4(); // test axis rotation methods against general purpose // X AXIS expected.set(1, 1, 1, 1); rotated.set(1, 1, 1, 1); worker.setIdentity().applyRotationX(MathUtils.QUARTER_PI).applyPost(expected, expected); worker.setIdentity().applyRotation(MathUtils.QUARTER_PI, 1, 0, 0).applyPost(rotated, rotated); assertTrue(rotated.distance(expected) <= MathUtils.EPSILON); // Y AXIS expected.set(1, 1, 1, 1); rotated.set(1, 1, 1, 1); worker.setIdentity().applyRotationY(MathUtils.QUARTER_PI).applyPost(expected, expected); worker.setIdentity().applyRotation(MathUtils.QUARTER_PI, 0, 1, 0).applyPost(rotated, rotated); assertTrue(rotated.distance(expected) <= MathUtils.EPSILON); // Z AXIS expected.set(1, 1, 1, 1); rotated.set(1, 1, 1, 1); worker.setIdentity().applyRotationZ(MathUtils.QUARTER_PI).applyPost(expected, expected); worker.setIdentity().applyRotation(MathUtils.QUARTER_PI, 0, 0, 1).applyPost(rotated, rotated); assertTrue(rotated.distance(expected) <= MathUtils.EPSILON); }