Java Code Examples for org.joml.Matrix4f#mul()
The following examples show how to use
org.joml.Matrix4f#mul() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnimMeshesLoader.java From lwjglbook with Apache License 2.0 | 6 votes |
private static List<AnimatedFrame> buildAnimationFrames(List<Bone> boneList, Node rootNode, Matrix4f rootTransformation) { int numFrames = rootNode.getAnimationFrames(); List<AnimatedFrame> frameList = new ArrayList<>(); for (int i = 0; i < numFrames; i++) { AnimatedFrame frame = new AnimatedFrame(); frameList.add(frame); int numBones = boneList.size(); for (int j = 0; j < numBones; j++) { Bone bone = boneList.get(j); Node node = rootNode.findByName(bone.getBoneName()); Matrix4f boneMatrix = Node.getParentTransforms(node, i); boneMatrix.mul(bone.getOffsetMatrix()); boneMatrix = new Matrix4f(rootTransformation).mul(boneMatrix); frame.setMatrix(j, boneMatrix); } } return frameList; }
Example 2
Source File: Transform3DTest.java From WraithEngine with Apache License 2.0 | 5 votes |
@Test public void getFullMatrix() { Transform3D parent = new Transform3D(); parent.setPosition(10f, 30f, 50f); parent.setRotation(new Quaternionf().rotateLocalX((float) Math.toRadians(90f))); parent.setSize(4f); Transform3D t = new Transform3D(); t.setParent(parent); t.setPosition(-5f, -17f, -5f); t.getRotation() .rotateLocalX((float) Math.toRadians(45f)); t.setSize(0.5f); Matrix4f mat = new Matrix4f(); t.getFullMatrix(mat); Matrix4f mat2 = new Matrix4f(); mat2.translate(-5f, -17f, -5f); mat2.rotate(new Quaternionf().rotateLocalX((float) Math.toRadians(45f))); mat2.scale(0.5f); Matrix4f tempMat2 = new Matrix4f(); parent.getLocalMatrix(tempMat2); mat2 = tempMat2.mul(mat2); Assert.assertEquals(mat2, mat); }
Example 3
Source File: Transform3D.java From WraithEngine with Apache License 2.0 | 5 votes |
/** * Calculates the full matrix for this transform and stores it in the output * matrix parameter. A full transform is considered: * <p> * <code>out = parent * local</code> * <p> * for the given transforms. If this transform does not have a parent, then this * method returns the local transformation matrix. * * @param out * - The matrix to store the output into. */ public void getFullMatrix(Matrix4f out) { if (parent == null) { getLocalMatrix(out); return; } parent.getFullMatrix(matrixBuffer); out.set(matrixBuffer); getLocalMatrix(matrixBuffer); out.mul(matrixBuffer); }
Example 4
Source File: Transformation.java From lwjglbook with Apache License 2.0 | 5 votes |
public Matrix4f getModelViewMatrix(GameItem gameItem, Matrix4f viewMatrix) { Vector3f rotation = gameItem.getRotation(); modelViewMatrix.identity().translate(gameItem.getPosition()). rotateX((float)Math.toRadians(-rotation.x)). rotateY((float)Math.toRadians(-rotation.y)). rotateZ((float)Math.toRadians(-rotation.z)). scale(gameItem.getScale()); Matrix4f viewCurr = new Matrix4f(viewMatrix); return viewCurr.mul(modelViewMatrix); }
Example 5
Source File: Transformation.java From lwjglbook with Apache License 2.0 | 5 votes |
public Matrix4f getModelViewMatrix(GameItem gameItem, Matrix4f viewMatrix) { Vector3f rotation = gameItem.getRotation(); modelViewMatrix.identity().translate(gameItem.getPosition()). rotateX((float)Math.toRadians(-rotation.x)). rotateY((float)Math.toRadians(-rotation.y)). rotateZ((float)Math.toRadians(-rotation.z)). scale(gameItem.getScale()); Matrix4f viewCurr = new Matrix4f(viewMatrix); return viewCurr.mul(modelViewMatrix); }
Example 6
Source File: Transformation.java From lwjglbook with Apache License 2.0 | 5 votes |
public Matrix4f getOrtoProjModelMatrix(GameItem gameItem, Matrix4f orthoMatrix) { Vector3f rotation = gameItem.getRotation(); Matrix4f modelMatrix = new Matrix4f(); modelMatrix.identity().translate(gameItem.getPosition()). rotateX((float)Math.toRadians(-rotation.x)). rotateY((float)Math.toRadians(-rotation.y)). rotateZ((float)Math.toRadians(-rotation.z)). scale(gameItem.getScale()); Matrix4f orthoMatrixCurr = new Matrix4f(orthoMatrix); orthoMatrixCurr.mul(modelMatrix); return orthoMatrixCurr; }
Example 7
Source File: Transformation.java From lwjglbook with Apache License 2.0 | 5 votes |
public Matrix4f getModelViewMatrix(GameItem gameItem, Matrix4f viewMatrix) { Vector3f rotation = gameItem.getRotation(); modelViewMatrix.identity().translate(gameItem.getPosition()). rotateX((float)Math.toRadians(-rotation.x)). rotateY((float)Math.toRadians(-rotation.y)). rotateZ((float)Math.toRadians(-rotation.z)). scale(gameItem.getScale()); Matrix4f viewCurr = new Matrix4f(viewMatrix); return viewCurr.mul(modelViewMatrix); }
Example 8
Source File: Transformation.java From lwjglbook with Apache License 2.0 | 5 votes |
public Matrix4f getModelViewMatrix(GameItem gameItem, Matrix4f viewMatrix) { Vector3f rotation = gameItem.getRotation(); modelViewMatrix.identity().translate(gameItem.getPosition()). rotateX((float)Math.toRadians(-rotation.x)). rotateY((float)Math.toRadians(-rotation.y)). rotateZ((float)Math.toRadians(-rotation.z)). scale(gameItem.getScale()); Matrix4f viewCurr = new Matrix4f(viewMatrix); return viewCurr.mul(modelViewMatrix); }
Example 9
Source File: MD5Loader.java From lwjglbook with Apache License 2.0 | 4 votes |
private static AnimatedFrame processAnimationFrame(MD5Model md5Model, MD5AnimModel animModel, MD5Frame frame, List<Matrix4f> invJointMatrices) { AnimatedFrame result = new AnimatedFrame(); MD5BaseFrame baseFrame = animModel.getBaseFrame(); List<MD5Hierarchy.MD5HierarchyData> hierarchyList = animModel.getHierarchy().getHierarchyDataList(); List<MD5JointInfo.MD5JointData> joints = md5Model.getJointInfo().getJoints(); int numJoints = joints.size(); float[] frameData = frame.getFrameData(); for (int i = 0; i < numJoints; i++) { MD5JointInfo.MD5JointData joint = joints.get(i); MD5BaseFrame.MD5BaseFrameData baseFrameData = baseFrame.getFrameDataList().get(i); Vector3f position = baseFrameData.getPosition(); Quaternionf orientation = baseFrameData.getOrientation(); int flags = hierarchyList.get(i).getFlags(); int startIndex = hierarchyList.get(i).getStartIndex(); if ((flags & 1) > 0) { position.x = frameData[startIndex++]; } if ((flags & 2) > 0) { position.y = frameData[startIndex++]; } if ((flags & 4) > 0) { position.z = frameData[startIndex++]; } if ((flags & 8) > 0) { orientation.x = frameData[startIndex++]; } if ((flags & 16) > 0) { orientation.y = frameData[startIndex++]; } if ((flags & 32) > 0) { orientation.z = frameData[startIndex++]; } // Update Quaternion's w component orientation = MD5Utils.calculateQuaternion(orientation.x, orientation.y, orientation.z); // Calculate translation and rotation matrices for this joint Matrix4f translateMat = new Matrix4f().translate(position); Matrix4f rotationMat = new Matrix4f().rotate(orientation); Matrix4f jointMat = translateMat.mul(rotationMat); // Joint position is relative to joint's parent index position. Use parent matrices // to transform it to model space if (joint.getParentIndex() > -1) { Matrix4f parentMatrix = result.getLocalJointMatrices()[joint.getParentIndex()]; jointMat = new Matrix4f(parentMatrix).mul(jointMat); } result.setMatrix(i, jointMat, invJointMatrices.get(i)); } return result; }
Example 10
Source File: MD5Loader.java From lwjglbook with Apache License 2.0 | 4 votes |
private static AnimatedFrame processAnimationFrame(MD5Model md5Model, MD5AnimModel animModel, MD5Frame frame, List<Matrix4f> invJointMatrices) { AnimatedFrame result = new AnimatedFrame(); MD5BaseFrame baseFrame = animModel.getBaseFrame(); List<MD5Hierarchy.MD5HierarchyData> hierarchyList = animModel.getHierarchy().getHierarchyDataList(); List<MD5JointInfo.MD5JointData> joints = md5Model.getJointInfo().getJoints(); int numJoints = joints.size(); float[] frameData = frame.getFrameData(); for (int i = 0; i < numJoints; i++) { MD5JointInfo.MD5JointData joint = joints.get(i); MD5BaseFrame.MD5BaseFrameData baseFrameData = baseFrame.getFrameDataList().get(i); Vector3f position = baseFrameData.getPosition(); Quaternionf orientation = baseFrameData.getOrientation(); int flags = hierarchyList.get(i).getFlags(); int startIndex = hierarchyList.get(i).getStartIndex(); if ((flags & 1) > 0) { position.x = frameData[startIndex++]; } if ((flags & 2) > 0) { position.y = frameData[startIndex++]; } if ((flags & 4) > 0) { position.z = frameData[startIndex++]; } if ((flags & 8) > 0) { orientation.x = frameData[startIndex++]; } if ((flags & 16) > 0) { orientation.y = frameData[startIndex++]; } if ((flags & 32) > 0) { orientation.z = frameData[startIndex++]; } // Update Quaternion's w component orientation = MD5Utils.calculateQuaternion(orientation.x, orientation.y, orientation.z); // Calculate translation and rotation matrices for this joint Matrix4f translateMat = new Matrix4f().translate(position); Matrix4f rotationMat = new Matrix4f().rotate(orientation); Matrix4f jointMat = translateMat.mul(rotationMat); // Joint position is relative to joint's parent index position. Use parent matrices // to transform it to model space if (joint.getParentIndex() > -1) { Matrix4f parentMatrix = result.getLocalJointMatrices()[joint.getParentIndex()]; jointMat = new Matrix4f(parentMatrix).mul(jointMat); } result.setMatrix(i, jointMat, invJointMatrices.get(i)); } return result; }
Example 11
Source File: AnimatedFrame.java From lwjglbook with Apache License 2.0 | 4 votes |
public void setMatrix(int pos, Matrix4f localJointMatrix, Matrix4f invJointMatrix) { localJointMatrices[pos] = localJointMatrix; Matrix4f mat = new Matrix4f(localJointMatrix); mat.mul(invJointMatrix); jointMatrices[pos] = mat; }
Example 12
Source File: MD5Loader.java From lwjglbook with Apache License 2.0 | 4 votes |
private static AnimatedFrame processAnimationFrame(MD5Model md5Model, MD5AnimModel animModel, MD5Frame frame, List<Matrix4f> invJointMatrices) { AnimatedFrame result = new AnimatedFrame(); MD5BaseFrame baseFrame = animModel.getBaseFrame(); List<MD5Hierarchy.MD5HierarchyData> hierarchyList = animModel.getHierarchy().getHierarchyDataList(); List<MD5JointInfo.MD5JointData> joints = md5Model.getJointInfo().getJoints(); int numJoints = joints.size(); float[] frameData = frame.getFrameData(); for (int i = 0; i < numJoints; i++) { MD5JointInfo.MD5JointData joint = joints.get(i); MD5BaseFrame.MD5BaseFrameData baseFrameData = baseFrame.getFrameDataList().get(i); Vector3f position = baseFrameData.getPosition(); Quaternionf orientation = baseFrameData.getOrientation(); int flags = hierarchyList.get(i).getFlags(); int startIndex = hierarchyList.get(i).getStartIndex(); if ((flags & 1) > 0) { position.x = frameData[startIndex++]; } if ((flags & 2) > 0) { position.y = frameData[startIndex++]; } if ((flags & 4) > 0) { position.z = frameData[startIndex++]; } if ((flags & 8) > 0) { orientation.x = frameData[startIndex++]; } if ((flags & 16) > 0) { orientation.y = frameData[startIndex++]; } if ((flags & 32) > 0) { orientation.z = frameData[startIndex++]; } // Update Quaternion's w component orientation = MD5Utils.calculateQuaternion(orientation.x, orientation.y, orientation.z); // Calculate translation and rotation matrices for this joint Matrix4f translateMat = new Matrix4f().translate(position); Matrix4f rotationMat = new Matrix4f().rotate(orientation); Matrix4f jointMat = translateMat.mul(rotationMat); // Joint position is relative to joint's parent index position. Use parent matrices // to transform it to model space if (joint.getParentIndex() > -1) { Matrix4f parentMatrix = result.getLocalJointMatrices()[joint.getParentIndex()]; jointMat = new Matrix4f(parentMatrix).mul(jointMat); } result.setMatrix(i, jointMat, invJointMatrices.get(i)); } return result; }
Example 13
Source File: AnimatedFrame.java From lwjglbook with Apache License 2.0 | 4 votes |
public void setMatrix(int pos, Matrix4f localJointMatrix, Matrix4f invJointMatrix) { localJointMatrices[pos] = localJointMatrix; Matrix4f mat = new Matrix4f(localJointMatrix); mat.mul(invJointMatrix); jointMatrices[pos] = mat; }
Example 14
Source File: MD5Loader.java From lwjglbook with Apache License 2.0 | 4 votes |
private static AnimatedFrame processAnimationFrame(MD5Model md5Model, MD5AnimModel animModel, MD5Frame frame, List<Matrix4f> invJointMatrices) { AnimatedFrame result = new AnimatedFrame(); MD5BaseFrame baseFrame = animModel.getBaseFrame(); List<MD5Hierarchy.MD5HierarchyData> hierarchyList = animModel.getHierarchy().getHierarchyDataList(); List<MD5JointInfo.MD5JointData> joints = md5Model.getJointInfo().getJoints(); int numJoints = joints.size(); float[] frameData = frame.getFrameData(); for (int i = 0; i < numJoints; i++) { MD5JointInfo.MD5JointData joint = joints.get(i); MD5BaseFrame.MD5BaseFrameData baseFrameData = baseFrame.getFrameDataList().get(i); Vector3f position = baseFrameData.getPosition(); Quaternionf orientation = baseFrameData.getOrientation(); int flags = hierarchyList.get(i).getFlags(); int startIndex = hierarchyList.get(i).getStartIndex(); if ((flags & 1) > 0) { position.x = frameData[startIndex++]; } if ((flags & 2) > 0) { position.y = frameData[startIndex++]; } if ((flags & 4) > 0) { position.z = frameData[startIndex++]; } if ((flags & 8) > 0) { orientation.x = frameData[startIndex++]; } if ((flags & 16) > 0) { orientation.y = frameData[startIndex++]; } if ((flags & 32) > 0) { orientation.z = frameData[startIndex++]; } // Update Quaternion's w component orientation = MD5Utils.calculateQuaternion(orientation.x, orientation.y, orientation.z); // Calculate translation and rotation matrices for this joint Matrix4f translateMat = new Matrix4f().translate(position); Matrix4f rotationMat = new Matrix4f().rotate(orientation); Matrix4f jointMat = translateMat.mul(rotationMat); // Joint position is relative to joint's parent index position. Use parent matrices // to transform it to model space if (joint.getParentIndex() > -1) { Matrix4f parentMatrix = result.getLocalJointMatrices()[joint.getParentIndex()]; jointMat = new Matrix4f(parentMatrix).mul(jointMat); } result.setMatrix(i, jointMat, invJointMatrices.get(i)); } return result; }
Example 15
Source File: MD5Loader.java From lwjglbook with Apache License 2.0 | 4 votes |
private static AnimatedFrame processAnimationFrame(MD5Model md5Model, MD5AnimModel animModel, MD5Frame frame, List<Matrix4f> invJointMatrices) { AnimatedFrame result = new AnimatedFrame(); MD5BaseFrame baseFrame = animModel.getBaseFrame(); List<MD5Hierarchy.MD5HierarchyData> hierarchyList = animModel.getHierarchy().getHierarchyDataList(); List<MD5JointInfo.MD5JointData> joints = md5Model.getJointInfo().getJoints(); int numJoints = joints.size(); float[] frameData = frame.getFrameData(); for (int i = 0; i < numJoints; i++) { MD5JointInfo.MD5JointData joint = joints.get(i); MD5BaseFrame.MD5BaseFrameData baseFrameData = baseFrame.getFrameDataList().get(i); Vector3f position = baseFrameData.getPosition(); Quaternionf orientation = baseFrameData.getOrientation(); int flags = hierarchyList.get(i).getFlags(); int startIndex = hierarchyList.get(i).getStartIndex(); if ((flags & 1) > 0) { position.x = frameData[startIndex++]; } if ((flags & 2) > 0) { position.y = frameData[startIndex++]; } if ((flags & 4) > 0) { position.z = frameData[startIndex++]; } if ((flags & 8) > 0) { orientation.x = frameData[startIndex++]; } if ((flags & 16) > 0) { orientation.y = frameData[startIndex++]; } if ((flags & 32) > 0) { orientation.z = frameData[startIndex++]; } // Update Quaternion's w component orientation = MD5Utils.calculateQuaternion(orientation.x, orientation.y, orientation.z); // Calculate translation and rotation matrices for this joint Matrix4f translateMat = new Matrix4f().translate(position); Matrix4f rotationMat = new Matrix4f().rotate(orientation); Matrix4f jointMat = translateMat.mul(rotationMat); // Joint position is relative to joint's parent index position. Use parent matrices // to transform it to model space if (joint.getParentIndex() > -1) { Matrix4f parentMatrix = result.getLocalJointMatrices()[joint.getParentIndex()]; jointMat = new Matrix4f(parentMatrix).mul(jointMat); } result.setMatrix(i, jointMat, invJointMatrices.get(i)); } return result; }
Example 16
Source File: MD5Loader.java From lwjglbook with Apache License 2.0 | 4 votes |
private static AnimatedFrame processAnimationFrame(MD5Model md5Model, MD5AnimModel animModel, MD5Frame frame, List<Matrix4f> invJointMatrices) { AnimatedFrame result = new AnimatedFrame(); MD5BaseFrame baseFrame = animModel.getBaseFrame(); List<MD5Hierarchy.MD5HierarchyData> hierarchyList = animModel.getHierarchy().getHierarchyDataList(); List<MD5JointInfo.MD5JointData> joints = md5Model.getJointInfo().getJoints(); int numJoints = joints.size(); float[] frameData = frame.getFrameData(); for (int i = 0; i < numJoints; i++) { MD5JointInfo.MD5JointData joint = joints.get(i); MD5BaseFrame.MD5BaseFrameData baseFrameData = baseFrame.getFrameDataList().get(i); Vector3f position = baseFrameData.getPosition(); Quaternionf orientation = baseFrameData.getOrientation(); int flags = hierarchyList.get(i).getFlags(); int startIndex = hierarchyList.get(i).getStartIndex(); if ((flags & 1) > 0) { position.x = frameData[startIndex++]; } if ((flags & 2) > 0) { position.y = frameData[startIndex++]; } if ((flags & 4) > 0) { position.z = frameData[startIndex++]; } if ((flags & 8) > 0) { orientation.x = frameData[startIndex++]; } if ((flags & 16) > 0) { orientation.y = frameData[startIndex++]; } if ((flags & 32) > 0) { orientation.z = frameData[startIndex++]; } // Update Quaternion's w component orientation = MD5Utils.calculateQuaternion(orientation.x, orientation.y, orientation.z); // Calculate translation and rotation matrices for this joint Matrix4f translateMat = new Matrix4f().translate(position); Matrix4f rotationMat = new Matrix4f().rotate(orientation); Matrix4f jointMat = translateMat.mul(rotationMat); // Joint position is relative to joint's parent index position. Use parent matrices // to transform it to model space if (joint.getParentIndex() > -1) { Matrix4f parentMatrix = result.getLocalJointMatrices()[joint.getParentIndex()]; jointMat = new Matrix4f(parentMatrix).mul(jointMat); } result.setMatrix(i, jointMat, invJointMatrices.get(i)); } return result; }
Example 17
Source File: AnimatedFrame.java From lwjglbook with Apache License 2.0 | 4 votes |
public void setMatrix(int pos, Matrix4f localJointMatrix, Matrix4f invJointMatrix) { localJointMatrices[pos] = localJointMatrix; Matrix4f mat = new Matrix4f(localJointMatrix); mat.mul(invJointMatrix); jointMatrices[pos] = mat; }
Example 18
Source File: AnimatedFrame.java From lwjglbook with Apache License 2.0 | 4 votes |
public void setMatrix(int pos, Matrix4f localJointMatrix, Matrix4f invJointMatrix) { localJointMatrices[pos] = localJointMatrix; Matrix4f mat = new Matrix4f(localJointMatrix); mat.mul(invJointMatrix); jointMatrices[pos] = mat; }
Example 19
Source File: MD5Loader.java From lwjglbook with Apache License 2.0 | 4 votes |
private static AnimatedFrame processAnimationFrame(MD5Model md5Model, MD5AnimModel animModel, MD5Frame frame, List<Matrix4f> invJointMatrices) { AnimatedFrame result = new AnimatedFrame(); MD5BaseFrame baseFrame = animModel.getBaseFrame(); List<MD5Hierarchy.MD5HierarchyData> hierarchyList = animModel.getHierarchy().getHierarchyDataList(); List<MD5JointInfo.MD5JointData> joints = md5Model.getJointInfo().getJoints(); int numJoints = joints.size(); float[] frameData = frame.getFrameData(); for (int i = 0; i < numJoints; i++) { MD5JointInfo.MD5JointData joint = joints.get(i); MD5BaseFrame.MD5BaseFrameData baseFrameData = baseFrame.getFrameDataList().get(i); Vector3f position = baseFrameData.getPosition(); Quaternionf orientation = baseFrameData.getOrientation(); int flags = hierarchyList.get(i).getFlags(); int startIndex = hierarchyList.get(i).getStartIndex(); if ((flags & 1) > 0) { position.x = frameData[startIndex++]; } if ((flags & 2) > 0) { position.y = frameData[startIndex++]; } if ((flags & 4) > 0) { position.z = frameData[startIndex++]; } if ((flags & 8) > 0) { orientation.x = frameData[startIndex++]; } if ((flags & 16) > 0) { orientation.y = frameData[startIndex++]; } if ((flags & 32) > 0) { orientation.z = frameData[startIndex++]; } // Update Quaternion's w component orientation = MD5Utils.calculateQuaternion(orientation.x, orientation.y, orientation.z); // Calculate translation and rotation matrices for this joint Matrix4f translateMat = new Matrix4f().translate(position); Matrix4f rotationMat = new Matrix4f().rotate(orientation); Matrix4f jointMat = translateMat.mul(rotationMat); // Joint position is relative to joint's parent index position. Use parent matrices // to transform it to model space if (joint.getParentIndex() > -1) { Matrix4f parentMatrix = result.getLocalJointMatrices()[joint.getParentIndex()]; jointMat = new Matrix4f(parentMatrix).mul(jointMat); } result.setMatrix(i, jointMat, invJointMatrices.get(i)); } return result; }
Example 20
Source File: AnimatedFrame.java From lwjglbook with Apache License 2.0 | 4 votes |
public void setMatrix(int pos, Matrix4f localJointMatrix, Matrix4f invJointMatrix) { localJointMatrices[pos] = localJointMatrix; Matrix4f mat = new Matrix4f(localJointMatrix); mat.mul(invJointMatrix); jointMatrices[pos] = mat; }