@Override public Matrix4 clone() { return new Matrix4(this); }
@Override public Matrix4 clone() { return new Matrix4(this); }
/** * @return An instance of Matrix4 that is intended for temporary use in calculations and so forth. Multiple calls to * the method should return instances of this class that are not currently in use. */ public final static Matrix4 fetchTempInstance() { if (MathConstants.useMathPools) { return Matrix4.MAT_POOL.fetch(); } else { return new Matrix4(); } }
/** * @return An instance of Matrix4 that is intended for temporary use in calculations and so forth. Multiple calls to * the method should return instances of this class that are not currently in use. */ public final static Matrix4 fetchTempInstance() { if (MathConstants.useMathPools) { return Matrix4.MAT_POOL.fetch(); } else { return new Matrix4(); } }
@Override public ResultSample doInverseTest(final int count, final int maxCount, final long timeOutMS) { final Matrix4 m1 = new Matrix4(); final double near = 1.0, far = 1000.0, fovy = 90.0, aspect = 0.5; MathUtils.matrixPerspective(fovy, aspect, near, far, m1); final long start = System.currentTimeMillis(); int loopCount = 0; while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) { ++loopCount; for (int i = 0; i < count; ++i) { m1.invertLocal(); } } return populateResult(System.currentTimeMillis() - start, loopCount, m1.toArray(null)); }
public void updateTextureMatrix(final Spatial store, final String key) { Matrix4 texMat = store.getProperty(key, null); if (texMat == null) { texMat = new Matrix4(); store.setProperty(key, texMat); } updateTextureMatrix(texMat); }
@Test public void testAngleAxis() { final Matrix4 mat4A = new Matrix4(); // rotate identity 90 degrees around X final double angle = MathUtils.HALF_PI; mat4A.fromAngleAxis(MathUtils.HALF_PI, Vector3.UNIT_X); assertEquals(new Matrix4( // 1, 0, 0, 0, // 0, Math.cos(angle), -Math.sin(angle), 0, // 0, Math.sin(angle), Math.cos(angle), 0, // 0, 0, 0, 1), mat4A); }
@Test(expected = ArithmeticException.class) public void testBadInvert() { final Matrix4 mat4A = new Matrix4(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); mat4A.invertLocal(); }
@Test(expected = IllegalArgumentException.class) public void testBadArray() { final Matrix4 mat4A = new Matrix4(); mat4A.toArray(new double[9]); }
@Test public void testSimpleHash() { // Just a simple sanity check. final Matrix4 mat1 = new Matrix4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); final Matrix4 mat2 = new Matrix4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); final Matrix4 mat3 = new Matrix4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0); assertTrue(mat1.hashCode() == mat2.hashCode()); assertTrue(mat1.hashCode() != mat3.hashCode()); }
@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); }
@Test public void testScale() { final Matrix4 mat4A = new Matrix4( // 0.01, 0.1, 0.2, 0.3, // 1.0, 1.1, 1.2, 1.3, // 2.0, 2.1, 2.2, 2.3, // 3.0, 3.1, 3.2, 3.3); final Matrix4 result = mat4A.scale(new Vector4(-1, 2, 3, 4), null); assertEquals(new Matrix4( // 0.01 * -1, 0.1 * 2, 0.2 * 3, 0.3 * 4, // 1.0 * -1, 1.1 * 2, 1.2 * 3, 1.3 * 4, // 2.0 * -1, 2.1 * 2, 2.2 * 3, 2.3 * 4, // 3.0 * -1, 3.1 * 2, 3.2 * 3, 3.3 * 4), result); result.scaleLocal(new Vector4(-1, 0.5, 1 / 3., .25)); assertEquals(mat4A, result); }
@Test public void testClone() { final Matrix4 mat1 = new Matrix4(); final Matrix4 mat2 = mat1.clone(); assertEquals(mat1, mat2); assertNotSame(mat1, mat2); }
@Test(expected = InvalidTransformException.class) public void testFromHomogeneousMatrix() { final ValidatingTransform vt1 = new ValidatingTransform(); final Matrix4 matrix = new Matrix4(); vt1.fromHomogeneousMatrix(matrix); // good matrix.setM00(Double.NaN); vt1.fromHomogeneousMatrix(matrix); // bad }
/** * Create setup to use as fallback if fancy water is not supported. */ private void createFallbackData() { fallbackTextureState = new TextureState(); fallbackTextureState.setEnabled(true); fallbackTexture = TextureManager.load(fallbackMapTextureString, Texture.MinificationFilter.Trilinear, TextureStoreFormat.GuessCompressedFormat, true); fallbackTextureState.setTexture(fallbackTexture, 0); fallbackTexture.setWrap(Texture.WrapMode.Repeat); fallbackTextureStateMatrix = new Matrix4(); as1 = new BlendState(); as1.setBlendEnabled(true); as1.setTestEnabled(true); as1.setSourceFunction(BlendState.SourceFunction.SourceAlpha); as1.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha); as1.setEnabled(true); }
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 testToArray() { final double[] values = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; final Matrix4 mat4A = new Matrix4().fromArray(values); // row major final double[] dbls1 = mat4A.toArray(null); for (int i = 0; i < 16; i++) { assertTrue(values[i] == dbls1[i]); } // column major final double[] colmajor = { 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15 }; mat4A.toArray(dbls1, false); for (int i = 0; i < 16; i++) { assertTrue(colmajor[i] == dbls1[i]); } }
@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); } }