@Test public void testInvert() { final Matrix3 mat3A = new Matrix3().applyRotationX(MathUtils.QUARTER_PI); final Matrix3 inverted = mat3A.invert(null); assertEquals(Matrix3.IDENTITY, mat3A.multiply(inverted, null)); assertEquals(mat3A, inverted.invertLocal()); }
@Test public void testOrthonormal() { final Matrix4 mat4 = new Matrix4(); assertTrue(mat4.isOrthonormal()); // just rotation mat4.set(new Matrix3().applyRotationX(MathUtils.QUARTER_PI)); assertTrue(mat4.isOrthonormal()); // non-uniform scale mat4.set(new Matrix3().scaleLocal(new Vector3(1, 2, 3)).applyRotationX(MathUtils.QUARTER_PI)); assertFalse(mat4.isOrthonormal()); // uniform scale mat4.set(new Matrix3().scaleLocal(new Vector3(2, 2, 2)).applyRotationX(MathUtils.QUARTER_PI)); assertFalse(mat4.isOrthonormal()); // uniform scale 1 mat4.set(new Matrix3().scaleLocal(new Vector3(1, 1, 1)).applyRotationX(MathUtils.QUARTER_PI)); assertTrue(mat4.isOrthonormal()); }
@Test public void testApplyVector3() { final Matrix3 mat3 = new Matrix3().applyRotationX(MathUtils.HALF_PI); final Vector3 vec3 = new Vector3(0, 1, 0); final Vector3 result = mat3.applyPost(vec3, null); assertTrue(Math.abs(new Vector3(0, 0, 1).distance(result)) <= MathUtils.EPSILON); vec3.set(0, 1, 1); mat3.applyPost(vec3, result); assertTrue(Math.abs(new Vector3(0, -1, 1).distance(result)) <= MathUtils.EPSILON); vec3.set(0, 1, 1); mat3.applyPre(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(mat3.applyPre(vec3, null))) <= MathUtils.EPSILON); }
@Test public void testOrthonormal() { final Matrix3 mat3 = new Matrix3(); assertTrue(mat3.isOrthonormal()); // just rotation mat3.applyRotationX(MathUtils.QUARTER_PI); assertTrue(mat3.isOrthonormal()); // non-uniform scale mat3.setIdentity(); mat3.scaleLocal(new Vector3(1, 2, 3)); assertFalse(mat3.isOrthonormal()); // non-uniform scale + rotation mat3.setIdentity(); mat3.scaleLocal(new Vector3(1, 2, 3)); mat3.applyRotationX(MathUtils.QUARTER_PI); assertFalse(mat3.isOrthonormal()); }
@Test public void testAxes() { final Matrix3 rot = new Matrix3().applyRotationX(MathUtils.QUARTER_PI).applyRotationY(MathUtils.HALF_PI); final Quaternion quat1 = new Quaternion().fromAxes(rot.getColumn(0, null), rot.getColumn(1, null), rot.getColumn(2, null)); final Quaternion quat2 = new Quaternion().fromRotationMatrix(rot); assertEquals(quat2, quat1); final Vector3[] axes = quat1.toAxes(new Vector3[3]); quat1.fromAxes(axes[0], axes[1], axes[2]); assertEquals(quat2, quat1); }
@Test public void testApplyVector3() { final Transform trans = new Transform().setRotation(new Matrix3().applyRotationX(MathUtils.HALF_PI)).translate( 1, 2, 3); final Vector3 vec3 = new Vector3(0, 1, 0);
assertEquals(Transform.IDENTITY, trans); final Transform immutable = new Transform(new Matrix3().applyRotationX(MathUtils.QUARTER_PI), new Vector3(0, -1, -2), new Vector3(1, 2, 3), true, true, true); assertTrue(true == immutable.isIdentity()); assertTrue(true == immutable.isRotationMatrix()); assertTrue(true == immutable.isUniformScale()); assertEquals(new Matrix3().applyRotationX(MathUtils.QUARTER_PI), immutable.getMatrix()); assertEquals(new Vector3(0, -1, -2), immutable.getScale()); assertEquals(new Vector3(1, 2, 3), immutable.getTranslation());
worker.applyRotationX(MathUtils.QUARTER_PI); worker.applyPost(expected, expected); 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);