@Test public void testDistance() { final Vector4 vec1 = new Vector4(0, 0, 0, 0); assertTrue(4.0 == vec1.distance(4, 0, 0, 0)); assertTrue(3.0 == vec1.distance(0, 3, 0, 0)); assertTrue(2.0 == vec1.distance(0, 0, 2, 0)); assertTrue(1.0 == vec1.distance(0, 0, 0, 1)); final Vector4 vec2 = new Vector4(1, 1, 1, 1); assertTrue(Math.sqrt(4) == vec1.distance(vec2)); }
@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 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); }