@Override public ResultSample doRotateTest1(final int count, final int maxCount, final long timeOutMS) { final Matrix4 m1 = a3dMatrixRandom(); final Vector3 vec = new Vector3(1.0, 2.0, 3.0).normalizeLocal(); final double a = MathUtils.HALF_PI; final double x = vec.getX(), y = vec.getY(), z = vec.getZ(); final long start = System.currentTimeMillis(); int loopCount = 0; while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) { ++loopCount; for (int i = 0; i < count; ++i) { m1.applyRotation(a, x, y, z); } } return populateResult(System.currentTimeMillis() - start, loopCount, m1.toArray(null)); }
@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); }
private Matrix4 a3dMatrixRandom() { final Matrix4 mat = new Matrix4(); final Vector3 axis = new Vector3(MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble()); axis.normalizeLocal(); mat.applyRotation(MathUtils.nextRandomDouble(), axis.getX(), axis.getY(), axis.getZ()); mat.applyTranslationPost(MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble()); return mat; }
@Test public void testTranslation() { final Matrix4 src = new Matrix4(); src.applyRotation(MathUtils.QUARTER_PI, 1, 0, 0); final Matrix4 trans = new Matrix4(); trans.setColumn(3, new Vector4(1, 2, 3, 1)); final Matrix4 transThenRotate = trans.multiply(src, null); final Matrix4 rotateThenTrans = src.multiply(trans, null); final Matrix4 pre1 = new Matrix4(src).applyTranslationPre(1, 2, 3); final Matrix4 post1 = new Matrix4(src).applyTranslationPost(1, 2, 3); assertEquals(transThenRotate, pre1); assertEquals(rotateThenTrans, post1); }