/** * Creates a new instance * * @param bindShapeMatrix The bind shape matrix. A copy of this array * will be stored. If it is <code>null</code>, a new array will be * created, which represents the identity matrix. */ public DefaultSkinModel(float bindShapeMatrix[]) { if (bindShapeMatrix == null) { this.bindShapeMatrix = MathUtils.createIdentity4x4(); } else { this.bindShapeMatrix = bindShapeMatrix.clone(); } this.joints = new ArrayList<NodeModel>(); }
/** * Create a string representation of the given array, as a matrix, * interpreting it as a matrix that is stored in column-major order. The * given array may be <code>null</code>. If it is not <code>null</code>, * then it must either have 3x3 elements or 4x4 elements. * * @param array The array * @return The string representation */ public static String createMatrixString(float array[]) { if (array == null) { return "null"; } if (array.length == 9) { return createMatrixString(array, 3, 3); } if (array.length == 16) { return createMatrixString(array, 4, 4); } return "WARNING: Not a matrix: "+Arrays.toString(array); }
/** * Adds the operation to invert the current matrix * * @return This builder */ MatrixOps invert4x4() { float result[] = new float[16]; functions.add(named("invert4x4", input -> { MathUtils.invert4x4(input, result); return result; })); return this; }
MathUtils.setIdentity4x4(localResult); if (nodeModel.getTranslation() != null) MathUtils.quaternionToMatrix4x4(q, m); MathUtils.mul4x4(localResult, m, localResult); MathUtils.setIdentity4x4(m); m[ 0] = s[0]; m[ 5] = s[1]; m[10] = s[2]; m[15] = 1.0f; MathUtils.mul4x4(localResult, m, localResult);
Supplier<float[]> externalViewMatrixSupplier) float viewMatrix[] = MathUtils.createIdentity4x4(); return () -> MathUtils.setIdentity4x4(viewMatrix); return viewMatrix;
if (zFar == null) MathUtils.infinitePerspective4x4( fovDeg, localAspectRatio, zNear, localResult); MathUtils.perspective4x4( fovDeg, localAspectRatio, zNear, zFar, localResult); float zNear = cameraOrthographic.getZnear(); float zFar = cameraOrthographic.getZfar(); MathUtils.setIdentity4x4(localResult); localResult[0] = 1.0f / xMag; localResult[5] = 1.0f / yMag; MathUtils.setIdentity4x4(localResult);
/** * Compute the global transform for the given {@link NodeModel}, * and store it in the given result. If the given result is * <code>null</code> or does not have a length of 16, then * a new array will be created and returned. * * @param nodeModel The {@link NodeModel} * @param result The result * @return The result */ private static float[] computeGlobalTransform( NodeModel nodeModel, float result[]) { float localResult[] = Utils.validate(result, 16); float tempLocalTransform[] = TEMP_MATRIX_4x4_IN_GLOBAL.get(); NodeModel currentNode = nodeModel; MathUtils.setIdentity4x4(localResult); while (currentNode != null) { currentNode.computeLocalTransform(tempLocalTransform); MathUtils.mul4x4( tempLocalTransform, localResult, localResult); currentNode = currentNode.getParent(); } return localResult; }
/** * Creates a 4x4 identity matrix * * @return The matrix */ public static float[] createIdentity4x4() { float m[] = new float[16]; setIdentity4x4(m); return m; }
/** * Adds the operation to multiply the current matrix with the matrix * that is provided by the given supplier * * @param operandSupplier The supplier of the operand * @return This builder */ MatrixOps multiply4x4(Supplier<float[]> operandSupplier) { float result[] = new float[16]; functions.add(named("multiply4x4", input -> { MathUtils.mul4x4(input, operandSupplier.get(), result); return result; })); return this; }
/** * Create a string representation of the given array, as a matrix, * interpreting it as a matrix that is stored in column-major order. The * given array may be <code>null</code>. If it is not <code>null</code>, * then it must either have 3x3 elements or 4x4 elements. <br> * <br> * The individual elements of the matrix will be formatted (in an * unspecified way) so that the matrix entries are aligned. * * @param array The array * @return The string representation */ public static String createFormattedMatrixString(float array[]) { if (array == null) { return "null"; } String format = "%10.5f "; if (array.length == 9) { return createFormattedMatrixString(array, 3, 3, format); } if (array.length == 16) { return createFormattedMatrixString(array, 4, 4, format); } return "WARNING: Not a matrix: "+Arrays.toString(array); }
float invLength = 1.0f / (float)Math.sqrt(dot(q, q));
/** * Adds the operation to invert the current matrix * * @return This builder */ MatrixOps invert3x3() { float result[] = new float[9]; functions.add(named("invert3x4", input -> { MathUtils.invert3x3(input, result); return result; })); return this; }
/** * Adds the operation to convert the current 4x4 matrix into a 3x3 * matrix by extracting the upper left (rotation and scale) part * * @return This builder */ MatrixOps getRotationScale() { float result[] = new float[9]; functions.add(named("getRotationScale", input -> { MathUtils.getRotationScale(input, result); return result; })); return this; }
Supplier<float[]> externalProjectionMatrixSupplier) float projectionMatrix[] = MathUtils.createIdentity4x4(); return () -> MathUtils.setIdentity4x4(projectionMatrix); return projectionMatrix;
if (zFar == null) MathUtils.infinitePerspective4x4( fovDeg, localAspectRatio, zNear, localResult); MathUtils.perspective4x4( fovDeg, localAspectRatio, zNear, zFar, localResult); float zNear = cameraOrthographic.getZnear(); float zFar = cameraOrthographic.getZfar(); MathUtils.setIdentity4x4(localResult); localResult[0] = 1.0f / xMag; localResult[5] = 1.0f / yMag; MathUtils.setIdentity4x4(localResult);
/** * Creates a supplier that provides a 4x4 identity matrix. * * @return The supplier */ private static Supplier<float[]> createIdentitySupplier4x4() { float matrix[] = new float[16]; return () -> { MathUtils.setIdentity4x4(matrix); return matrix; }; }
MathUtils.mul4x4(parentTransform, localTransform, transform);
/** * Fill the given matrix to describe a perspective projection with the * given parameters. * * @param fovyDeg The Field-Of-View, in y-direction, in degrees * @param aspect The aspect ratio * @param zNear The z-value of the near clipping plane * @param zFar The z-value of the far clipping plane * @param m The matrix to fill */ public static void perspective4x4( float fovyDeg, float aspect, float zNear, float zFar, float m[]) { setIdentity4x4(m); float fovyRad = (float)Math.toRadians(fovyDeg); float t = (float)Math.tan(0.5 * fovyRad); m[0] = 1.0f / (aspect * t); m[5] = 1.0f / t; m[10] = (zFar + zNear) / (zNear - zFar); m[11] = -1.0f; m[14] = 2.0f * zFar * zNear / (zNear - zFar); m[15] = 0.0f; }
MathUtils.invert4x4(localResult, localResult); return localResult; };
/** * Compute the bounding box of the {@link GltfModel} * * @return The bounding box */ BoundingBox compute() { BoundingBox boundingBox = new BoundingBox(); List<SceneModel> sceneModels = gltfModel.getSceneModels(); for (SceneModel sceneModel : sceneModels) { float rootTransform[] = MathUtils.createIdentity4x4(); computeSceneBoundingBox(sceneModel, rootTransform, boundingBox); } return boundingBox; }