@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)); }
Matrix4 result = store; if (result == null) { result = new Matrix4(); final double temp33 = +_m20 * dA3 - _m21 * dA1 + _m22 * dA0; result.set(temp00, temp01, temp02, temp03, temp10, temp11, temp12, temp13, temp20, temp21, temp22, temp23, temp30, temp31, temp32, temp33); result.multiplyLocal(1.0 / det);
/** * Updates the value of our projection matrix. */ protected void updateProjectionMatrix() { if (getProjectionMode() == ProjectionMode.Parallel) { _projection.setIdentity(); _projection.setM00(2.0 / (_frustumRight - _frustumLeft)); _projection.setM11(2.0 / (_frustumTop - _frustumBottom)); _projection.setM22(-2.0 / (_frustumFar - _frustumNear)); _projection.setM30(-(_frustumRight + _frustumLeft) / (_frustumRight - _frustumLeft)); _projection.setM31(-(_frustumTop + _frustumBottom) / (_frustumTop - _frustumBottom)); _projection.setM32(-(_frustumFar + _frustumNear) / (_frustumFar - _frustumNear)); } else if (getProjectionMode() == ProjectionMode.Perspective) { _projection.setIdentity(); _projection.setM00((2.0 * _frustumNear) / (_frustumRight - _frustumLeft)); _projection.setM11((2.0 * _frustumNear) / (_frustumTop - _frustumBottom)); _projection.setM20((_frustumRight + _frustumLeft) / (_frustumRight - _frustumLeft)); _projection.setM21((_frustumTop + _frustumBottom) / (_frustumTop - _frustumBottom)); _projection.setM22(-(_frustumFar + _frustumNear) / (_frustumFar - _frustumNear)); _projection.setM23(-1.0); _projection.setM32(-(2.0 * _frustumFar * _frustumNear) / (_frustumFar - _frustumNear)); _projection.setM33(-0.0); } _updatePMatrix = false; }
if (getM00() != comp.getM00()) { return false; } else if (getM01() != comp.getM01()) { return false; } else if (getM02() != comp.getM02()) { return false; } else if (getM03() != comp.getM03()) { return false; } else if (getM10() != comp.getM10()) { return false; } else if (getM11() != comp.getM11()) { return false; } else if (getM12() != comp.getM12()) { return false; } else if (getM13() != comp.getM13()) { return false; } else if (getM20() != comp.getM20()) { return false; } else if (getM21() != comp.getM21()) { return false; } else if (getM22() != comp.getM22()) { return false; } else if (getM23() != comp.getM23()) { return false; } else if (getM30() != comp.getM30()) { return false; } else if (getM31() != comp.getM31()) { return false; } else if (getM32() != comp.getM32()) {
@Test public void testGetSet() { final Matrix4 mat4A = new Matrix4(); assertEquals(Matrix4.IDENTITY, mat4A); mat4A.setM00(0.0); mat4A.setM01(0.1); mat4A.setM02(0.2); mat4A.setM03(0.3); mat4A.setM10(1.0); mat4A.setM11(1.1); mat4A.setM12(1.2); mat4A.setM13(1.3); mat4A.setM20(2.0); mat4A.setM21(2.1); mat4A.setM22(2.2); mat4A.setM23(2.3); mat4A.setM30(3.0); mat4A.setM31(3.1); mat4A.setM32(3.2); mat4A.setM33(3.3); assertTrue(0.0 == mat4A.getM00()); assertTrue(0.1 == mat4A.getM01()); assertTrue(0.2 == mat4A.getM02()); assertTrue(0.3 == mat4A.getM03()); assertTrue(1.0 == mat4A.getM10()); assertTrue(1.1 == mat4A.getM11()); assertTrue(1.2 == mat4A.getM12()); assertTrue(1.3 == mat4A.getM13());
/** * Updates the value of our view matrix. */ protected void updateViewMatrix() { _view.setIdentity(); _view.setM00(-_left.getX()); _view.setM10(-_left.getY()); _view.setM20(-_left.getZ()); _view.setM01(_up.getX()); _view.setM11(_up.getY()); _view.setM21(_up.getZ()); _view.setM02(-_direction.getX()); _view.setM12(-_direction.getY()); _view.setM22(-_direction.getZ()); _view.setM30(_left.dot(_location)); _view.setM31(-_up.dot(_location)); _view.setM32(_direction.dot(_location)); }
tempX = jntMat.getM00() * bindVX + jntMat.getM01() * bindVY + jntMat.getM02() * bindVZ + jntMat.getM03(); tempY = jntMat.getM10() * bindVX + jntMat.getM11() * bindVY + jntMat.getM12() * bindVZ + jntMat.getM13(); tempZ = jntMat.getM20() * bindVX + jntMat.getM21() * bindVY + jntMat.getM22() * bindVZ + jntMat.getM23(); tempX = jntMat.getM00() * bindNX + jntMat.getM01() * bindNY + jntMat.getM02() * bindNZ; tempY = jntMat.getM10() * bindNX + jntMat.getM11() * bindNY + jntMat.getM12() * bindNZ; tempZ = jntMat.getM20() * bindNX + jntMat.getM21() * bindNY + jntMat.getM22() * bindNZ;
Matrix4 result = store; if (result == null) { result = new Matrix4(); result.setM00(1.0 - (yy + zz)); result.setM01(xy - zw); result.setM02(xz + yw); result.setM10(xy + zw); result.setM11(1.0 - (xx + zz)); result.setM12(yz - xw); result.setM20(xz - yw); result.setM21(yz + xw); result.setM22(1.0 - (xx + yy));
final Matrix4 workingMat = Matrix4.fetchTempInstance(); final Matrix4 finalMat = Matrix4.fetchTempInstance(); finalMat.setIdentity(); for (final TransformElement transform : transforms) { final double[] array = transform.getArray(); final TransformElementType type = transform.getType(); if (type == TransformElementType.Translation) { workingMat.setIdentity(); workingMat.setColumn(3, new Vector4(array[0], array[1], array[2], 1.0)); finalMat.multiplyLocal(workingMat); } else if (type == TransformElementType.Rotation) { if (array[3] != 0) { workingMat.setIdentity(); final Matrix3 rotate = new Matrix3().fromAngleAxis(array[3] * MathUtils.DEG_TO_RAD, new Vector3( array[0], array[1], array[2])); workingMat.set(rotate); finalMat.multiplyLocal(workingMat); workingMat.setIdentity(); workingMat.scale(new Vector4(array[0], array[1], array[2], 1), workingMat); finalMat.multiplyLocal(workingMat); } else if (type == TransformElementType.Matrix) { workingMat.fromArray(array); finalMat.multiplyLocal(workingMat); } else if (type == TransformElementType.Lookat) { final Vector3 pos = new Vector3(array[0], array[1], array[2]); final Matrix3 rot = new Matrix3(); rot.lookAt(target.subtractLocal(pos), up);
rangeMatrix.setIdentity(); rangeMatrix.setM00(maxX - minX); rangeMatrix.setM11(maxY - minY); rangeMatrix.setM30(minX); rangeMatrix.setM31(minY); rangeMatrix.multiplyLocal(modelViewProjectionInverseMatrix);
@Test public void testValid() { final Matrix4 mat4 = new Matrix4(); assertTrue(Matrix4.isValid(mat4)); for (int i = 0; i < 16; i++) { mat4.setIdentity(); mat4.setValue(i / 4, i % 4, Double.NaN); assertFalse(Matrix4.isValid(mat4)); mat4.setIdentity(); mat4.setValue(i / 4, i % 4, Double.POSITIVE_INFINITY); assertFalse(Matrix4.isValid(mat4)); mat4.setIdentity(); assertTrue(Matrix4.isValid(mat4)); assertFalse(Matrix4.isValid(null)); assertTrue(mat4.strictEquals(mat4)); assertFalse(mat4.equals(null)); assertFalse(mat4.strictEquals(null)); assertFalse(mat4.equals(new Vector2())); assertFalse(mat4.strictEquals(new Vector2())); final Matrix4 matTemp = Matrix4.fetchTempInstance(); matTemp.set(mat4); assertEquals(mat4, matTemp); assertNotSame(mat4, matTemp); Matrix4.releaseTempInstance(matTemp); mat4.set(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
/** * Same as set(IDENTITY) * * @return this matrix for chaining */ public Matrix4 setIdentity() { return set(Matrix4.IDENTITY); }
public void updateTextureMatrix(final Matrix4 matrixStore) { update(); final ReadOnlyMatrix4 projectorView = getModelViewMatrix(); final ReadOnlyMatrix4 projectorProjection = getProjectionMatrix(); matrixStore.set(projectorView).multiplyLocal(projectorProjection).multiplyLocal(BIAS); } }
@Override public Matrix4 clone() { return new Matrix4(this); }
@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()); }
/** * Update texture matrix. * * @param index * the index */ private void updateTextureMatrix(final int index) { // Create a matrix going from light to camera space final Camera cam = ContextManager.getCurrentContext().getCurrentCamera(); _shadowMatrix.set(cam.getViewMatrix()).invertLocal(); _shadowMatrix.multiplyLocal(_shadowMapRenderer.getCamera().getModelViewProjectionMatrix()) .multiplyLocal(SCALE_BIAS_MATRIX); // _shadowMapTexture[index].setTextureMatrix(_shadowMatrix); }
textureReflect.setWrap(Texture.WrapMode.EdgeClamp); textureReflect.setMagnificationFilter(Texture.MagnificationFilter.Bilinear); Matrix4 matrix = new Matrix4(); matrix.setM00(-1.0); matrix.setM30(1.0); textureReflect.setTextureMatrix(matrix); tRenderer.setupTexture(textureReflect); matrix = new Matrix4(); matrix.setM00(0.8); matrix.setM11(0.8); dudvTexture.setTextureMatrix(matrix); textureState.setTexture(dudvTexture, 2);
final double[] colmajor = { 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15 }; final Matrix4 mat4A = new Matrix4().fromArray(values); final FloatBuffer fb = mat4A.toFloatBuffer(FloatBuffer.allocate(16)); fb.flip(); for (int i = 0; i < 16; i++) { mat4A.toFloatBuffer(fb, false); fb.flip(); for (int i = 0; i < 16; i++) { final DoubleBuffer db = mat4A.toDoubleBuffer(DoubleBuffer.allocate(16)); db.flip(); for (int i = 0; i < 16; i++) { mat4A.toDoubleBuffer(db, false); db.flip(); for (int i = 0; i < 16; i++) {
@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); }