/** * @param store * the double array to store our matrix data in. If null, a new array is created. * @return matrix data as a double array in row major order. * @throws IllegalArgumentException * if the store is non-null and has a length < 16 */ @Override public double[] toArray(final double[] store) { return toArray(store, true); }
/** * @param store * the double array to store our matrix data in. If null, a new array is created. * @return matrix data as a double array in row major order. * @throws IllegalArgumentException * if the store is non-null and has a length < 16 */ @Override public double[] toArray(final double[] store) { return toArray(store, true); }
@Override public ResultSample doTranslateTest(final int count, final int maxCount, final long timeOutMS) { final Matrix4 m1 = a3dMatrixRandom(); final long start = System.currentTimeMillis(); int loopCount = 0; while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) { ++loopCount; for (int i = 0; i < count; ++i) { m1.applyTranslationPost(1.0, 2.0, 3.0); } } return populateResult(System.currentTimeMillis() - start, loopCount, m1.toArray(null)); }
@Override public ResultSample doTransposeTest(final int count, final int maxCount, final long timeOutMS) { final Matrix4 m1 = a3dMatrixRandom(); final long start = System.currentTimeMillis(); int loopCount = 0; while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) { ++loopCount; for (int i = 0; i < count; ++i) { m1.transposeLocal(); } } return populateResult(System.currentTimeMillis() - start, loopCount, m1.toArray(null)); }
@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)); }
@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)); }
@Override public ResultSample doMultTest(final int count, final int maxCount, final long timeOutMS) { final Matrix4 m1 = a3dMatrixRandom(); final Matrix4 m2 = a3dMatrixRandom(); final long start = System.currentTimeMillis(); int loopCount = 0; while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) { ++loopCount; for (int i = 0; i < count; ++i) { m1.multiply(m2, m1); } } return populateResult(System.currentTimeMillis() - start, loopCount, m1.toArray(null)); }
@Override public ResultSample doScaleTest(final int count, final int maxCount, final long timeOutMS) { final Matrix4 m1 = a3dMatrixRandom(); final Vector4 vec = new Vector4(1.0, 2.0, 3.0, 1.0); final long start = System.currentTimeMillis(); int loopCount = 0; while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) { ++loopCount; for (int i = 0; i < count; ++i) { m1.scaleLocal(vec); } } return populateResult(System.currentTimeMillis() - start, loopCount, m1.toArray(null)); }
@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(expected = IllegalArgumentException.class) public void testBadArray() { final Matrix4 mat4A = new Matrix4(); mat4A.toArray(new double[9]); }
@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]); } }
@Override public ResultSample doInverse3Test(final int count, final int maxCount, final long timeOutMS) { final Matrix4 mat = a3dMatrixRandom(); final Matrix3 m1 = new Matrix3( // mat.getM00(), mat.getM01(), mat.getM02(), // mat.getM10(), mat.getM11(), mat.getM12(), // mat.getM20(), mat.getM21(), mat.getM22()); mat.setIdentity(); 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, mat.set(m1).toArray(null)); }
@Override public ResultSample doTransformMultTest(final int count, final int maxCount, final long timeOutMS) { final ReadOnlyMatrix4 m1 = new Matrix4().fromAngleAxis(MathUtils.nextRandomDouble(), new Vector3(MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble())); final ReadOnlyMatrix4 m2 = new Matrix4().fromAngleAxis(MathUtils.nextRandomDouble(), new Vector3(MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble())); final Transform a = new Transform().fromHomogeneousMatrix(m1); final Transform b = new Transform(); final Transform by = new Transform().fromHomogeneousMatrix(m2); final long start = System.currentTimeMillis(); int loopCount = 0; while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) { ++loopCount; for (int i = 0; i < count; ++i) { if (i % 2 == 0) { a.multiply(by, b); } else { b.multiply(by, a); } } } return populateResult(System.currentTimeMillis() - start, loopCount, a.getHomogeneousMatrix(null).toArray(null)); }