/** * Sets the values of this matrix to the values of the provided double array. * * @param source * @return this matrix for chaining * @throws NullPointerException * if source is null. * @throws ArrayIndexOutOfBoundsException * if source array has a length less than 16. */ public Matrix4 fromArray(final double[] source) { return fromArray(source, true); }
/** * Sets the values of this matrix to the values of the provided double array. * * @param source * @return this matrix for chaining * @throws NullPointerException * if source is null. * @throws ArrayIndexOutOfBoundsException * if source array has a length less than 16. */ public Matrix4 fromArray(final double[] source) { return fromArray(source, true); }
finalMat.multiplyLocal(workingMat); } else if ("matrix".equals(transform.getName())) { workingMat.fromArray(array); finalMat.multiplyLocal(workingMat); } else if ("lookat".equals(transform.getName())) {
@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]); } }
if (bindShapeMatrixEL != null) { final double[] array = _colladaDOMUtil.parseDoubleArray(bindShapeMatrixEL); bindShapeMatrix.fromHomogeneousMatrix(new Matrix4().fromArray(array));
finalMat.multiplyLocal(workingMat); } else if (type == TransformElementType.Matrix) { workingMat.fromArray(array); finalMat.multiplyLocal(workingMat); } else if (type == TransformElementType.Lookat) {
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);
private void modifyProjectionMatrix(final Vector4 clipPlane) { // Get the current projection matrix projectionMatrix = cam.getProjectionMatrix().toArray(projectionMatrix); // Get the inverse transpose of the current modelview matrix final ReadOnlyMatrix4 modelViewMatrixInvTrans = tRenderer.getCamera().getModelViewMatrix().invert(tmpMatrix) .transposeLocal(); modelViewMatrixInvTrans.applyPre(clipPlane, clipPlane); // Calculate the clip-space corner point opposite the clipping plane // as (sgn(clipPlane.x), sgn(clipPlane.y), 1, 1) and // transform it into camera space by multiplying it // by the inverse of the projection matrix cornerPoint.setX((sign(clipPlane.getX()) + projectionMatrix[8]) / projectionMatrix[0]); cornerPoint.setY((sign(clipPlane.getY()) + projectionMatrix[9]) / projectionMatrix[5]); cornerPoint.setZ(-1.0); cornerPoint.setW((1.0 + projectionMatrix[10]) / projectionMatrix[14]); // Calculate the scaled plane vector final Vector4 scaledPlaneVector = clipPlane.multiply((2.0 / clipPlane.dot(cornerPoint)), cornerPoint); // Replace the third row of the projection matrix projectionMatrix[2] = scaledPlaneVector.getX(); projectionMatrix[6] = scaledPlaneVector.getY(); projectionMatrix[10] = scaledPlaneVector.getZ() + 1.0; projectionMatrix[14] = scaledPlaneVector.getW(); // Load it back into OpenGL final Matrix4 newProjectionMatrix = tmpMatrix.fromArray(projectionMatrix); tRenderer.getCamera().setProjectionMatrix(newProjectionMatrix); }
private void modifyProjectionMatrix(final Vector4 clipPlane) { // Get the current projection matrix projectionMatrix = cam.getProjectionMatrix().toArray(projectionMatrix); // Get the inverse transpose of the current modelview matrix final ReadOnlyMatrix4 modelViewMatrixInvTrans = tRenderer.getCamera().getViewMatrix().invert(tmpMatrix) .transposeLocal(); modelViewMatrixInvTrans.applyPre(clipPlane, clipPlane); // Calculate the clip-space corner point opposite the clipping plane // as (sgn(clipPlane.x), sgn(clipPlane.y), 1, 1) and // transform it into camera space by multiplying it // by the inverse of the projection matrix cornerPoint.setX((sign(clipPlane.getX()) + projectionMatrix[8]) / projectionMatrix[0]); cornerPoint.setY((sign(clipPlane.getY()) + projectionMatrix[9]) / projectionMatrix[5]); cornerPoint.setZ(-1.0); cornerPoint.setW((1.0 + projectionMatrix[10]) / projectionMatrix[14]); // Calculate the scaled plane vector final Vector4 scaledPlaneVector = clipPlane.multiply((2.0 / clipPlane.dot(cornerPoint)), cornerPoint); // Replace the third row of the projection matrix projectionMatrix[2] = scaledPlaneVector.getX(); projectionMatrix[6] = scaledPlaneVector.getY(); projectionMatrix[10] = scaledPlaneVector.getZ() + 1.0; projectionMatrix[14] = scaledPlaneVector.getW(); // Load it back into OpenGL final Matrix4 newProjectionMatrix = tmpMatrix.fromArray(projectionMatrix); tRenderer.getCamera().setProjectionMatrix(newProjectionMatrix); }